@@ -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}
0 commit comments