Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit bbab151

Browse files
authored
Merge 11e2254 into 6ae2211
2 parents 6ae2211 + 11e2254 commit bbab151

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* fix: support index expressions for no-magic-number rule.
6+
37
## 4.13.0
48

59
* feat: add [Checkstyle](https://dartcodemetrics.dev/docs/cli/analyze#checkstyle) format reporter.
@@ -67,7 +71,7 @@
6771

6872
* feat: add static code diagnostics [`avoid-global-state`](https://dartcodemetrics.dev/docs/rules/common/avoid-global-state), [`avoid-unrelated-type-assertions`](https://dartcodemetrics.dev/docs/rules/common/avoid-unrelated-type-assertions).
6973
* feat: support extensions and static getters for [`check-unused-l10n`](https://dartcodemetrics.dev/docs/cli/check-unused-l10n).
70-
* feat: improve [ `prefer-correct-type-name`](https://dartcodemetrics.dev/docs/rules/common/prefer-correct-type-name), [`prefer-match-file-name`](https://dartcodemetrics.dev/docs/rules/common/prefer-match-file-name) rules.
74+
* feat: improve [prefer-correct-type-name](https://dartcodemetrics.dev/docs/rules/common/prefer-correct-type-name), [`prefer-match-file-name`](https://dartcodemetrics.dev/docs/rules/common/prefer-match-file-name) rules.
7175
* feat: add `delete-files` flag to [`check-unused-files`](https://dartcodemetrics.dev/docs/cli/check-unused-files) command.
7276
* feat: facelift console reporters.
7377
* chore: restrict `analyzer` version to `>=2.4.0 <3.1.0`.

lib/src/analyzers/lint_analyzer/rules/rules_list/no_magic_number/no_magic_number_rule.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class NoMagicNumberRule extends CommonRule {
4343
.where(_isNotInsideConstMap)
4444
.where(_isNotInsideConstConstructor)
4545
.where(_isNotInDateTime)
46+
.where(_isNotInsideIndexExpression)
4647
.map((lit) => createIssue(
4748
rule: this,
4849
location: nodeLocation(
@@ -86,4 +87,6 @@ class NoMagicNumberRule extends CommonRule {
8687
l.thisOrAncestorMatching((ancestor) =>
8788
ancestor is InstanceCreationExpression && ancestor.isConst) ==
8889
null;
90+
91+
bool _isNotInsideIndexExpression(Literal l) => l.parent is! IndexExpression;
8992
}
Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
int good_f1(int x) => x + 1;
2-
bool good_f2(int x) => x != 0;
3-
bool good_f3(String x) => x.indexOf(str) != -1;
4-
final someDay = DateTime(2006, 12, 1);
5-
final anotherDay = DateTime.utc(2006, 12, 1);
6-
final f = Intl.message(example: const <String, int>{'Assigned': 3});
7-
final f = foo(const [32, 12]);
8-
final f = Future.delayed(const Duration(seconds: 5));
9-
final f = foo(const Bar(5));
10-
final number = 500;
11-
var number = 500;
12-
var numbers = [100, 200, 300];
1+
void main() {
2+
int good_f1(int x) => x + 1;
3+
bool good_f2(int x) => x != 0;
4+
bool good_f3(String x) => x.indexOf(str) != -1;
5+
final someDay = DateTime(2006, 12, 1);
6+
final anotherDay = DateTime.utc(2006, 12, 1);
7+
final f = Intl.message(example: const <String, int>{'Assigned': 3});
8+
final f = foo(const [32, 12]);
9+
final f = Future.delayed(const Duration(seconds: 5));
10+
final f = foo(const Bar(5));
11+
final number = 500;
12+
var number = 500;
13+
var numbers = [100, 200, 300];
14+
numbers[0];
15+
16+
Map<int, String> m = {
17+
1: '',
18+
2: '',
19+
3: '',
20+
};
21+
String? mv = m[2];
22+
final mf = m[2];
23+
print(m[2]);
24+
}

0 commit comments

Comments
 (0)