Repository: felangel/bloc (dart)

Issue:
fix(bloc_lint): only `*_bloc.dart` and `*_cubit.dart` are included in analysis
**Description**
The `bloc_lint` rules should apply to all bloc and cubit instances not just instances that are declared in files ending in `_bloc.dart` or `_cubit.dart`.

Pull request:
<!--
  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): include bloc/cubit instances declared in any file (closes #4564)

## 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/src/rules/avoid_public_bloc_methods.dart b/packages/bloc_lint/lib/src/rules/avoid_public_bloc_methods.dart
index 9b00242c1a7..395847a4ab3 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
@@ -12,10 +12,7 @@ class AvoidPublicBlocMethods extends LintRule {
   static const rule = 'avoid_public_bloc_methods';
 
   @override
-  Listener? create(LintContext context) {
-    if (!context.document.type.isBloc) return null;
-    return _Listener(context);
-  }
+  Listener? create(LintContext context) => _Listener(context);
 }
 
 class _Listener extends Listener {
diff --git a/packages/bloc_lint/lib/src/rules/avoid_public_fields.dart b/packages/bloc_lint/lib/src/rules/avoid_public_fields.dart
index add03e675a3..0d97a0f6524 100644
--- a/packages/bloc_lint/lib/src/rules/avoid_public_fields.dart
+++ b/packages/bloc_lint/lib/src/rules/avoid_public_fields.dart
@@ -12,10 +12,7 @@ class AvoidPublicFields extends LintRule {
   static const rule = 'avoid_public_fields';
 
   @override
-  Listener? create(LintContext context) {
-    if (context.document.type.isOther) return null;
-    return _Listener(context);
-  }
+  Listener? create(LintContext context) => _Listener(context);
 }
 
 class _Listener extends Listener {
diff --git a/packages/bloc_lint/lib/src/rules/prefer_void_public_cubit_methods.dart b/packages/bloc_lint/lib/src/rules/prefer_void_public_cubit_methods.dart
index edb6a57b451..6e72e559e11 100644
--- a/packages/bloc_lint/lib/src/rules/prefer_void_public_cubit_methods.dart
+++ b/packages/bloc_lint/lib/src/rules/prefer_void_public_cubit_methods.dart
@@ -12,10 +12,7 @@ class PreferVoidPublicCubitMethods extends LintRule {
   static const rule = 'prefer_void_public_cubit_methods';
 
   @override
-  Listener? create(LintContext context) {
-    if (!context.document.type.isCubit) return null;
-    return _Listener(context);
-  }
+  Listener? create(LintContext context) => _Listener(context);
 }
 
 class _Listener extends Listener {


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 083e9aed344..dbf5e8fc302 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
@@ -12,6 +12,23 @@ void main() {
       content: '''
 import 'package:bloc/bloc.dart';
 
+enum CounterEvent { increment, decrement }
+class CounterBloc extends Bloc<CounterEvent, int> {
+  CounterBloc() : super(0);
+
+  void foo() { print ('foo'); }
+       ^^^
+}
+''',
+    );
+
+    lintTest(
+      'lints when file name does not follow naming conventions',
+      rule: AvoidPublicBlocMethods.new,
+      path: 'main.dart',
+      content: '''
+import 'package:bloc/bloc.dart';
+
 enum CounterEvent { increment, decrement }
 class CounterBloc extends Bloc<CounterEvent, int> {
   CounterBloc() : super(0);
diff --git a/packages/bloc_lint/test/src/rules/avoid_public_fields_test.dart b/packages/bloc_lint/test/src/rules/avoid_public_fields_test.dart
index 6a91826fb85..8ad540b8b01 100644
--- a/packages/bloc_lint/test/src/rules/avoid_public_fields_test.dart
+++ b/packages/bloc_lint/test/src/rules/avoid_public_fields_test.dart
@@ -12,6 +12,23 @@ void main() {
       content: '''
 import 'package:bloc/bloc.dart';
 
+enum CounterEvent { increment, decrement }
+class CounterBloc extends Bloc<CounterEvent, int> {
+  CounterBloc() : super(0);
+
+  var count = 0;
+  ^^^^^^^^^^^^^
+}
+''',
+    );
+
+    lintTest(
+      'lints when file name does not follow naming conventions',
+      rule: AvoidPublicFields.new,
+      path: 'main.dart',
+      content: '''
+import 'package:bloc/bloc.dart';
+
 enum CounterEvent { increment, decrement }
 class CounterBloc extends Bloc<CounterEvent, int> {
   CounterBloc() : super(0);
diff --git a/packages/bloc_lint/test/src/rules/prefer_void_public_cubit_methods_test.dart b/packages/bloc_lint/test/src/rules/prefer_void_public_cubit_methods_test.dart
index 21619db4e56..ac5e72f0751 100644
--- a/packages/bloc_lint/test/src/rules/prefer_void_public_cubit_methods_test.dart
+++ b/packages/bloc_lint/test/src/rules/prefer_void_public_cubit_methods_test.dart
@@ -149,6 +149,24 @@ class CounterCubit extends Cubit<int> {
 ''',
     );
 
+    lintTest(
+      'lints when file name does not follow naming conventions',
+      rule: PreferVoidPublicCubitMethods.new,
+      path: 'main.dart',
+      content: '''
+import 'package:bloc/bloc.dart';
+
+class CounterCubit extends Cubit<int> {
+  CounterCubit() : super(0);
+
+  void increment() => emit(state + 1);
+
+  bool get isEven => state.isEven;
+           ^^^^^^
+}
+''',
+    );
+
     lintTest(
       'lints when public getter exists on Cubit (bool)',
       rule: PreferVoidPublicCubitMethods.new,