Repository: felangel/bloc (dart)

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.

Pull request description:
<!--
  Thanks for contributing!

  Provide a description of your changes below and a general summary in the title

  Please look at the following checklist to ensure that your PR can be accepted quickly:
-->

## Status

**READY**

## Breaking Changes

NO

## Description

<!--- Describe your changes in detail -->
- fix(bloc_lint): `avoid_public_bloc_methods` false positive (closes #4519)

## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [ ] ✨ New feature (non-breaking change which adds functionality)
- [X] 🛠️ Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
- [ ] 🧹 Code refactor
- [ ] ✅ Build configuration change
- [ ] 📝 Documentation
- [ ] 🗑️ Chore

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,
+  };
+}
 ''',
     );
   });