@@ -59,6 +59,14 @@ import 'package:solid_lints/src/models/solid_lint_rule.dart';
5959/// bool canDrive(int age, {bool isUSA = false}) {
6060/// return isUSA ? age >= 16 : age > 18; // LINT
6161/// }
62+ ///
63+ /// class Circle {
64+ /// final int r;
65+ /// const Circle({required this.r});
66+ /// }
67+ /// Circle(r: 5); // LINT
68+ /// var circle = Circle(r: 10); // LINT
69+ /// final circle2 = Circle(r: 10); // LINT
6270/// ```
6371///
6472/// #### GOOD:
@@ -74,6 +82,13 @@ import 'package:solid_lints/src/models/solid_lint_rule.dart';
7482/// bool canDrive(int age, {bool isUSA = false}) {
7583/// return isUSA ? age >= usaDrivingAge : age > worldWideDrivingAge;
7684/// }
85+ ///
86+ /// class Circle {
87+ /// final int r;
88+ /// const Circle({required this.r});
89+ /// }
90+ /// const Circle(r: 5);
91+ /// const circle = Circle(r: 10)
7792/// ```
7893///
7994/// ### Allowed
@@ -174,11 +189,24 @@ class NoMagicNumberRule extends SolidLintRule<NoMagicNumberParameters> {
174189 (l is IntegerLiteral &&
175190 ! config.parameters.allowedNumbers.contains (l.value));
176191
177- bool _isNotInsideVariable (Literal l) =>
178- l.thisOrAncestorMatching (
179- (ancestor) => ancestor is VariableDeclaration ,
180- ) ==
181- null ;
192+ bool _isNotInsideVariable (Literal l) {
193+ // Whether we encountered such node,
194+ // This is tracked because [InstanceCreationExpression] can be
195+ // inside [VariableDeclaration] removing unwanted literals
196+
197+ bool isInstanceCreationExpression = false ;
198+ return l.thisOrAncestorMatching ((ancestor) {
199+ if (ancestor is InstanceCreationExpression ) {
200+ isInstanceCreationExpression = true ;
201+ }
202+ if (isInstanceCreationExpression) {
203+ return false ;
204+ } else {
205+ return ancestor is VariableDeclaration ;
206+ }
207+ }) ==
208+ null ;
209+ }
182210
183211 bool _isNotInDateTime (Literal l) =>
184212 l.thisOrAncestorMatching (
@@ -206,10 +234,9 @@ class NoMagicNumberRule extends SolidLintRule<NoMagicNumberParameters> {
206234 }
207235
208236 bool _isNotInsideConstConstructor (Literal l) =>
209- l.thisOrAncestorMatching (
210- (ancestor) =>
211- ancestor is InstanceCreationExpression && ancestor.isConst,
212- ) ==
237+ l.thisOrAncestorMatching ((ancestor) {
238+ return ancestor is InstanceCreationExpression && ancestor.isConst;
239+ }) ==
213240 null ;
214241
215242 bool _isNotInsideIndexExpression (Literal l) => l.parent is ! IndexExpression ;
0 commit comments