Skip to content

Commit 1bf6653

Browse files
Daniil Marchenkoyurii-prykhodko-solid
andauthored
Update analyzer dependency (#104)
* analyzer plugin update * rm solid_lints.iml * rm FunctionDeclaration * Dedupe loc lint warnings --------- Co-authored-by: Yurii Prykhodko <[email protected]>
1 parent cd7aa10 commit 1bf6653

File tree

5 files changed

+30
-35
lines changed

5 files changed

+30
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#IDEA Files
22
/.idea/
3+
solid_lints.iml
34

45
# Files and directories created by pub.
56
.dart_tool/

lib/lints/function_lines_of_code/function_lines_of_code_metric.dart

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,33 @@ class FunctionLinesOfCodeMetric
4646
ErrorReporter reporter,
4747
CustomLintContext context,
4848
) {
49-
context.registry.addDeclaration((node) {
50-
if (node
51-
case FunctionDeclaration() ||
52-
MethodDeclaration() ||
53-
FunctionExpression() ||
54-
FunctionBody()) {
55-
final visitor = FunctionLinesOfCodeVisitor(resolver.lineInfo);
56-
node.visitChildren(visitor);
49+
void checkNode(AstNode node) => _checkNode(resolver, reporter, node);
5750

58-
if (visitor.linesWithCode.length > config.parameters.maxLines) {
59-
reporter.reportErrorForOffset(
60-
code,
61-
node.firstTokenAfterCommentAndMetadata.offset,
62-
node.end,
63-
);
64-
}
51+
context.registry.addMethodDeclaration(checkNode);
52+
context.registry.addFunctionExpression(checkNode);
53+
}
54+
55+
void _checkNode(
56+
CustomLintResolver resolver,
57+
ErrorReporter reporter,
58+
AstNode node,
59+
) {
60+
final visitor = FunctionLinesOfCodeVisitor(resolver.lineInfo);
61+
node.visitChildren(visitor);
62+
63+
if (visitor.linesWithCode.length > config.parameters.maxLines) {
64+
if (node is! AnnotatedNode) {
65+
return reporter.reportErrorForNode(code, node);
6566
}
66-
});
67+
68+
final startOffset = node.firstTokenAfterCommentAndMetadata.offset;
69+
final lengthDifference = startOffset - node.offset;
70+
71+
reporter.reportErrorForOffset(
72+
code,
73+
startOffset,
74+
node.length - lengthDifference,
75+
);
76+
}
6777
}
6878
}

lint_test/lines_of_code_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class A {
126126
class B {
127127
/// expect_lint: function_lines_of_code
128128
void anon() {
129+
/// expect_lint: function_lines_of_code
129130
test("addition", () {
130131
expect(1 + 1, equals(2));
131132
test("addition", () {

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ environment:
99
sdk: '>=3.0.0 <4.0.0'
1010

1111
dependencies:
12-
analyzer: ^6.0.0
12+
analyzer: ^6.2.0
1313
collection: ^1.17.2
14-
custom_lint_builder: ^0.5.6
14+
custom_lint_builder: ^0.5.8
1515
glob: ^2.1.2
1616
path: ^1.8.3
1717
yaml: ^3.1.2

solid_lints.iml

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)