-
Notifications
You must be signed in to change notification settings - Fork 24
refactor: migrate function_lines_of_code rule #296
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
solid-illiaaihistov
merged 13 commits into
solid-software:analysis_server_migration
from
solid-illiaaihistov:251-migrate-function_lines_of_code
Jun 24, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c20a85d
refactor: migrate function_lines_of_code rule (#251)
7dca484
refactor: update function expression visitor logic
7683e73
refactor: migrate function_lines_of_code tests to AutoTestLintOffsets
ad21fe8
refactor: optimize currentUnit access in function lines of code visitor
b64df6a
feat: update description and add test case for function lines of code…
e6ba189
refactor: simplify lines of code visitor logic
5417f80
refactor: migrate function_lines_of_code rule tests to a table-driven…
02ac214
refactor: introduce TableDrivenRuleTest base class to consolidate tab…
c905eae
refactor: simplify test code generation by introducing string extensi…
d382c1c
Merge remote-tracking branch 'upstream/analysis_server_migration' int…
a097a03
refactor: move parameter parser initialization into FunctionLinesOfCo…
662d8a2
Merge remote-tracking branch 'upstream/analysis_server_migration' int…
d9a49f5
refactor: move cyclomatic complexity parameters initialization inside…
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
73 changes: 73 additions & 0 deletions
73
lib/src/lints/function_lines_of_code/visitors/function_lines_of_code_rule_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,73 @@ | ||
| import 'package:analyzer/analysis_rule/rule_context.dart'; | ||
| import 'package:analyzer/dart/ast/ast.dart'; | ||
| import 'package:analyzer/dart/ast/visitor.dart'; | ||
| import 'package:solid_lints/src/lints/function_lines_of_code/function_lines_of_code_rule.dart'; | ||
| import 'package:solid_lints/src/lints/function_lines_of_code/models/function_lines_of_code_parameters.dart'; | ||
| import 'package:solid_lints/src/lints/function_lines_of_code/visitors/function_lines_of_code_visitor.dart'; | ||
|
|
||
| /// A visitor that reports on functions/methods exceeding the max line limit. | ||
| class FunctionLinesOfCodeRuleVisitor extends RecursiveAstVisitor<void> { | ||
| final FunctionLinesOfCodeRule _rule; | ||
| final RuleContext _context; | ||
| final FunctionLinesOfCodeParameters _parameters; | ||
|
|
||
| /// Creates a new instance of [FunctionLinesOfCodeRuleVisitor]. | ||
| FunctionLinesOfCodeRuleVisitor(this._rule, this._context, this._parameters); | ||
|
|
||
| @override | ||
| void visitFunctionDeclaration(FunctionDeclaration node) { | ||
| final isIgnored = _parameters.exclude.shouldIgnore(node); | ||
| if (!isIgnored) { | ||
| _checkNode(node); | ||
| } | ||
| super.visitFunctionDeclaration(node); | ||
| } | ||
|
|
||
| @override | ||
| void visitMethodDeclaration(MethodDeclaration node) { | ||
| final isIgnored = _parameters.exclude.shouldIgnore(node); | ||
| if (!isIgnored) { | ||
| _checkNode(node); | ||
| } | ||
| super.visitMethodDeclaration(node); | ||
| } | ||
|
|
||
| @override | ||
| void visitFunctionExpression(FunctionExpression node) { | ||
| if (node.parent is! FunctionDeclaration) { | ||
| _checkNode(node); | ||
| } | ||
| super.visitFunctionExpression(node); | ||
| } | ||
|
|
||
| void _checkNode(AstNode node) { | ||
|
solid-illiaaihistov marked this conversation as resolved.
|
||
| final currentUnit = _context.currentUnit; | ||
| if (currentUnit == null) return; | ||
|
|
||
| final lineInfo = currentUnit.unit.lineInfo; | ||
| final visitor = FunctionLinesOfCodeVisitor(lineInfo); | ||
| node.visitChildren(visitor); | ||
| if (visitor.linesWithCode.length <= _parameters.maxLines) return; | ||
|
|
||
| final reporter = currentUnit.diagnosticReporter; | ||
| if (node is! AnnotatedNode) { | ||
| reporter.atNode( | ||
| node, | ||
| _rule.diagnosticCode, | ||
| arguments: [_parameters.maxLines], | ||
| ); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| final startOffset = node.firstTokenAfterCommentAndMetadata.offset; | ||
| final lengthDifference = startOffset - node.offset; | ||
|
|
||
| reporter.atOffset( | ||
| offset: startOffset, | ||
| length: node.length - lengthDifference, | ||
| diagnosticCode: _rule.diagnosticCode, | ||
| arguments: [_parameters.maxLines], | ||
| ); | ||
| } | ||
| } | ||
14 changes: 0 additions & 14 deletions
14
lint_test/function_lines_of_code_test/analysis_options.yaml
This file was deleted.
Oops, something went wrong.
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.