Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Unified Diff: pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Issue 3009063002: Add fixes for more lints (Closed)
Patch Set: Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/correction/fix_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index 76163cb0d3cc259ced60ce71de64d195e22b2f3a..679afb1ccbae4363522ecd7441c20d9013037bb7 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -412,7 +412,7 @@ class FixProcessor {
await _addFix_addOverrideAnnotation();
}
if (name == LintNames.avoid_annotating_with_dynamic) {
- await _addFix_removeTypeName();
+ await _addFix_removeTypeAnnotation();
}
if (name == LintNames.avoid_empty_else) {
await _addFix_removeEmptyElse();
@@ -421,7 +421,7 @@ class FixProcessor {
await _addFix_removeInitializer();
}
if (name == LintNames.avoid_return_types_on_setters) {
- await _addFix_removeTypeName();
+ await _addFix_removeTypeAnnotation();
}
if (name == LintNames.avoid_types_on_closure_parameters) {
await _addFix_replaceWithIdentifier();
@@ -438,6 +438,12 @@ class FixProcessor {
if (name == LintNames.prefer_conditional_assignment) {
await _addFix_replaceWithConditionalAssignment();
}
+ if (name == LintNames.prefer_is_not_empty) {
+ await _addFix_isNotEmpty();
+ }
+ if (name == LintNames.type_init_formals) {
+ await _addFix_removeTypeAnnotation();
+ }
if (name == LintNames.unnecessary_brace_in_string_interp) {
await _addFix_removeInterpolationBraces();
}
@@ -1788,6 +1794,32 @@ class FixProcessor {
}
}
+ Future<Null> _addFix_isNotEmpty() async {
+ if (node is! PrefixExpression) {
+ return;
+ }
+ PrefixExpression prefixExpression = node;
+ Token negation = prefixExpression.operator;
+ if (negation.type != TokenType.BANG) {
+ return;
+ }
+ SimpleIdentifier identifier;
+ Expression expression = prefixExpression.operand;
+ if (expression is PrefixedIdentifier) {
+ identifier = expression.identifier;
+ } else if (expression is PropertyAccess) {
+ identifier = expression.propertyName;
+ } else {
+ return;
+ }
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
+ await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
+ builder.addDeletion(range.token(negation));
+ builder.addSimpleReplacement(range.node(identifier), 'isNotEmpty');
+ });
+ _addFixFromBuilder(changeBuilder, DartFixKind.USE_IS_NOT_EMPTY);
+ }
+
Future<Null> _addFix_isNotNull() async {
if (coveredNode is IsExpression) {
IsExpression isExpression = coveredNode as IsExpression;
@@ -2060,8 +2092,9 @@ class FixProcessor {
}
}
- Future<Null> _addFix_removeTypeName() async {
- final TypeName type = node.getAncestor((node) => node is TypeName);
+ Future<Null> _addFix_removeTypeAnnotation() async {
+ final TypeAnnotation type =
+ node.getAncestor((node) => node is TypeAnnotation);
if (type != null) {
DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
@@ -2198,7 +2231,7 @@ class FixProcessor {
});
_addFixFromBuilder(changeBuilder, DartFixKind.REPLACE_WITH_IDENTIFIER);
} else {
- await _addFix_removeTypeName();
+ await _addFix_removeTypeAnnotation();
}
}
@@ -3178,6 +3211,8 @@ class LintNames {
static const String prefer_collection_literals = 'prefer_collection_literals';
static const String prefer_conditional_assignment =
'prefer_conditional_assignment';
+ static const String prefer_is_not_empty = 'prefer_is_not_empty';
+ static const String type_init_formals = 'type_init_formals';
static const String unnecessary_brace_in_string_interp =
'unnecessary_brace_in_string_interp';
static const String unnecessary_lambdas = 'unnecessary_lambdas';
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix.dart ('k') | pkg/analysis_server/test/services/correction/fix_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698