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

fix: handle dynamics in map literals for avoid-dynamic #1194

Merged
merged 4 commits into from
Mar 20, 2023
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: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## Unreleased

* feat: add static code diagnostic [prefer-define-hero-tag](https://github.com/dart-code-checker/dart-code-metrics/issues/1027).
* fix: handle dynamics in map literals for [`avoid-dynamic`](https://dcm.dev/docs/individuals/rules/common/avoid-dynamic).
* fix: change anti-patterns default severity to `warning`.
* feat: add static code diagnostic [`prefer-define-hero-tag`](https://dcm.dev/docs/individuals/rules/common/prefer-define-hero-tag).
* chore: restrict `analyzer` version to `>=5.1.0 <5.8.0`.
* feat: add avoid-substring rule
* feat: add static code diagnostic [`avoid-substring`](https://dcm.dev/docs/individuals/rules/common/avoid-substring).

## 5.6.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LongMethod extends Pattern {
),
super(
id: patternId,
severity: readSeverity(patternSettings, Severity.none),
severity: readSeverity(patternSettings, Severity.warning),
excludes: readExcludes(patternSettings),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LongParameterList extends Pattern {
),
super(
id: patternId,
severity: readSeverity(patternSettings, Severity.none),
severity: readSeverity(patternSettings, Severity.warning),
excludes: readExcludes(patternSettings),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ class _Visitor extends RecursiveAstVisitor<void> {
final parent = node.parent;
if (parent is NamedType && (parent.type?.isDynamic ?? false)) {
final grandParent = node.parent?.parent;
if (grandParent != null) {
final grandGrandParent = grandParent.parent;
if (!(grandGrandParent is NamedType &&
(grandGrandParent.type?.isDartCoreMap ?? false))) {
_nodes.add(grandParent);
}
if (grandParent != null && !_isWithinMap(grandParent)) {
_nodes.add(grandParent);
}
}
}

bool _isWithinMap(AstNode grandParent) {
final grandGrandParent = grandParent.parent;

return grandGrandParent is NamedType &&
(grandGrandParent.type?.isDartCoreMap ?? false) ||
grandGrandParent is SetOrMapLiteral && grandGrandParent.isMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class _Visitor extends RecursiveAstVisitor<void> {
!_isEmptyFutureOrType(type);

bool _isEmptyType(DartType type) =>
// ignore: deprecated_member_use
type.isBottom || type.isDartCoreNull || type.isVoid;

bool _isEmptyFutureType(DartType type) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class _ReturnVisitor extends RecursiveAstVisitor<void> {

final type = node.expression?.staticType;

// ignore: deprecated_member_use
if (type == null || type.isVoid) {
_hasValidReturn = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class _BlockVisitor extends RecursiveAstVisitor<void> {
void visitMethodInvocation(MethodInvocation node) {
if (node.parent is CascadeExpression ||
node.parent is VariableDeclaration ||
// ignore: deprecated_member_use
(node.staticType?.isVoid ?? false)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ platforms:
macos:

dependencies:
analyzer: ">=5.1.0 <5.8.0"
analyzer: ">=5.1.0 <5.9.0"
analyzer_plugin: ">=0.11.0 <0.12.0"
ansicolor: ^2.0.1
args: ^2.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void main() {
AntiPatternTestHelper.verifyInitialization(
issues: issues,
antiPatternId: 'long-method',
severity: Severity.none,
severity: Severity.warning,
);

AntiPatternTestHelper.verifyIssues(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void main() {
AntiPatternTestHelper.verifyInitialization(
issues: issues,
antiPatternId: 'long-parameter-list',
severity: Severity.none,
severity: Severity.warning,
);

AntiPatternTestHelper.verifyIssues(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {

RuleTestHelper.verifyIssues(
issues: issues,
startLines: [2, 6, 10, 10, 10, 12, 23, 28, 31, 38],
startLines: [2, 6, 10, 10, 10, 12, 23, 28, 31, 39],
startColumns: [3, 4, 1, 22, 33, 7, 3, 3, 3, 32],
locationTexts: [
'dynamic s = 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ class SomeClass {

abstract class BaseClass<T> {}

class Generic extends BaseClass<dynamic> {} // LINT
// LINT
class Generic extends BaseClass<dynamic> {
final Map<String, dynamic> myMap = {};

final myMap = <String, dynamic>{};
}