This repository was archived by the owner on Jul 16, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed
lib/src/analyzers/lint_analyzer/rules/rules_list/no_magic_number
test/src/analyzers/lint_analyzer/rules/rules_list/no_magic_number/examples Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 3
3
## Unreleased
4
4
5
5
* chore: activate new lint rules.
6
+ * fix: correctly handle const maps in ` no-magic-number ` .
6
7
7
8
## 4.11.0-dev.1
8
9
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ class NoMagicNumberRule extends CommonRule {
40
40
.where (_isMagicNumber)
41
41
.where (_isNotInsideVariable)
42
42
.where (_isNotInsideCollectionLiteral)
43
+ .where (_isNotInsideConstMap)
43
44
.where (_isNotInsideConstConstructor)
44
45
.where (_isNotInDateTime)
45
46
.map ((lit) => createIssue (
@@ -75,6 +76,12 @@ class NoMagicNumberRule extends CommonRule {
75
76
76
77
bool _isNotInsideCollectionLiteral (Literal l) => l.parent is ! TypedLiteral ;
77
78
79
+ bool _isNotInsideConstMap (Literal l) {
80
+ final grandParent = l.parent? .parent;
81
+
82
+ return ! (grandParent is SetOrMapLiteral && grandParent.isConst);
83
+ }
84
+
78
85
bool _isNotInsideConstConstructor (Literal l) =>
79
86
l.thisOrAncestorMatching ((ancestor) =>
80
87
ancestor is InstanceCreationExpression && ancestor.isConst) ==
Original file line number Diff line number Diff line change @@ -2,5 +2,17 @@ const pi = 3.14;
2
2
const pi2 = pi * 2 ;
3
3
const str = 'Hello' ;
4
4
5
- void good_f4 (int x) => a * pi;
6
- void good_f5 () => good_f4 (pi2);
5
+ void fun1 (int x) => a * pi;
6
+ void fun2 () => fun1 (pi2);
7
+ void fun3 () => const {
8
+ 'Key.a' : 0.1 ,
9
+ 'Key.b' : 0.1 ,
10
+ 'Key.c' : 0.1 ,
11
+ };
12
+ void fun4 () {
13
+ return const {1 , 2 };
14
+ }
15
+
16
+ void fun5 () => const {1 , 2 };
17
+
18
+ void fun6 () => const Map <String , String >();
You can’t perform that action at this time.
0 commit comments