-
Notifications
You must be signed in to change notification settings - Fork 24
refactor: migrate avoid_returning_widgets rule #243
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
Open
andrew-bekhiet-solid
wants to merge
25
commits into
analysis_server_migration
Choose a base branch
from
migrate/avoid_returning_widgets
base: analysis_server_migration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
43a6648
Created analysis_options.yaml rules parser
Dariaa14 87abe51
Improved yaml parser and added the analysis_options loader
Dariaa14 4c604a3
Improved rules loader from yaml
Dariaa14 87f5870
Added verification before looking for .yaml's path
Dariaa14 ca9df7c
Fields and getters are now declared before the constructor
Dariaa14 226a748
Added method to get options of a rule by it's name
Dariaa14 08c3e8e
Made suggested changes to file upward finder
Dariaa14 1eee0b2
Removed top-level variable
Dariaa14 0ef7917
Improved name of variable in loadRuleFromContext
Dariaa14 86c3f4d
Updated analysis options to have rules for each configuration file path
Dariaa14 e0490f7
Updated file upward finder to not mix File from dart.io with file fro…
Dariaa14 03a53ba
Added usage example in avoid_global_state_rule
Dariaa14 9f90265
style: move getters and fields before constructor
andrew-bekhiet-solid a8d53e4
style: improve readability
andrew-bekhiet-solid 73514fd
fix: don't parse enabled if the rule has configured options
andrew-bekhiet-solid c6a2453
feat: reload rules from file if newer
andrew-bekhiet-solid 55af03a
test: add AnalysisOptionsLoaderTest
andrew-bekhiet-solid 06c5367
feat(SolidLintRule): add parameter parsing
andrew-bekhiet-solid affc62c
fix: use Map<String, Object?> for raw rule config
andrew-bekhiet-solid 1b10b3d
fix: method name
andrew-bekhiet-solid 4c30ac9
fix: make sure rules options are loaded before getting parameters
andrew-bekhiet-solid 1cb4497
refactor: remove unused AnalysisOptionsLoader from AvoidGlobalStateRule
andrew-bekhiet-solid 0975ba7
refactor: extract duplicate logic
andrew-bekhiet-solid 20d709e
refactor: migrate avoid_returning_widgets rule
andrew-bekhiet-solid 5d06255
Merge remote-tracking branch 'origin/analysis_server_migration' into …
andrew-bekhiet-solid 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
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
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
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
84 changes: 84 additions & 0 deletions
84
lib/src/lints/avoid_returning_widgets/visitors/avoid_returning_widgets_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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import 'package:analyzer/dart/ast/ast.dart'; | ||
| import 'package:analyzer/dart/ast/visitor.dart'; | ||
| import 'package:analyzer/dart/element/element.dart'; | ||
| import 'package:analyzer/dart/element/type.dart'; | ||
| import 'package:solid_lints/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule.dart'; | ||
| import 'package:solid_lints/src/lints/avoid_returning_widgets/models/avoid_returning_widgets_parameters.dart'; | ||
| import 'package:solid_lints/src/utils/types_utils.dart'; | ||
|
|
||
| /// A visitor that reports on functions that return widgets. | ||
| class AvoidReturningWidgetsVisitor extends RecursiveAstVisitor<void> { | ||
| final AvoidReturningWidgetsRule _rule; | ||
| final AvoidReturningWidgetsParameters _parameters; | ||
|
|
||
| /// Creates a new instance of [AvoidReturningWidgetsVisitor] | ||
| AvoidReturningWidgetsVisitor(this._rule, this._parameters); | ||
|
|
||
| @override | ||
| void visitFunctionDeclaration(FunctionDeclaration node) { | ||
| super.visitFunctionDeclaration(node); | ||
|
|
||
| _visitDeclaration(node); | ||
| } | ||
|
|
||
| @override | ||
| void visitMethodDeclaration(MethodDeclaration node) { | ||
| super.visitMethodDeclaration(node); | ||
|
|
||
| _visitDeclaration(node); | ||
| } | ||
|
|
||
| @override | ||
| void visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { | ||
| super.visitFunctionDeclarationStatement(node); | ||
|
|
||
| _visitDeclaration(node.functionDeclaration); | ||
| } | ||
|
|
||
| void _visitDeclaration(Declaration node) { | ||
| if (node is! FunctionDeclaration && node is! MethodDeclaration) { | ||
| return; | ||
| } | ||
|
|
||
| final returnType = switch (node) { | ||
| Declaration( | ||
| declaredFragment: ExecutableFragment( | ||
| element: ExecutableElement(type: FunctionType(:final returnType)) | ||
| ) | ||
| ) => | ||
| returnType, | ||
| MethodDeclaration(returnType: TypeAnnotation(:final type)) => type, | ||
| FunctionDeclaration(returnType: TypeAnnotation(:final type)) => type, | ||
| _ => null, | ||
| }; | ||
| if (returnType == null) return; | ||
|
|
||
| final isWidgetReturned = hasWidgetType(returnType); | ||
| if (!isWidgetReturned) return; | ||
|
|
||
| final isIgnored = _parameters.exclude.shouldIgnore(node); | ||
| if (isIgnored) return; | ||
|
|
||
| if (_isOverridden(node)) return; | ||
|
|
||
| _rule.reportAtNode(node); | ||
| } | ||
|
|
||
| bool _isOverridden(Declaration node) { | ||
| return switch (node) { | ||
| Declaration( | ||
| declaredFragment: Fragment( | ||
| element: Element( | ||
| name: final String name, | ||
| enclosingElement: final InterfaceElement enclosingElement | ||
| ) | ||
| ), | ||
| ) => | ||
| enclosingElement.getInheritedMember( | ||
| Name.forLibrary(enclosingElement.library, name), | ||
| ) != | ||
| null, | ||
| _ => false, | ||
| }; | ||
| } | ||
| } |
11 changes: 0 additions & 11 deletions
11
lint_test/avoid_returning_widget_test/analysis_options.yaml
This file was deleted.
Oops, something went wrong.
96 changes: 0 additions & 96 deletions
96
lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Oops, something went wrong.
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.