Repository: felangel/bloc

Issue:
fix: BlocLint falsely reports avoid_public_bloc_methods
**Description**
Linter reposrts that there's a public method while pointing to single symbol of private's method body.

**Steps To Reproduce**
This code in Bloc shows this behavior:

```dart
  void _updateScheduleName() =>
      _scheduleName =
          _schedule == null
              ? null
              : switch (_schedule!.type) {
                ScheduleType.group =>
                  _groups.firstWhereOrNull((e) => e.id == _schedule!.id)?.name,
                ScheduleType.teacher =>
                  _teachers
                      .firstWhereOrNull((e) => e.id == _schedule!.id)
                      ?.name,
                ScheduleType.room =>
                  _rooms.firstWhereOrNull((e) => e.id == _schedule!.id)?.name,
              };
```

**Expected Behavior**
No linter error should appear as method is private or at least whole method should be marked.

**Screenshots**
![Image](https://github.com/user-attachments/assets/9edca2af-02e3-4fa0-874b-f4cac93c56ac)

**Notes**
I use VSCodium and restarting doesn't fix the issue. Updating linter didn't as well.


Discussion: Thanks for filling the issue! I’ll take a closer look later today 👍

Fix patch:
diff --git a/packages/bloc_lint/lib/bloc_lint.dart b/packages/bloc_lint/lib/bloc_lint.dart
index 779988efd9c..e3a62945f1c 100644
--- a/packages/bloc_lint/lib/bloc_lint.dart
+++ b/packages/bloc_lint/lib/bloc_lint.dart
@@ -1,7 +1,7 @@
 export 'package:_fe_analyzer_shared/src/parser/parser.dart'
     show DeclarationKind, Listener;
 export 'package:_fe_analyzer_shared/src/scanner/token.dart'
-    show Keyword, Token, TokenType;
+    show BeginToken, Keyword, Token, TokenType;
 
 export 'src/diagnostic.dart' show Diagnostic, Severity;
 export 'src/lint_rule.dart' show LintRule, LintRuleBuilder;
diff --git a/packages/bloc_lint/lib/src/rules/avoid_public_bloc_methods.dart b/packages/bloc_lint/lib/src/rules/avoid_public_bloc_methods.dart
index 2f3eaf1c9dd..a5558bd2e21 100644
--- a/packages/bloc_lint/lib/src/rules/avoid_public_bloc_methods.dart
+++ b/packages/bloc_lint/lib/src/rules/avoid_public_bloc_methods.dart
@@ -62,6 +62,7 @@ class _Listener extends Listener {
     if (!(enclosingDeclarationName?.endsWith('Bloc') ?? false)) {
       return;
     }
+    if (name is BeginToken && name.previous?.type == Keyword.SWITCH) return;
     final methodName = name.lexeme;
     if (enclosingDeclarationName == methodName) return;
     if (allowedMethods.contains(methodName)) return;


Test patch:
diff --git a/packages/bloc_lint/test/src/rules/avoid_public_bloc_methods_test.dart b/packages/bloc_lint/test/src/rules/avoid_public_bloc_methods_test.dart
index 118bdcae148..083e9aed344 100644
--- a/packages/bloc_lint/test/src/rules/avoid_public_bloc_methods_test.dart
+++ b/packages/bloc_lint/test/src/rules/avoid_public_bloc_methods_test.dart
@@ -82,6 +82,23 @@ class CounterCubit extends Cubit<int> {
   
   void increment() => emit(state + 1);
 }
+''',
+    );
+
+    lintTest(
+      'does not lint on internal switch expression',
+      rule: AvoidPublicBlocMethods.new,
+      path: 'counter_bloc.dart',
+      content: '''
+import 'package:bloc/bloc.dart';
+
+enum CounterEvent { increment, decrement }
+class CounterBloc extends Bloc<CounterEvent, int> {
+  CounterBloc() : super(0);
+  bool _isEven(int x) => switch (x) {
+    int() => false,
+  };
+}
 ''',
     );
   });