Skip to content

Commit

Permalink
issue-167. fixed after comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shaark committed Dec 5, 2024
1 parent 2cc9b19 commit 1008015
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/src/common/parameters/excluded_identifier_parameter.dart
Original file line number Diff line number Diff line change
@@ -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,
});

///
Expand Down
19 changes: 15 additions & 4 deletions lib/src/common/parameters/excluded_identifiers_list_parameter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ExcludedIdentifiersListParameter {
} else if (item is String) {
exclude.add(
ExcludedIdentifierParameter(
methodName: item,
declarationName: item,
),
);
}
Expand All @@ -56,7 +56,7 @@ class ExcludedIdentifiersListParameter {
} else if (item is String) {
exclude.add(
ExcludedIdentifierParameter(
methodName: item,
declarationName: item,
),
);
}
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lint_test/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ custom_lint:
- method_name: excludeMethod
- simpleMethodName
- SimpleClassName
- exclude
- newline_before_return
- no_empty_block:
exclude:
Expand Down

0 comments on commit 1008015

Please sign in to comment.