@@ -67,7 +67,7 @@ class _Visitor extends SimpleAstVisitor<void> {
6767 var keyword = node.keyword;
6868 keyword ?? =
6969 node.thisOrAncestorOfType <PatternVariableDeclaration >()? .keyword;
70- if (keyword? .type != Keyword .FINAL ) return ;
70+ if (keyword == null || keyword .type != Keyword .FINAL ) return ;
7171
7272 var errorCode = getErrorCode (node.matchedValueType);
7373 rule.reportLintForToken (keyword, errorCode: errorCode);
@@ -95,9 +95,11 @@ class _Visitor extends SimpleAstVisitor<void> {
9595 // loop. `a` is a variable declared outside the loop.
9696 if (forLoopParts is ForEachPartsWithDeclaration ) {
9797 var loopVariable = forLoopParts.loopVariable;
98+ var keyword = loopVariable.keyword;
99+ if (keyword == null ) return ;
98100 if (loopVariable.isFinal) {
99101 var errorCode = getErrorCode (loopVariable.type);
100- rule.reportLintForToken (loopVariable. keyword, errorCode: errorCode);
102+ rule.reportLintForToken (keyword, errorCode: errorCode);
101103 }
102104 } else if (forLoopParts is ForEachPartsWithPattern ) {
103105 var keyword = forLoopParts.keyword;
@@ -112,9 +114,11 @@ class _Visitor extends SimpleAstVisitor<void> {
112114
113115 @override
114116 void visitVariableDeclarationStatement (VariableDeclarationStatement node) {
117+ var keyword = node.variables.keyword;
118+ if (keyword == null ) return ;
115119 if (node.variables.isFinal) {
116120 var errorCode = getErrorCode (node.variables.type);
117- rule.reportLintForToken (node.variables. keyword, errorCode: errorCode);
121+ rule.reportLintForToken (keyword, errorCode: errorCode);
118122 }
119123 }
120124}
0 commit comments