-
Notifications
You must be signed in to change notification settings - Fork 25
Make it possible to exclude extensions, entities and mixins from prefer_match_file_name rule
#206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yurii-prykhodko-solid
merged 21 commits into
solid-software:master
from
iimironchuk:ignore-extensions
May 5, 2025
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ea40baa
prefer_match_file_name ignore extensions
iimironchuk 261d661
extension ignored by parameter
iimironchuk 969bfc3
ignore some entity by exclude_entity
iimironchuk 5ef5a49
ignore some entity by exclude_entity
iimironchuk 6c9207d
ignore some entity by exclude_entity final variant
iimironchuk f572aff
Fix formatting
iimironchuk ff56afc
now the logic of ignoring entities can be reused
iimironchuk 3960ca4
suggested changes done
iimironchuk fdd18e3
added exclude_entity to analysis_options.yaml
iimironchuk 56c400e
fix in CHANGELOG
iimironchuk 90a987a
separate test case file + several declarations added
iimironchuk 988f69f
rm unused import
bf85077
Use Set for O(1) lookups
c320343
Add more test cases, do not advertise class support
b775620
Expand changelog entry
1e0d2a7
revert lib/analysis_options.yaml change
012ee33
revert lint_test/analysis_optinos.yaml change
a2f585d
rm obsolete comment
51c8a3a
rm custom_lint dependency from test package
3cd0752
rm duplicate rule
8bf640e
fmt
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
52 changes: 52 additions & 0 deletions
52
lib/src/common/parameters/excluded_entities_list_parameter.dart
This file contains hidden or 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,52 @@ | ||
| import 'package:analyzer/dart/ast/ast.dart'; | ||
|
|
||
| /// A model representing "exclude_entity" parameters for linting, defining | ||
| /// identifiers (classes, mixins, enums, extensions) to be ignored during | ||
| /// analysis. | ||
| /// Supported entities: | ||
| /// - mixin | ||
| /// - extension | ||
| /// - enum | ||
| class ExcludedEntitiesListParameter { | ||
| /// The parameter model | ||
| final Set<String> excludedEntityNames; | ||
|
|
||
| /// A common parameter key for analysis_options.yaml | ||
| static const String excludeEntityKey = 'exclude_entity'; | ||
|
|
||
| /// Constructor for [ExcludedEntitiesListParameter] class | ||
| ExcludedEntitiesListParameter({ | ||
| required this.excludedEntityNames, | ||
| }); | ||
|
|
||
| /// Method for creating from json data | ||
| factory ExcludedEntitiesListParameter.fromJson(Map<String, dynamic> json) { | ||
| final raw = json['exclude_entity']; | ||
| if (raw is List) { | ||
| return ExcludedEntitiesListParameter( | ||
| excludedEntityNames: Set<String>.from(raw), | ||
| ); | ||
| } | ||
|
|
||
| return ExcludedEntitiesListParameter( | ||
| excludedEntityNames: {}, | ||
| ); | ||
| } | ||
|
|
||
| /// Returns whether the target node should be ignored during analysis. | ||
| bool shouldIgnoreEntity(Declaration node) { | ||
| if (excludedEntityNames.isEmpty) return false; | ||
|
|
||
| if (node is MixinDeclaration && excludedEntityNames.contains('mixin')) { | ||
| return true; | ||
| } else if (node is EnumDeclaration && | ||
| excludedEntityNames.contains('enum')) { | ||
| return true; | ||
| } else if (node is ExtensionDeclaration && | ||
| excludedEntityNames.contains('extension')) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
lib/src/lints/prefer_match_file_name/models/prefer_match_file_name_parameters.dart
This file contains hidden or 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,19 @@ | ||
| import 'package:solid_lints/src/common/parameters/excluded_entities_list_parameter.dart'; | ||
|
|
||
| /// A data model class that represents the "prefer match file name" input | ||
| /// parameters | ||
| class PreferMatchFileNameParameters { | ||
| /// A list of entities that should be excluded from the lint. | ||
| final ExcludedEntitiesListParameter excludeEntity; | ||
|
|
||
| /// Constructor for [PreferMatchFileNameParameters] model | ||
| const PreferMatchFileNameParameters({ | ||
| required this.excludeEntity, | ||
| }); | ||
|
|
||
| /// Method for creating from json data | ||
| factory PreferMatchFileNameParameters.fromJson(Map<String, Object?> json) => | ||
| PreferMatchFileNameParameters( | ||
| excludeEntity: ExcludedEntitiesListParameter.fromJson(json), | ||
| ); | ||
| } |
This file contains hidden or 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
29 changes: 22 additions & 7 deletions
29
lib/src/lints/prefer_match_file_name/visitors/prefer_match_file_name_visitor.dart
This file contains hidden or 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
9 changes: 9 additions & 0 deletions
9
lint_test/prefer_match_file_name_ignore_entity/enum/analysis_options.yaml
This file contains hidden or 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,9 @@ | ||
| analyzer: | ||
| plugins: | ||
| - ../../../custom_lint | ||
|
|
||
| custom_lint: | ||
| rules: | ||
| - prefer_match_file_name: | ||
| exclude_entity: | ||
| - enum |
15 changes: 15 additions & 0 deletions
15
lint_test/prefer_match_file_name_ignore_entity/enum/test.dart
This file contains hidden or 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,15 @@ | ||
| // ignore_for_file: unused_element, unused_field | ||
|
|
||
| /// `prefer_match_file_name` rule will be ignored by this enttiy because of | ||
| /// exclude_entity: | ||
| /// - enum | ||
| /// in analysis_options.yaml | ||
| enum Ignored { _ } | ||
|
|
||
| enum IgnoredAgain { _ } | ||
|
|
||
| // expect_lint: prefer_match_file_name | ||
| abstract class WrongNamedClass {} | ||
|
|
||
| /// Only first public element declaration is checked | ||
| class PreferMatchFileNameIgnoreExtensions {} |
9 changes: 9 additions & 0 deletions
9
lint_test/prefer_match_file_name_ignore_entity/extension/analysis_options.yaml
This file contains hidden or 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,9 @@ | ||
| analyzer: | ||
| plugins: | ||
| - ../../../custom_lint | ||
|
|
||
| custom_lint: | ||
| rules: | ||
| - prefer_match_file_name: | ||
| exclude_entity: | ||
| - extension |
15 changes: 15 additions & 0 deletions
15
lint_test/prefer_match_file_name_ignore_entity/extension/test.dart
This file contains hidden or 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,15 @@ | ||
| // ignore_for_file: unused_element, unused_field | ||
|
|
||
| /// `prefer_match_file_name` rule will be ignored by this extension because of | ||
| /// exclude_entity: | ||
| /// - extension | ||
| /// in analysis_options.yaml | ||
| extension Ignored on String {} | ||
|
|
||
| extension IgnoredAgain on String {} | ||
|
|
||
| // expect_lint: prefer_match_file_name | ||
| abstract class WrongNamedClass {} | ||
|
|
||
| /// Only first public element declaration is checked | ||
| class PreferMatchFileNameIgnoreExtensions {} |
9 changes: 9 additions & 0 deletions
9
lint_test/prefer_match_file_name_ignore_entity/mixin/analysis_options.yaml
This file contains hidden or 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,9 @@ | ||
| analyzer: | ||
| plugins: | ||
| - ../../../custom_lint | ||
|
|
||
| custom_lint: | ||
| rules: | ||
| - prefer_match_file_name: | ||
| exclude_entity: | ||
| - mixin |
13 changes: 13 additions & 0 deletions
13
lint_test/prefer_match_file_name_ignore_entity/mixin/test.dart
This file contains hidden or 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,13 @@ | ||
| // ignore_for_file: unused_element, unused_field | ||
|
|
||
| /// `prefer_match_file_name` rule will be ignored by this entity because of | ||
| /// exclude_entity: | ||
| /// - mixin | ||
| /// in analysis_options.yaml | ||
| mixin IgnoredMixin {} | ||
|
|
||
| // expect_lint: prefer_match_file_name | ||
| abstract class WrongNamedClass {} | ||
|
|
||
| /// Only first public element declaration is checked | ||
| class PreferMatchFileNameIgnoreExtensions {} |
This file contains hidden or 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,5 @@ | ||
| // ignore_for_file: unused_element, unused_field | ||
|
|
||
| /// Check if the `prefer_match_file_name` rule ignored for extensions | ||
| // expect_lint: prefer_match_file_name | ||
| extension DefaultExtension on String {} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.