Skip to content

Commit cc0e0cf

Browse files
author
Illia Aihistov
committed
feat: ignore magic numbers within record literals and named record fields
1 parent e31a5d9 commit cc0e0cf

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/src/lints/no_magic_number/visitors/no_magic_number_rule_visitor.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ class NoMagicNumberRuleVisitor extends SimpleAstVisitor<void> {
8080
/// intermediate [PrefixExpression] node.
8181
bool _isNotInsideCollectionLiteral(Literal l) {
8282
final p = _effectiveParent(l);
83-
return p is! TypedLiteral && p is! MapLiteralEntry;
83+
return p is! TypedLiteral &&
84+
p is! MapLiteralEntry &&
85+
p is! RecordLiteral &&
86+
!(p is NamedExpression && p.parent is RecordLiteral);
8487
}
8588

8689
bool _isNotInsideConstConstructor(Literal l) =>

test/src/lints/no_magic_number/no_magic_number_rule_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ class Duration {
287287
288288
@Timeout(Duration(seconds: 30))
289289
void fn() {}
290+
''');
291+
}
292+
293+
Future<void> test_does_not_report_in_records() async {
294+
await assertNoDiagnostics(r'''
295+
void fn() {
296+
var point = (10, 20);
297+
var named = (x: 100, y: 200);
298+
}
290299
''');
291300
}
292301
}

0 commit comments

Comments
 (0)