From 100801598eada8230ba1c92fbecb205dcc3c70a5 Mon Sep 17 00:00:00 2001 From: shaark Date: Thu, 5 Dec 2024 18:13:38 +0200 Subject: [PATCH] issue-167. fixed after comments --- .../excluded_identifier_parameter.dart | 8 ++++++-- .../excluded_identifiers_list_parameter.dart | 19 +++++++++++++++---- lint_test/analysis_options.yaml | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/src/common/parameters/excluded_identifier_parameter.dart b/lib/src/common/parameters/excluded_identifier_parameter.dart index c886a7f..f55f970 100644 --- a/lib/src/common/parameters/excluded_identifier_parameter.dart +++ b/lib/src/common/parameters/excluded_identifier_parameter.dart @@ -1,15 +1,19 @@ /// Model class for ExcludeRule parameters class ExcludedIdentifierParameter { /// The name of the method that should be excluded from the lint. - final String methodName; + final String? methodName; /// The name of the class that should be excluded from the lint. final String? className; + /// The name of the plain Strings that should be excluded from the lint + final String? declarationName; + /// Constructor for [ExcludedIdentifierParameter] model const ExcludedIdentifierParameter({ - required this.methodName, + this.methodName, this.className, + this.declarationName, }); /// diff --git a/lib/src/common/parameters/excluded_identifiers_list_parameter.dart b/lib/src/common/parameters/excluded_identifiers_list_parameter.dart index 48a45d4..96db25b 100644 --- a/lib/src/common/parameters/excluded_identifiers_list_parameter.dart +++ b/lib/src/common/parameters/excluded_identifiers_list_parameter.dart @@ -29,7 +29,7 @@ class ExcludedIdentifiersListParameter { } else if (item is String) { exclude.add( ExcludedIdentifierParameter( - methodName: item, + declarationName: item, ), ); } @@ -56,7 +56,7 @@ class ExcludedIdentifiersListParameter { } else if (item is String) { exclude.add( ExcludedIdentifierParameter( - methodName: item, + declarationName: item, ), ); } @@ -68,10 +68,21 @@ class ExcludedIdentifiersListParameter { /// Returns whether the target node should be ignored during analysis. bool shouldIgnore(Declaration node) { - final declaredName = node.declaredElement?.name; + final declarationName = node.declaredElement?.name; final excludedItem = exclude.firstWhereOrNull( - (e) => e.methodName == declaredName || e.className == declaredName, + (e) { + if (e.declarationName == declarationName) { + return true; + } else if (node is ClassDeclaration) { + return e.className == declarationName; + } else if (node is MethodDeclaration) { + return e.methodName == declarationName; + } else if (node is FunctionDeclaration) { + return e.methodName == declarationName; + } + return false; + }, ); if (excludedItem == null) return false; diff --git a/lint_test/analysis_options.yaml b/lint_test/analysis_options.yaml index ffabfbe..10c18f3 100644 --- a/lint_test/analysis_options.yaml +++ b/lint_test/analysis_options.yaml @@ -39,6 +39,7 @@ custom_lint: - method_name: excludeMethod - simpleMethodName - SimpleClassName + - exclude - newline_before_return - no_empty_block: exclude: