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

fix: support index expressions for no-magic-number rule #755

Merged
merged 1 commit into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

* fix: support index expressions for no-magic-number rule.

## 4.13.0

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

* 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).
* feat: support extensions and static getters for [`check-unused-l10n`](https://dartcodemetrics.dev/docs/cli/check-unused-l10n).
* 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.
* 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.
* feat: add `delete-files` flag to [`check-unused-files`](https://dartcodemetrics.dev/docs/cli/check-unused-files) command.
* feat: facelift console reporters.
* chore: restrict `analyzer` version to `>=2.4.0 <3.1.0`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class NoMagicNumberRule extends CommonRule {
.where(_isNotInsideConstMap)
.where(_isNotInsideConstConstructor)
.where(_isNotInDateTime)
.where(_isNotInsideIndexExpression)
.map((lit) => createIssue(
rule: this,
location: nodeLocation(
Expand Down Expand Up @@ -86,4 +87,6 @@ class NoMagicNumberRule extends CommonRule {
l.thisOrAncestorMatching((ancestor) =>
ancestor is InstanceCreationExpression && ancestor.isConst) ==
null;

bool _isNotInsideIndexExpression(Literal l) => l.parent is! IndexExpression;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
int good_f1(int x) => x + 1;
bool good_f2(int x) => x != 0;
bool good_f3(String x) => x.indexOf(str) != -1;
final someDay = DateTime(2006, 12, 1);
final anotherDay = DateTime.utc(2006, 12, 1);
final f = Intl.message(example: const <String, int>{'Assigned': 3});
final f = foo(const [32, 12]);
final f = Future.delayed(const Duration(seconds: 5));
final f = foo(const Bar(5));
final number = 500;
var number = 500;
var numbers = [100, 200, 300];
void main() {
int good_f1(int x) => x + 1;
bool good_f2(int x) => x != 0;
bool good_f3(String x) => x.indexOf(str) != -1;
final someDay = DateTime(2006, 12, 1);
final anotherDay = DateTime.utc(2006, 12, 1);
final f = Intl.message(example: const <String, int>{'Assigned': 3});
final f = foo(const [32, 12]);
final f = Future.delayed(const Duration(seconds: 5));
final f = foo(const Bar(5));
final number = 500;
var number = 500;
var numbers = [100, 200, 300];
numbers[0];

Map<int, String> m = {
1: '',
2: '',
3: '',
};
String? mv = m[2];
final mf = m[2];
print(m[2]);
}