Merge pull request #966 from a14n/avoid_field_initializers_in_const_classes
add avoid_field_initializers_in_const_classes
diff --git a/lib/src/rules/avoid_double_and_int_checks.dart b/lib/src/rules/avoid_double_and_int_checks.dart
index 5999487..930f79a 100644
--- a/lib/src/rules/avoid_double_and_int_checks.dart
+++ b/lib/src/rules/avoid_double_and_int_checks.dart
@@ -29,6 +29,17 @@
}
```
+**GOOD:**
+```
+f(dynamic x) {
+ if (x is num) {
+ ...
+ } else {
+ ...
+ }
+}
+```
+
''';
class AvoidDoubleAndIntChecks extends LintRule {
diff --git a/lib/src/rules/unnecessary_statements.dart b/lib/src/rules/unnecessary_statements.dart
index ff31eb9..e1741dd 100644
--- a/lib/src/rules/unnecessary_statements.dart
+++ b/lib/src/rules/unnecessary_statements.dart
@@ -4,6 +4,7 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
+import 'package:analyzer/dart/element/type.dart';
import 'package:linter/src/analyzer.dart';
const _desc = r'Avoid using unnecessary statements.';
@@ -77,6 +78,15 @@
u.accept(reportNoClearEffect);
});
}
+
+ @override
+ visitCascadeExpression(CascadeExpression node) {
+ for (var section in node.cascadeSections) {
+ if (section is PropertyAccess && section.bestType is FunctionType) {
+ reportNoClearEffect.rule.reportLint(section);
+ }
+ }
+ }
}
class _ReportNoClearEffectVisitor extends UnifyingAstVisitor {
diff --git a/pubspec.yaml b/pubspec.yaml
index d995896..328d35b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -10,7 +10,6 @@
args: '>=1.4.0 <2.0.0'
glob: ^1.0.3
meta: ^1.0.2
- plugin: ^0.2.0
source_span: ^1.0.2
yaml: ^2.1.2
dev_dependencies:
diff --git a/test/rule_test.dart b/test/rule_test.dart
index 8145290..0c30a4d 100644
--- a/test/rule_test.dart
+++ b/test/rule_test.dart
@@ -347,6 +347,7 @@
}
});
});
+ actual.sort();
try {
expect(actual, unorderedMatches(expected));
// ignore: avoid_catches_without_on_clauses
@@ -418,7 +419,7 @@
p.Context get pathContext => physicalResourceProvider.pathContext;
}
-class Annotation {
+class Annotation implements Comparable<Annotation> {
final int column;
final int length;
final String message;
@@ -438,6 +439,16 @@
: this(message, ErrorType.LINT, null, column: column, length: length);
@override
+ int compareTo(Annotation other) {
+ if (lineNumber != other.lineNumber) {
+ return lineNumber - other.lineNumber;
+ } else if (column != other.column) {
+ return column - other.column;
+ }
+ return message.compareTo(other.message);
+ }
+
+ @override
String toString() =>
'[$type]: "$message" (line: $lineNumber) - [$column:$length]';
diff --git a/test/rules/unnecessary_statements.dart b/test/rules/unnecessary_statements.dart
index 6113b56..8cb464a 100644
--- a/test/rules/unnecessary_statements.dart
+++ b/test/rules/unnecessary_statements.dart
@@ -9,6 +9,11 @@
1 + 1; // LINT
foo; // LINT
new MyClass().foo; // LINT
+ new MyClass()..foo; // LINT
+ new MyClass()
+ ..getter // OK
+ ..foo() // OK
+ ..foo; // LINT
[]; // LINT
<dynamic, dynamic>{}; // LINT
"blah"; // LINT
@@ -30,18 +35,22 @@
}
asConditionAndReturnOk() {
- if (true == someBool) {
- // OK
+ if (true == someBool) // OK
+ {
return 1 + 1; // OK
} else if (false == someBool) {
return foo; // OK
}
- while (new MyClass() != null) {
- // OK
+ while (new MyClass() != null) // OK
+ {
return new MyClass().foo; // OK
}
- for (; someBool ?? someBool;) {
- // OK
+ while (null == someBool) // OK
+ {
+ return new MyClass()..foo; // LINT
+ }
+ for (; someBool ?? someBool;) // OK
+ {
return <dynamic, dynamic>{}; // OK
}
do {} while ("blah".isEmpty); // OK
@@ -52,9 +61,11 @@
() => new MyClass().foo; // LINT
myfun() => new MyClass().foo; // OK
+ myfun2() => new MyClass()..foo; // LINT
}
myfun() => new MyClass().foo; // OK
+myfun2() => new MyClass()..foo; // LINT
expressionBranching() {
null ?? 1 + 1; // LINT
@@ -145,4 +156,6 @@
class MyClass {
bool foo() => true;
+
+ get getter => true;
}