File tree Expand file tree Collapse file tree 2 files changed +64
-1
lines changed
Expand file tree Collapse file tree 2 files changed +64
-1
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ class ParameterAssignments extends AnalysisRule {
4242 var visitor = _Visitor (this );
4343 registry.addFunctionDeclaration (this , visitor);
4444 registry.addMethodDeclaration (this , visitor);
45+ registry.addFunctionExpression (this , visitor);
46+ registry.addConstructorDeclaration (this , visitor);
4547 }
4648}
4749
@@ -151,6 +153,11 @@ class _Visitor extends SimpleAstVisitor<void> {
151153
152154 _Visitor (this .rule);
153155
156+ @override
157+ void visitConstructorDeclaration (ConstructorDeclaration node) {
158+ _checkParameters (node.parameters, node.body);
159+ }
160+
154161 @override
155162 void visitFunctionDeclaration (FunctionDeclaration node) {
156163 _checkParameters (
@@ -159,6 +166,13 @@ class _Visitor extends SimpleAstVisitor<void> {
159166 );
160167 }
161168
169+ @override
170+ void visitFunctionExpression (FunctionExpression node) {
171+ if (node.parent is ! FunctionDeclaration ) {
172+ _checkParameters (node.parameters, node.body);
173+ }
174+ }
175+
162176 @override
163177 void visitMethodDeclaration (MethodDeclaration node) {
164178 _checkParameters (node.parameters, node.body);
Original file line number Diff line number Diff line change @@ -17,6 +17,43 @@ class ParameterAssignmentsTest extends LintRuleTest {
1717 @override
1818 String get lintRule => LintNames .parameter_assignments;
1919
20+ test_anonymousFunction_assignment () async {
21+ await assertDiagnostics (
22+ r'''
23+ void main() {
24+ (int i) {
25+ i = 42;
26+ }(0);
27+ }
28+ ''' ,
29+ [lint (30 , 6 )],
30+ );
31+ }
32+
33+ test_anonymousFunction_assignment_arrowBody () async {
34+ await assertDiagnostics (
35+ r'''
36+ void main() {
37+ (int i) => i = 42;
38+ }
39+ ''' ,
40+ [lint (27 , 6 )],
41+ );
42+ }
43+
44+ test_anonymousFunction_assignment_notInvoked () async {
45+ await assertDiagnostics (
46+ r'''
47+ void main() {
48+ (int i) {
49+ i = 42;
50+ };
51+ }
52+ ''' ,
53+ [lint (30 , 6 )],
54+ );
55+ }
56+
2057 test_assignment_inIfElseBranches () async {
2158 await assertDiagnostics (
2259 r'''
@@ -70,7 +107,6 @@ void f([int? _]) {
70107 );
71108 }
72109
73- @FailingTest (reason: 'Closures not implemented' )
74110 test_closure_assignment () async {
75111 await assertDiagnostics (
76112 r'''
@@ -95,6 +131,19 @@ void f(int p) {
95131 );
96132 }
97133
134+ test_constructor_assignment () async {
135+ await assertDiagnostics (
136+ r'''
137+ class Foo {
138+ Foo(int x) {
139+ x = 4;
140+ }
141+ }
142+ ''' ,
143+ [lint (31 , 5 )],
144+ );
145+ }
146+
98147 test_function_assignment () async {
99148 await assertDiagnostics (
100149 r'''
You can’t perform that action at this time.
0 commit comments