OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library linter.src.rules.parameter_assignments; | 5 library linter.src.rules.parameter_assignments; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
9 import 'package:linter/src/linter.dart'; | 9 import 'package:linter/src/linter.dart'; |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 @override | 62 @override |
63 AstVisitor getVisitor() => _visitor; | 63 AstVisitor getVisitor() => _visitor; |
64 } | 64 } |
65 | 65 |
66 class _Visitor extends SimpleAstVisitor { | 66 class _Visitor extends SimpleAstVisitor { |
67 final LintRule rule; | 67 final LintRule rule; |
68 _Visitor(this.rule); | 68 _Visitor(this.rule); |
69 | 69 |
70 @override | 70 @override |
71 void visitFunctionDeclaration(FunctionDeclaration node) { | 71 void visitFunctionDeclaration(FunctionDeclaration node) { |
72 node.functionExpression.parameters.parameters.forEach((e) { | 72 FormalParameterList parameters = node.functionExpression.parameters; |
73 if (node.functionExpression.body.isPotentiallyMutatedInScope(e.element)) { | 73 if (parameters != null) { |
74 rule.reportLint(e); | 74 // Getter do not have formal parameters. |
75 } | 75 parameters.parameters.forEach((e) { |
76 }); | 76 if (node.functionExpression.body |
| 77 .isPotentiallyMutatedInScope(e.element)) { |
| 78 rule.reportLint(e); |
| 79 } |
| 80 }); |
| 81 } |
77 } | 82 } |
78 | 83 |
79 @override | 84 @override |
80 void visitMethodDeclaration(MethodDeclaration node) { | 85 void visitMethodDeclaration(MethodDeclaration node) { |
81 FormalParameterList parameterList = node.parameters; | 86 FormalParameterList parameterList = node.parameters; |
82 if (parameterList != null) { | 87 if (parameterList != null) { |
83 // Getters don't have parameters. | 88 // Getters don't have parameters. |
84 parameterList.parameters.forEach((e) { | 89 parameterList.parameters.forEach((e) { |
85 if (node.body.isPotentiallyMutatedInScope(e.element)) { | 90 if (node.body.isPotentiallyMutatedInScope(e.element)) { |
86 rule.reportLint(e); | 91 rule.reportLint(e); |
87 } | 92 } |
88 }); | 93 }); |
89 } | 94 } |
90 } | 95 } |
91 } | 96 } |
OLD | NEW |