Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 87add35

Browse files
fix: handle dynamics in map literals for avoid-dynamic
1 parent 66f2cc9 commit 87add35

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

‎CHANGELOG.md‎

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

3+
## Unreleased
4+
5+
* fix: handle dynamics in map literals for [`avoid-dynamic`](https://dcm.dev/docs/individuals/rules/common/avoid-dynamic).
6+
37
## 5.6.0
48

59
* fix: correctly handle implicit type parameters for [`no-equal-arguments`](https://dcm.dev/docs/individuals/rules/common/no-equal-arguments).

‎lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_dynamic/visitor.dart‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ class _Visitor extends RecursiveAstVisitor<void> {
1010
final parent = node.parent;
1111
if (parent is NamedType && (parent.type?.isDynamic ?? false)) {
1212
final grandParent = node.parent?.parent;
13-
if (grandParent != null) {
14-
final grandGrandParent = grandParent.parent;
15-
if (!(grandGrandParent is NamedType &&
16-
(grandGrandParent.type?.isDartCoreMap ?? false))) {
17-
_nodes.add(grandParent);
18-
}
13+
if (grandParent != null && !_isWithinMap(grandParent)) {
14+
_nodes.add(grandParent);
1915
}
2016
}
2117
}
18+
19+
bool _isWithinMap(AstNode grandParent) {
20+
final grandGrandParent = grandParent.parent;
21+
22+
return grandGrandParent is NamedType &&
23+
(grandGrandParent.type?.isDartCoreMap ?? false) ||
24+
grandGrandParent is SetOrMapLiteral && grandGrandParent.isMap;
25+
}
2226
}

‎test/src/analyzers/lint_analyzer/rules/rules_list/avoid_dynamic/avoid_dynamic_rule_test.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void main() {
2525

2626
RuleTestHelper.verifyIssues(
2727
issues: issues,
28-
startLines: [2, 6, 10, 10, 10, 12, 23, 28, 31, 38],
28+
startLines: [2, 6, 10, 10, 10, 12, 23, 28, 31, 39],
2929
startColumns: [3, 4, 1, 22, 33, 7, 3, 3, 3, 32],
3030
locationTexts: [
3131
'dynamic s = 1',

‎test/src/analyzers/lint_analyzer/rules/rules_list/avoid_dynamic/examples/example.dart‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@ class SomeClass {
3535

3636
abstract class BaseClass<T> {}
3737

38-
class Generic extends BaseClass<dynamic> {} // LINT
38+
// LINT
39+
class Generic extends BaseClass<dynamic> {
40+
final Map<String, dynamic> myMap = {};
41+
42+
final myMap = <String, dynamic>{};
43+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /