From 1c86354dabc86079311246ff072cc6cdc6912c82 Mon Sep 17 00:00:00 2001 From: elijah mac Date: Thu, 30 Jan 2025 09:08:13 +0200 Subject: [PATCH 01/10] Fixed avoid_late_keyword_allow_initialized_test.dart --- ...d_late_keyword_allow_initialized_test.dart | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart b/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart index 8136b96a..05af24d1 100644 --- a/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart +++ b/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart @@ -14,56 +14,68 @@ class ColorTween {} /// `avoid_late_keyword` /// allow_initialized option disabled class AvoidLateKeyword { - /// expect_lint: avoid_late_keyword + /// ignored_types: Animation late final Animation animation1; + /// ignored_types: Animation late final animation2 = AnimationController(); + /// ignored_types: Animation late final animation3 = SubAnimationController(); /// expect_lint: avoid_late_keyword late final ColorTween colorTween1; + /// expect_lint: avoid_late_keyword late final colorTween2 = ColorTween(); + /// expect_lint: avoid_late_keyword late final colorTween3 = colorTween2; - /// expect_lint: avoid_late_keyword + /// ignored_types: Animation late final AnimationController controller1; + /// expect_lint: avoid_late_keyword late final field1 = 'string'; /// expect_lint: avoid_late_keyword late final String field2; + /// expect_lint: avoid_late_keyword late final String field3 = 'string'; /// expect_lint: avoid_late_keyword late final field4; void test() { - /// expect_lint: avoid_late_keyword + /// ignored_types: Animation late final Animation animation1; + /// ignored_types: Animation late final animation2 = AnimationController(); + /// ignored_types: Animation late final animation3 = SubAnimationController(); /// expect_lint: avoid_late_keyword late final ColorTween colorTween1; + /// expect_lint: avoid_late_keyword late final colorTween2 = ColorTween(); + /// expect_lint: avoid_late_keyword late final colorTween3 = colorTween2; - /// expect_lint: avoid_late_keyword + /// ignored_types: Animation late final AnimationController controller1; + /// expect_lint: avoid_late_keyword late final local1 = 'string'; /// expect_lint: avoid_late_keyword late final String local2; + /// expect_lint: avoid_late_keyword late final String local4 = 'string'; /// expect_lint: avoid_late_keyword From fe851e8dcc962be4e3c36ac6fb1add670b2ddbe8 Mon Sep 17 00:00:00 2001 From: elijah mac Date: Thu, 30 Jan 2025 09:09:35 +0200 Subject: [PATCH 02/10] Fixed avoid_late_keyword_no_generics_test.dart --- .../avoid_late_keyword_no_generics_test.dart | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart b/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart index 12fea482..7c166749 100644 --- a/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart +++ b/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart @@ -15,38 +15,38 @@ class AvoidLateKeyword { /// expect_lint: avoid_late_keyword late final NotAllowed na1; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription subscription1; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription subscription2; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription> subscription3; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription>> subscription4; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription> subscription5; void test() { /// expect_lint: avoid_late_keyword late final NotAllowed na1; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription subscription1; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription subscription2; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription> subscription3; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription>> subscription4; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription> subscription5; } } From 9dd904fc8a52c2cecac9c6649899ef94deecacab Mon Sep 17 00:00:00 2001 From: elijah mac Date: Thu, 30 Jan 2025 09:22:51 +0200 Subject: [PATCH 03/10] Fixed avoid_late_keyword_with_generics_test.dart --- ...avoid_late_keyword_with_generics_test.dart | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart b/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart index 576ade7b..9778438e 100644 --- a/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart +++ b/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart @@ -7,6 +7,8 @@ class AnimationController {} class SubAnimationController extends AnimationController {} +class Allowed {} + class NotAllowed {} class Subscription {} @@ -18,19 +20,22 @@ class ConcreteTypeWithNoGenerics {} /// `avoid_late_keyword` /// allow_initialized option enabled class AvoidLateKeyword { - /// expect_lint: avoid_late_keyword + /// ignored_types: ColorTween late final ColorTween colorTween; - /// expect_lint: avoid_late_keyword + /// ignored_types: AnimationController late final AnimationController controller1; - /// expect_lint: avoid_late_keyword + /// ignored_types: AnimationController late final SubAnimationController controller2; + /// ignored_types: AnimationController late final controller3 = AnimationController(); + /// ignored_types: AnimationController late final controller4 = SubAnimationController(); + /// allow_initialized: true late final field1 = 'string'; /// expect_lint: avoid_late_keyword @@ -42,43 +47,47 @@ class AvoidLateKeyword { /// expect_lint: avoid_late_keyword late final NotAllowed na1; - late final na2 = NotAllowed(); + /// allow_initialized: true + late final a = Allowed(); /// expect_lint: avoid_late_keyword late final Subscription subscription1; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription subscription2; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription> late final Subscription> subscription3; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription> late final Subscription>> subscription4; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription> late final Subscription> subscription5; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription> late final Subscription> subscription6; /// expect_lint: avoid_late_keyword late final Subscription> subscription7; void test() { - /// expect_lint: avoid_late_keyword + /// ignored_types: ColorTween late final ColorTween colorTween; - /// expect_lint: avoid_late_keyword + /// ignored_types: AnimationController late final AnimationController controller1; - /// expect_lint: avoid_late_keyword + /// ignored_types: AnimationController late final SubAnimationController controller2; + /// ignored_types: AnimationController late final controller3 = AnimationController(); + /// ignored_types: AnimationController late final controller4 = SubAnimationController(); + /// allow_initialized: true late final local1 = 'string'; /// expect_lint: avoid_late_keyword @@ -90,15 +99,16 @@ class AvoidLateKeyword { /// expect_lint: avoid_late_keyword late final NotAllowed na1; - late final na2 = NotAllowed(); + /// allow_initialized: true + late final a = Allowed(); /// expect_lint: avoid_late_keyword late final Subscription subscription1; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription late final Subscription subscription2; - /// expect_lint: avoid_late_keyword + /// ignored_types: Subscription> late final Subscription> subscription3; } } From bc076a5d8a342f7941d5baea035e4dff4b955437 Mon Sep 17 00:00:00 2001 From: elijah mac Date: Thu, 30 Jan 2025 09:27:16 +0200 Subject: [PATCH 04/10] Fixed avoid_using_api external_source test --- .../avoid_using_api/external_source/lib/banned_library.dart | 1 - .../avoid_using_api/external_source/lib/external_source.dart | 1 - 2 files changed, 2 deletions(-) diff --git a/lint_test/avoid_using_api/external_source/lib/banned_library.dart b/lint_test/avoid_using_api/external_source/lib/banned_library.dart index abad4800..d36ffcde 100644 --- a/lint_test/avoid_using_api/external_source/lib/banned_library.dart +++ b/lint_test/avoid_using_api/external_source/lib/banned_library.dart @@ -1,2 +1 @@ -// expect_lint: avoid_global_state int banned = 5; diff --git a/lint_test/avoid_using_api/external_source/lib/external_source.dart b/lint_test/avoid_using_api/external_source/lib/external_source.dart index 4b2d78dc..bd422108 100644 --- a/lint_test/avoid_using_api/external_source/lib/external_source.dart +++ b/lint_test/avoid_using_api/external_source/lib/external_source.dart @@ -21,5 +21,4 @@ const test2 = 'Hello World'; void test() {} -// expect_lint: avoid_global_state int banned = 5; From 7d16f54bc4bf153de6ffb529bb91f82aeef14ae0 Mon Sep 17 00:00:00 2001 From: elijah mac Date: Thu, 30 Jan 2025 09:30:13 +0200 Subject: [PATCH 05/10] Fixed no_magic_number_allowed_in_widget_params_test.dart --- .../no_magic_number_allowed_in_widget_params_test.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart b/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart index 7d603d21..b9f21f1a 100644 --- a/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart +++ b/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart @@ -24,9 +24,10 @@ class MyWidgetDecoration { Widget build() { return MyWidget( - // expect_lint: no_magic_number + /// allowed_in_widget_params: true decoration: MyWidgetDecoration(size: 12), - // expect_lint: no_magic_number + + /// allowed_in_widget_params: true value: 23, ); } From 2c08c3528392e253c767d8ac53fcc4a37331888f Mon Sep 17 00:00:00 2001 From: elijah mac Date: Thu, 30 Jan 2025 09:46:58 +0200 Subject: [PATCH 06/10] Fixed alphabetize_by_type_test.dart --- .../alphabetize_by_type_test/alphabetize_by_type_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart b/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart index 498188fa..e26d062e 100644 --- a/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart +++ b/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart @@ -6,8 +6,8 @@ /// alphabetical-by-type option enabled class CorrectAlphabeticalByTypeClass { - final int a = 1; final double e = 1; + final int a = 1; } class WrongAlphabeticalByTypeClass { From 455c439af43f6534ff1c541faa0dc4ed639a6a48 Mon Sep 17 00:00:00 2001 From: elijah mac Date: Thu, 30 Jan 2025 11:37:14 +0200 Subject: [PATCH 07/10] Fixed prefer_match_file_name_rule.dart --- .../prefer_match_file_name/prefer_match_file_name_rule.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/lints/prefer_match_file_name/prefer_match_file_name_rule.dart b/lib/src/lints/prefer_match_file_name/prefer_match_file_name_rule.dart index 8c228a3a..26c52e90 100644 --- a/lib/src/lints/prefer_match_file_name/prefer_match_file_name_rule.dart +++ b/lib/src/lints/prefer_match_file_name/prefer_match_file_name_rule.dart @@ -87,7 +87,9 @@ class PreferMatchFileNameRule extends SolidLintRule { if (_doNormalizedNamesMatch( resolver.source.fullName, firstDeclaration.token.lexeme, - )) return; + )) { + return; + } final nodeType = humanReadableNodeType(firstDeclaration.parent).toLowerCase(); From 1e85fa532f3a7f4d969eb55395bf570d90aca141 Mon Sep 17 00:00:00 2001 From: elijah mac Date: Thu, 30 Jan 2025 15:03:46 +0200 Subject: [PATCH 08/10] Fixed function_lines_of_code_rule.dart --- .../function_lines_of_code_rule.dart | 24 +++++++--- .../analysis_options.yaml | 7 ++- .../function_lines_of_code_test.dart | 46 ++++++++++++++++++- 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart b/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart index 16593077..a723abb3 100644 --- a/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart +++ b/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart @@ -50,15 +50,25 @@ class FunctionLinesOfCodeRule ) { void checkNode(AstNode node) => _checkNode(resolver, reporter, node); - context.registry.addDeclaration((declarationNode) { - final isIgnored = config.parameters.exclude.shouldIgnore(declarationNode); + void checkDeclarationNode(Declaration node) { + final isIgnored = config.parameters.exclude.shouldIgnore(node); + if (isIgnored) { + return; + } + checkNode(node); + } - if (isIgnored) return; + // Check for an anonymous function + void checkFunctionExpressionNode(FunctionExpression node) { + if (node.parent is FunctionDeclaration) { + return; + } + checkNode(node); + } - context.registry.addMethodDeclaration(checkNode); - context.registry.addFunctionDeclaration(checkNode); - context.registry.addFunctionExpression(checkNode); - }); + context.registry.addFunctionDeclaration(checkDeclarationNode); + context.registry.addMethodDeclaration(checkDeclarationNode); + context.registry.addFunctionExpression(checkFunctionExpressionNode); } void _checkNode( diff --git a/lint_test/function_lines_of_code_test/analysis_options.yaml b/lint_test/function_lines_of_code_test/analysis_options.yaml index 96985aa8..459a4d79 100644 --- a/lint_test/function_lines_of_code_test/analysis_options.yaml +++ b/lint_test/function_lines_of_code_test/analysis_options.yaml @@ -7,5 +7,8 @@ custom_lint: - function_lines_of_code: max_lines: 5 exclude: - - longFunctionExcluded - - longMethodExcluded + - class_name: ClassWithLongMethods + method_name: longMethodExcluded + - method_name: longFunctionExcluded + - longFunctionExcludedByDeclarationName + - longMethodExcludedByDeclarationName diff --git a/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart b/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart index e35d5d6f..032f5cd6 100644 --- a/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart +++ b/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart @@ -256,7 +256,7 @@ class ClassWithLongMethods { return i; } - // Excluded by excludeNames + // Excluded by method_name int longMethodExcluded() { var i = 0; i++; @@ -267,6 +267,17 @@ class ClassWithLongMethods { return i; } +// Excluded by declaration_name + int longMethodExcludedByDeclarationName() { + var i = 0; + i++; + i++; + i++; + i++; + + return i; + } + int notLongMethod() { var i = 0; i++; @@ -481,7 +492,7 @@ int longFunction() { return i; } -// Excluded by excludeNames +// Excluded by method_name int longFunctionExcluded() { var i = 0; i++; @@ -491,3 +502,34 @@ int longFunctionExcluded() { return i; } + +// Excluded by declaration_name +int longFunctionExcludedByDeclarationName() { + var i = 0; + i++; + i++; + i++; + i++; + + return i; +} + +// expect_lint: function_lines_of_code +final longAnonymousFunction = () { + var i = 0; + i++; + i++; + i++; + i++; + + return i; +}; + +final notLongAnonymousFunction = () { + var i = 0; + i++; + i++; + i++; + + return i; +}; From f3a307699cbdf0fe63f5d5384953b8d1291b8059 Mon Sep 17 00:00:00 2001 From: elijah mac Date: Thu, 30 Jan 2025 15:40:32 +0200 Subject: [PATCH 09/10] Deleted avoid_unused_parameters_test folder --- .../analysis_options.yaml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 lint_test/avoid_unused_parameters_test/analysis_options.yaml diff --git a/lint_test/avoid_unused_parameters_test/analysis_options.yaml b/lint_test/avoid_unused_parameters_test/analysis_options.yaml deleted file mode 100644 index c90e9133..00000000 --- a/lint_test/avoid_unused_parameters_test/analysis_options.yaml +++ /dev/null @@ -1,11 +0,0 @@ -analyzer: - plugins: - - ../custom_lint - -custom_lint: - rules: - - avoid_unused_parameters: - exclude: - - class_name: Exclude - method_name: excludeMethod - - method_name: excludeMethod From a68712ee39159a73f32ae8e1c8fd7b019df17abf Mon Sep 17 00:00:00 2001 From: Yurii Prykhodko <144313329+yurii-prykhodko-solid@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:20:40 +0200 Subject: [PATCH 10/10] Update lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart --- .../function_lines_of_code/function_lines_of_code_rule.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart b/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart index a723abb3..e77a3590 100644 --- a/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart +++ b/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart @@ -60,6 +60,9 @@ class FunctionLinesOfCodeRule // Check for an anonymous function void checkFunctionExpressionNode(FunctionExpression node) { + // If a FunctionExpression is an immediate child of a FunctionDeclaration + // this means it's a named function, which are already check as part of + // addFunctionDeclaration call. if (node.parent is FunctionDeclaration) { return; }