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 33## Unreleased
44
55* chore: activate new lint rules.
6+ * fix: correctly handle const maps in ` no-magic-number ` .
67
78## 4.11.0-dev.1
89
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ class NoMagicNumberRule extends CommonRule {
4040 .where (_isMagicNumber)
4141 .where (_isNotInsideVariable)
4242 .where (_isNotInsideCollectionLiteral)
43+ .where (_isNotInsideConstMap)
4344 .where (_isNotInsideConstConstructor)
4445 .where (_isNotInDateTime)
4546 .map ((lit) => createIssue (
@@ -75,6 +76,12 @@ class NoMagicNumberRule extends CommonRule {
7576
7677 bool _isNotInsideCollectionLiteral (Literal l) => l.parent is ! TypedLiteral ;
7778
79+ bool _isNotInsideConstMap (Literal l) {
80+ final grandParent = l.parent? .parent;
81+
82+ return ! (grandParent is SetOrMapLiteral && grandParent.isConst);
83+ }
84+
7885 bool _isNotInsideConstConstructor (Literal l) =>
7986 l.thisOrAncestorMatching ((ancestor) =>
8087 ancestor is InstanceCreationExpression && ancestor.isConst) ==
Original file line number Diff line number Diff line change @@ -2,5 +2,17 @@ const pi = 3.14;
22const pi2 = pi * 2 ;
33const str = 'Hello' ;
44
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