-
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
- Loading branch information
shaark
committed
Dec 4, 2024
1 parent
956d433
commit 23c62a8
Showing
4 changed files
with
65 additions
and
40 deletions.
There are no files selected for viewing
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
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,53 @@ | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:collection/collection.dart'; | ||
import 'package:solid_lints/src/models/exclude_rule.dart'; | ||
|
||
/// A data model class that represents the "avoid returning widgets" input | ||
/// parameters. | ||
class ExcludeParameters { | ||
/// A list of methods that should be excluded from the lint. | ||
final List<ExcludeRule> exclude; | ||
|
||
/// Constructor for [ExcludeParameters] model | ||
ExcludeParameters({ | ||
required this.exclude, | ||
}); | ||
|
||
/// Method for creating from json data | ||
factory ExcludeParameters.fromJson({ | ||
required Iterable<dynamic> excludeList, | ||
}) { | ||
final exclude = <ExcludeRule>[]; | ||
|
||
for (final item in excludeList) { | ||
if (item is Map) { | ||
exclude.add(ExcludeRule.fromJson(item)); | ||
} | ||
} | ||
return ExcludeParameters( | ||
exclude: exclude, | ||
); | ||
} | ||
|
||
/// Method to define ignoring | ||
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>(); | ||
|
||
if (classDeclaration == null) return false; | ||
|
||
return classDeclaration.name.toString() == className; | ||
} | ||
} | ||
} |
12 changes: 6 additions & 6 deletions
12
...dels/avoid_returning_widgets_exclude.dart → lib/src/models/exclude_rule.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