Skip to content

Commit 0ef7ed2

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
[analyzer] Move 4 more HintCodes to be WarningCodes, UNUSED_*
Bug: #50796 Change-Id: Ib5b153bc6e64bc433df1f05c53d82f71b470bbec TEST=presubmit bots Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290703 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Nate Bosch <[email protected]>
1 parent b495821 commit 0ef7ed2

File tree

51 files changed

+385
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+385
-389
lines changed

pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class BulkFixProcessor {
383383
}
384384
} else if (errorCode == WarningCode.DUPLICATE_IMPORT ||
385385
errorCode == HintCode.UNNECESSARY_IMPORT ||
386-
errorCode == HintCode.UNUSED_IMPORT) {
386+
errorCode == WarningCode.UNUSED_IMPORT) {
387387
unusedImportErrors.add(error);
388388
}
389389
}

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,14 +1441,6 @@ HintCode.UNUSED_ELEMENT:
14411441
status: hasFix
14421442
HintCode.UNUSED_ELEMENT_PARAMETER:
14431443
status: hasFix
1444-
HintCode.UNUSED_FIELD:
1445-
status: hasFix
1446-
HintCode.UNUSED_IMPORT:
1447-
status: hasFix
1448-
HintCode.UNUSED_LOCAL_VARIABLE:
1449-
status: hasFix
1450-
HintCode.UNUSED_SHOWN_NAME:
1451-
status: hasFix
14521444
LanguageCode.IMPLICIT_DYNAMIC_FIELD:
14531445
status: needsFix
14541446
notes: |-
@@ -2869,8 +2861,14 @@ WarningCode.UNUSED_CATCH_CLAUSE:
28692861
status: hasFix
28702862
WarningCode.UNUSED_CATCH_STACK:
28712863
status: hasFix
2864+
WarningCode.UNUSED_FIELD:
2865+
status: hasFix
2866+
WarningCode.UNUSED_IMPORT:
2867+
status: hasFix
28722868
WarningCode.UNUSED_LABEL:
28732869
status: hasFix
2870+
WarningCode.UNUSED_LOCAL_VARIABLE:
2871+
status: hasFix
28742872
WarningCode.UNUSED_RESULT:
28752873
status: noFix
28762874
notes: |-
@@ -2879,3 +2877,5 @@ WarningCode.UNUSED_RESULT_WITH_MESSAGE:
28792877
status: noFix
28802878
notes: |-
28812879
There is no predictable common way in which a result _should_ be used.
2880+
WarningCode.UNUSED_SHOWN_NAME:
2881+
status: hasFix

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,18 +1386,6 @@ class FixProcessor extends BaseProcessor {
13861386
HintCode.UNUSED_ELEMENT_PARAMETER: [
13871387
RemoveUnusedParameter.new,
13881388
],
1389-
HintCode.UNUSED_FIELD: [
1390-
RemoveUnusedField.new,
1391-
],
1392-
HintCode.UNUSED_IMPORT: [
1393-
RemoveUnusedImport.new,
1394-
],
1395-
HintCode.UNUSED_LOCAL_VARIABLE: [
1396-
RemoveUnusedLocalVariable.new,
1397-
],
1398-
HintCode.UNUSED_SHOWN_NAME: [
1399-
RemoveNameFromCombinator.new,
1400-
],
14011389
ParserErrorCode.ABSTRACT_CLASS_MEMBER: [
14021390
RemoveAbstract.bulkFixable,
14031391
],
@@ -1640,9 +1628,21 @@ class FixProcessor extends BaseProcessor {
16401628
WarningCode.UNUSED_CATCH_STACK: [
16411629
RemoveUnusedCatchStack.new,
16421630
],
1631+
WarningCode.UNUSED_FIELD: [
1632+
RemoveUnusedField.new,
1633+
],
1634+
WarningCode.UNUSED_IMPORT: [
1635+
RemoveUnusedImport.new,
1636+
],
16431637
WarningCode.UNUSED_LABEL: [
16441638
RemoveUnusedLabel.new,
16451639
],
1640+
WarningCode.UNUSED_LOCAL_VARIABLE: [
1641+
RemoveUnusedLocalVariable.new,
1642+
],
1643+
WarningCode.UNUSED_SHOWN_NAME: [
1644+
RemoveNameFromCombinator.new,
1645+
],
16461646
};
16471647

16481648
final DartFixContext fixContext;

pkg/analysis_server/lib/src/services/correction/organize_imports.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ImportOrganizer {
5959
bool _isUnusedImport(UriBasedDirective directive) {
6060
for (var error in errors) {
6161
if ((error.errorCode == WarningCode.DUPLICATE_IMPORT ||
62-
error.errorCode == HintCode.UNUSED_IMPORT ||
62+
error.errorCode == WarningCode.UNUSED_IMPORT ||
6363
error.errorCode == HintCode.UNNECESSARY_IMPORT) &&
6464
directive.uri.offset == error.offset) {
6565
return true;

pkg/analysis_server/test/abstract_single_unit.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ class AbstractSingleUnitTest extends AbstractContextTest {
7575
error.errorCode != WarningCode.UNUSED_CATCH_CLAUSE &&
7676
error.errorCode != WarningCode.UNUSED_CATCH_STACK &&
7777
error.errorCode != HintCode.UNUSED_ELEMENT &&
78-
error.errorCode != HintCode.UNUSED_FIELD &&
79-
error.errorCode != HintCode.UNUSED_IMPORT &&
80-
error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE;
78+
error.errorCode != WarningCode.UNUSED_FIELD &&
79+
error.errorCode != WarningCode.UNUSED_IMPORT &&
80+
error.errorCode != WarningCode.UNUSED_LOCAL_VARIABLE;
8181
}), isEmpty);
8282
}
8383
testUnitElement = testUnit.declaredElement!;

pkg/analysis_server/test/src/services/correction/fix/data_driven/data_driven_test_support.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:analysis_server/src/services/correction/fix/data_driven/transfor
99
import 'package:analysis_server/src/services/correction/fix/data_driven/transform_set.dart';
1010
import 'package:analysis_server/src/services/correction/fix/data_driven/transform_set_manager.dart';
1111
import 'package:analyzer/error/error.dart';
12-
import 'package:analyzer/src/dart/error/hint_codes.dart';
12+
import 'package:analyzer/src/error/codes.dart';
1313
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
1414

1515
import '../fix_processor.dart';
@@ -46,7 +46,7 @@ abstract class DataDrivenFixProcessorTest extends FixProcessorTest {
4646
/// A method that can be used as an error filter to ignore any unused_import
4747
/// diagnostics.
4848
bool ignoreUnusedImport(AnalysisError error) =>
49-
error.errorCode != HintCode.UNUSED_IMPORT;
49+
error.errorCode != WarningCode.UNUSED_IMPORT;
5050

5151
/// Set the content of the library that defines the element referenced by the
5252
/// data on which this test is based.

pkg/analysis_server/test/src/services/correction/fix/remove_unused_import_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ import 'dart:math';
9494
import 'dart:async';
9595
void f() {}
9696
''');
97-
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
97+
await assertHasFixAllFix(WarningCode.UNUSED_IMPORT, '''
9898
void f() {}
9999
''');
100100
}
@@ -109,7 +109,7 @@ var tau = math.pi * 2;
109109
110110
void f() {}
111111
''');
112-
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
112+
await assertHasFixAllFix(WarningCode.UNUSED_IMPORT, '''
113113
import 'dart:math' as math;
114114
115115
var tau = math.pi * 2;
@@ -126,7 +126,7 @@ void f() {}
126126
import 'dart:math'; import 'dart:math'; import 'dart:math';
127127
void f() {}
128128
''');
129-
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
129+
await assertHasFixAllFix(WarningCode.UNUSED_IMPORT, '''
130130
131131
void f() {}
132132
''');
@@ -137,7 +137,7 @@ void f() {}
137137
import 'dart:math'; import 'dart:math'; import 'dart:math';
138138
void f() {}
139139
''');
140-
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
140+
await assertHasFixAllFix(WarningCode.UNUSED_IMPORT, '''
141141
import 'dart:math';
142142
void f() {}
143143
''');
@@ -150,7 +150,7 @@ import 'dart:math';
150150
import 'dart:math';
151151
void f() {}
152152
''');
153-
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
153+
await assertHasFixAllFix(WarningCode.UNUSED_IMPORT, '''
154154
void f() {}
155155
''');
156156
}

pkg/analyzer/lib/src/dart/error/hint_codes.g.dart

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import "package:analyzer/error/error.dart";
1515
import "package:analyzer/src/error/analyzer_error_code.dart";
16+
import "package:analyzer/src/error/codes.g.dart";
1617

1718
class HintCode extends AnalyzerErrorCode {
1819
/// When the target expression uses '?.' operator, it can be `null`, so all the
@@ -210,41 +211,9 @@ class HintCode extends AnalyzerErrorCode {
210211
uniqueName: 'UNUSED_ELEMENT_PARAMETER',
211212
);
212213

213-
/// Parameters:
214-
/// 0: the name of the unused field
215-
static const HintCode UNUSED_FIELD = HintCode(
216-
'UNUSED_FIELD',
217-
"The value of the field '{0}' isn't used.",
218-
correctionMessage: "Try removing the field, or using it.",
219-
hasPublishedDocs: true,
220-
);
221-
222-
/// Parameters:
223-
/// 0: the content of the unused import's URI
224-
static const HintCode UNUSED_IMPORT = HintCode(
225-
'UNUSED_IMPORT',
226-
"Unused import: '{0}'.",
227-
correctionMessage: "Try removing the import directive.",
228-
hasPublishedDocs: true,
229-
);
230-
231-
/// Parameters:
232-
/// 0: the name of the unused variable
233-
static const HintCode UNUSED_LOCAL_VARIABLE = HintCode(
234-
'UNUSED_LOCAL_VARIABLE',
235-
"The value of the local variable '{0}' isn't used.",
236-
correctionMessage: "Try removing the variable or using it.",
237-
hasPublishedDocs: true,
238-
);
239-
240-
/// Parameters:
241-
/// 0: the name that is shown but not used
242-
static const HintCode UNUSED_SHOWN_NAME = HintCode(
243-
'UNUSED_SHOWN_NAME',
244-
"The name {0} is shown, but isn't used.",
245-
correctionMessage: "Try removing the name from the list of shown members.",
246-
hasPublishedDocs: true,
247-
);
214+
/// This is the deprecated alias for [WarningCode.UNUSED_LOCAL_VARIABLE].
215+
static const WarningCode UNUSED_LOCAL_VARIABLE =
216+
WarningCode.UNUSED_LOCAL_VARIABLE;
248217

249218
/// Initialize a newly created error code to have the given [name].
250219
const HintCode(

pkg/analyzer/lib/src/error/codes.g.dart

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7151,11 +7151,23 @@ class WarningCode extends AnalyzerErrorCode {
71517151
static const HintCode UNUSED_ELEMENT_PARAMETER =
71527152
HintCode.UNUSED_ELEMENT_PARAMETER;
71537153

7154-
/// This is the new replacement for [HintCode.UNUSED_FIELD].
7155-
static const HintCode UNUSED_FIELD = HintCode.UNUSED_FIELD;
7154+
/// Parameters:
7155+
/// 0: the name of the unused field
7156+
static const WarningCode UNUSED_FIELD = WarningCode(
7157+
'UNUSED_FIELD',
7158+
"The value of the field '{0}' isn't used.",
7159+
correctionMessage: "Try removing the field, or using it.",
7160+
hasPublishedDocs: true,
7161+
);
71567162

7157-
/// This is the new replacement for [HintCode.UNUSED_IMPORT].
7158-
static const HintCode UNUSED_IMPORT = HintCode.UNUSED_IMPORT;
7163+
/// Parameters:
7164+
/// 0: the content of the unused import's URI
7165+
static const WarningCode UNUSED_IMPORT = WarningCode(
7166+
'UNUSED_IMPORT',
7167+
"Unused import: '{0}'.",
7168+
correctionMessage: "Try removing the import directive.",
7169+
hasPublishedDocs: true,
7170+
);
71597171

71607172
/// Parameters:
71617173
/// 0: the label that isn't used
@@ -7168,8 +7180,14 @@ class WarningCode extends AnalyzerErrorCode {
71687180
hasPublishedDocs: true,
71697181
);
71707182

7171-
/// This is the new replacement for [HintCode.UNUSED_LOCAL_VARIABLE].
7172-
static const HintCode UNUSED_LOCAL_VARIABLE = HintCode.UNUSED_LOCAL_VARIABLE;
7183+
/// Parameters:
7184+
/// 0: the name of the unused variable
7185+
static const WarningCode UNUSED_LOCAL_VARIABLE = WarningCode(
7186+
'UNUSED_LOCAL_VARIABLE',
7187+
"The value of the local variable '{0}' isn't used.",
7188+
correctionMessage: "Try removing the variable or using it.",
7189+
hasPublishedDocs: true,
7190+
);
71737191

71747192
/// Parameters:
71757193
/// 0: the name of the annotated method, property or function
@@ -7199,6 +7217,15 @@ class WarningCode extends AnalyzerErrorCode {
71997217
uniqueName: 'UNUSED_RESULT_WITH_MESSAGE',
72007218
);
72017219

7220+
/// Parameters:
7221+
/// 0: the name that is shown but not used
7222+
static const WarningCode UNUSED_SHOWN_NAME = WarningCode(
7223+
'UNUSED_SHOWN_NAME',
7224+
"The name {0} is shown, but isn't used.",
7225+
correctionMessage: "Try removing the name from the list of shown members.",
7226+
hasPublishedDocs: true,
7227+
);
7228+
72027229
/// Initialize a newly created error code to have the given [name].
72037230
const WarningCode(
72047231
String name,

pkg/analyzer/lib/src/error/error_code_values.g.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,6 @@ const List<ErrorCode> errorCodeValues = [
601601
HintCode.UNREACHABLE_SWITCH_CASE,
602602
HintCode.UNUSED_ELEMENT,
603603
HintCode.UNUSED_ELEMENT_PARAMETER,
604-
HintCode.UNUSED_FIELD,
605-
HintCode.UNUSED_IMPORT,
606-
HintCode.UNUSED_LOCAL_VARIABLE,
607-
HintCode.UNUSED_SHOWN_NAME,
608604
LanguageCode.IMPLICIT_DYNAMIC_FIELD,
609605
LanguageCode.IMPLICIT_DYNAMIC_FUNCTION,
610606
LanguageCode.IMPLICIT_DYNAMIC_INVOKE,
@@ -1014,7 +1010,11 @@ const List<ErrorCode> errorCodeValues = [
10141010
WarningCode.UNNECESSARY_WILDCARD_PATTERN,
10151011
WarningCode.UNUSED_CATCH_CLAUSE,
10161012
WarningCode.UNUSED_CATCH_STACK,
1013+
WarningCode.UNUSED_FIELD,
1014+
WarningCode.UNUSED_IMPORT,
10171015
WarningCode.UNUSED_LABEL,
1016+
WarningCode.UNUSED_LOCAL_VARIABLE,
10181017
WarningCode.UNUSED_RESULT,
10191018
WarningCode.UNUSED_RESULT_WITH_MESSAGE,
1019+
WarningCode.UNUSED_SHOWN_NAME,
10201020
];

pkg/analyzer/lib/src/error/imports_verifier.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ class ImportsVerifier {
405405
// only way for it to be `null` is if the import contains a string
406406
// interpolation, in which case the import wouldn't have resolved and
407407
// would not have been included in [_unusedImports].
408-
errorReporter
409-
.reportErrorForNode(HintCode.UNUSED_IMPORT, uri, [uri.stringValue!]);
408+
errorReporter.reportErrorForNode(
409+
WarningCode.UNUSED_IMPORT, uri, [uri.stringValue!]);
410410
}
411411
}
412412

@@ -432,7 +432,7 @@ class ImportsVerifier {
432432
// Only generate a hint if we won't also generate a
433433
// "duplicate_shown_name" hint for the same identifier.
434434
reporter.reportErrorForNode(
435-
HintCode.UNUSED_SHOWN_NAME, identifier, [identifier.name]);
435+
WarningCode.UNUSED_SHOWN_NAME, identifier, [identifier.name]);
436436
}
437437
}
438438
});

pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,9 @@ class GatherUsedLocalElementsVisitor extends RecursiveAstVisitor<void> {
449449
}
450450

451451
/// Instances of the class [UnusedLocalElementsVerifier] traverse an AST
452-
/// looking for cases of [HintCode.UNUSED_ELEMENT], [HintCode.UNUSED_FIELD],
453-
/// [HintCode.UNUSED_LOCAL_VARIABLE], etc.
452+
/// looking for cases of [WarningCode.UNUSED_ELEMENT],
453+
/// [WarningCode.UNUSED_FIELD],
454+
/// [WarningCode.UNUSED_LOCAL_VARIABLE], etc.
454455
class UnusedLocalElementsVerifier extends RecursiveAstVisitor<void> {
455456
/// The error listener to which errors will be reported.
456457
final AnalysisErrorListener _errorListener;
@@ -902,7 +903,7 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor<void> {
902903
void _visitFieldElement(FieldElement element) {
903904
if (!_isReadMember(element)) {
904905
_reportErrorForElement(
905-
HintCode.UNUSED_FIELD, element, [element.displayName]);
906+
WarningCode.UNUSED_FIELD, element, [element.displayName]);
906907
}
907908
}
908909

@@ -921,7 +922,7 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor<void> {
921922
} else if (_usedElements.isCatchStackTrace(element)) {
922923
errorCode = WarningCode.UNUSED_CATCH_STACK;
923924
} else {
924-
errorCode = HintCode.UNUSED_LOCAL_VARIABLE;
925+
errorCode = WarningCode.UNUSED_LOCAL_VARIABLE;
925926
}
926927
_reportErrorForElement(errorCode, element, [element.displayName]);
927928
}

0 commit comments

Comments
 (0)