Skip to content

Commit 1008015

Browse files
author
shaark
committed
issue-167. fixed after comments
1 parent 2cc9b19 commit 1008015

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

lib/src/common/parameters/excluded_identifier_parameter.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
/// Model class for ExcludeRule parameters
22
class ExcludedIdentifierParameter {
33
/// The name of the method that should be excluded from the lint.
4-
final String methodName;
4+
final String? methodName;
55

66
/// The name of the class that should be excluded from the lint.
77
final String? className;
88

9+
/// The name of the plain Strings that should be excluded from the lint
10+
final String? declarationName;
11+
912
/// Constructor for [ExcludedIdentifierParameter] model
1013
const ExcludedIdentifierParameter({
11-
required this.methodName,
14+
this.methodName,
1215
this.className,
16+
this.declarationName,
1317
});
1418

1519
///

lib/src/common/parameters/excluded_identifiers_list_parameter.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ExcludedIdentifiersListParameter {
2929
} else if (item is String) {
3030
exclude.add(
3131
ExcludedIdentifierParameter(
32-
methodName: item,
32+
declarationName: item,
3333
),
3434
);
3535
}
@@ -56,7 +56,7 @@ class ExcludedIdentifiersListParameter {
5656
} else if (item is String) {
5757
exclude.add(
5858
ExcludedIdentifierParameter(
59-
methodName: item,
59+
declarationName: item,
6060
),
6161
);
6262
}
@@ -68,10 +68,21 @@ class ExcludedIdentifiersListParameter {
6868

6969
/// Returns whether the target node should be ignored during analysis.
7070
bool shouldIgnore(Declaration node) {
71-
final declaredName = node.declaredElement?.name;
71+
final declarationName = node.declaredElement?.name;
7272

7373
final excludedItem = exclude.firstWhereOrNull(
74-
(e) => e.methodName == declaredName || e.className == declaredName,
74+
(e) {
75+
if (e.declarationName == declarationName) {
76+
return true;
77+
} else if (node is ClassDeclaration) {
78+
return e.className == declarationName;
79+
} else if (node is MethodDeclaration) {
80+
return e.methodName == declarationName;
81+
} else if (node is FunctionDeclaration) {
82+
return e.methodName == declarationName;
83+
}
84+
return false;
85+
},
7586
);
7687

7788
if (excludedItem == null) return false;

lint_test/analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ custom_lint:
3939
- method_name: excludeMethod
4040
- simpleMethodName
4141
- SimpleClassName
42+
- exclude
4243
- newline_before_return
4344
- no_empty_block:
4445
exclude:

0 commit comments

Comments
 (0)