-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* issue-167. extract exclude rule code * issue-167. fixed null check * issue-167. fixed after comments * issue-167. fixed after comments * issue-167. fixed comments * issue-167. fixed after comments * issue-167. fixed after comments --------- Co-authored-by: shaark <[email protected]>
- Loading branch information
1 parent
956d433
commit 3ee83ca
Showing
4 changed files
with
70 additions
and
40 deletions.
There are no files selected for viewing
12 changes: 6 additions & 6 deletions
12
...dels/avoid_returning_widgets_exclude.dart → ...meters/excluded_identifier_parameter.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
lib/src/common/parameters/excluded_identifiers_list_parameter.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:collection/collection.dart'; | ||
import 'package:solid_lints/src/common/parameters/excluded_identifier_parameter.dart'; | ||
|
||
/// A model representing "exclude" parameters for linting, defining | ||
/// identifiers (classes, methods, functions) to be ignored during analysis. | ||
class ExcludedIdentifiersListParameter { | ||
/// A list of identifiers (classes, methods, functions) that should be | ||
/// excluded from the lint. | ||
final List<ExcludedIdentifierParameter> exclude; | ||
|
||
/// A common parameter key for analysis_options.yaml | ||
static const String excludeParameterName = 'exclude'; | ||
|
||
/// Constructor for [ExcludedIdentifiersListParameter] model | ||
ExcludedIdentifiersListParameter({ | ||
required this.exclude, | ||
}); | ||
|
||
/// Method for creating from json data | ||
factory ExcludedIdentifiersListParameter.fromJson({ | ||
required Iterable<dynamic> excludeList, | ||
}) { | ||
final exclude = <ExcludedIdentifierParameter>[]; | ||
|
||
for (final item in excludeList) { | ||
if (item is Map) { | ||
exclude.add(ExcludedIdentifierParameter.fromJson(item)); | ||
} | ||
} | ||
return ExcludedIdentifiersListParameter( | ||
exclude: exclude, | ||
); | ||
} | ||
|
||
/// Returns whether the target node should be ignored during analysis. | ||
bool shouldIgnore(Declaration node) { | ||
final methodName = node.declaredElement?.name; | ||
|
||
final excludedItem = | ||
exclude.firstWhereOrNull((e) => e.methodName == methodName); | ||
|
||
if (excludedItem == null) return false; | ||
|
||
final className = excludedItem.className; | ||
|
||
if (className == null || node is! MethodDeclaration) { | ||
return true; | ||
} else { | ||
final classDeclaration = node.thisOrAncestorOfType<ClassDeclaration>(); | ||
|
||
return classDeclaration != null && | ||
classDeclaration.name.toString() == className; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters