mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 11:42:11 +00:00
[analyzer] Move 4 more HintCodes to be WarningCodes, UNUSED_*
Bug: https://github.com/dart-lang/sdk/issues/50796 Change-Id: Ib5b153bc6e64bc433df1f05c53d82f71b470bbec TEST=presubmit bots Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290703 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Alexander Aprelev <aam@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Nate Bosch <nbosch@google.com>
This commit is contained in:
parent
b49582196c
commit
0ef7ed2ebd
|
@ -383,7 +383,7 @@ class BulkFixProcessor {
|
|||
}
|
||||
} else if (errorCode == WarningCode.DUPLICATE_IMPORT ||
|
||||
errorCode == HintCode.UNNECESSARY_IMPORT ||
|
||||
errorCode == HintCode.UNUSED_IMPORT) {
|
||||
errorCode == WarningCode.UNUSED_IMPORT) {
|
||||
unusedImportErrors.add(error);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1441,14 +1441,6 @@ HintCode.UNUSED_ELEMENT:
|
|||
status: hasFix
|
||||
HintCode.UNUSED_ELEMENT_PARAMETER:
|
||||
status: hasFix
|
||||
HintCode.UNUSED_FIELD:
|
||||
status: hasFix
|
||||
HintCode.UNUSED_IMPORT:
|
||||
status: hasFix
|
||||
HintCode.UNUSED_LOCAL_VARIABLE:
|
||||
status: hasFix
|
||||
HintCode.UNUSED_SHOWN_NAME:
|
||||
status: hasFix
|
||||
LanguageCode.IMPLICIT_DYNAMIC_FIELD:
|
||||
status: needsFix
|
||||
notes: |-
|
||||
|
@ -2869,8 +2861,14 @@ WarningCode.UNUSED_CATCH_CLAUSE:
|
|||
status: hasFix
|
||||
WarningCode.UNUSED_CATCH_STACK:
|
||||
status: hasFix
|
||||
WarningCode.UNUSED_FIELD:
|
||||
status: hasFix
|
||||
WarningCode.UNUSED_IMPORT:
|
||||
status: hasFix
|
||||
WarningCode.UNUSED_LABEL:
|
||||
status: hasFix
|
||||
WarningCode.UNUSED_LOCAL_VARIABLE:
|
||||
status: hasFix
|
||||
WarningCode.UNUSED_RESULT:
|
||||
status: noFix
|
||||
notes: |-
|
||||
|
@ -2879,3 +2877,5 @@ WarningCode.UNUSED_RESULT_WITH_MESSAGE:
|
|||
status: noFix
|
||||
notes: |-
|
||||
There is no predictable common way in which a result _should_ be used.
|
||||
WarningCode.UNUSED_SHOWN_NAME:
|
||||
status: hasFix
|
||||
|
|
|
@ -1386,18 +1386,6 @@ class FixProcessor extends BaseProcessor {
|
|||
HintCode.UNUSED_ELEMENT_PARAMETER: [
|
||||
RemoveUnusedParameter.new,
|
||||
],
|
||||
HintCode.UNUSED_FIELD: [
|
||||
RemoveUnusedField.new,
|
||||
],
|
||||
HintCode.UNUSED_IMPORT: [
|
||||
RemoveUnusedImport.new,
|
||||
],
|
||||
HintCode.UNUSED_LOCAL_VARIABLE: [
|
||||
RemoveUnusedLocalVariable.new,
|
||||
],
|
||||
HintCode.UNUSED_SHOWN_NAME: [
|
||||
RemoveNameFromCombinator.new,
|
||||
],
|
||||
ParserErrorCode.ABSTRACT_CLASS_MEMBER: [
|
||||
RemoveAbstract.bulkFixable,
|
||||
],
|
||||
|
@ -1640,9 +1628,21 @@ class FixProcessor extends BaseProcessor {
|
|||
WarningCode.UNUSED_CATCH_STACK: [
|
||||
RemoveUnusedCatchStack.new,
|
||||
],
|
||||
WarningCode.UNUSED_FIELD: [
|
||||
RemoveUnusedField.new,
|
||||
],
|
||||
WarningCode.UNUSED_IMPORT: [
|
||||
RemoveUnusedImport.new,
|
||||
],
|
||||
WarningCode.UNUSED_LABEL: [
|
||||
RemoveUnusedLabel.new,
|
||||
],
|
||||
WarningCode.UNUSED_LOCAL_VARIABLE: [
|
||||
RemoveUnusedLocalVariable.new,
|
||||
],
|
||||
WarningCode.UNUSED_SHOWN_NAME: [
|
||||
RemoveNameFromCombinator.new,
|
||||
],
|
||||
};
|
||||
|
||||
final DartFixContext fixContext;
|
||||
|
|
|
@ -59,7 +59,7 @@ class ImportOrganizer {
|
|||
bool _isUnusedImport(UriBasedDirective directive) {
|
||||
for (var error in errors) {
|
||||
if ((error.errorCode == WarningCode.DUPLICATE_IMPORT ||
|
||||
error.errorCode == HintCode.UNUSED_IMPORT ||
|
||||
error.errorCode == WarningCode.UNUSED_IMPORT ||
|
||||
error.errorCode == HintCode.UNNECESSARY_IMPORT) &&
|
||||
directive.uri.offset == error.offset) {
|
||||
return true;
|
||||
|
|
|
@ -75,9 +75,9 @@ class AbstractSingleUnitTest extends AbstractContextTest {
|
|||
error.errorCode != WarningCode.UNUSED_CATCH_CLAUSE &&
|
||||
error.errorCode != WarningCode.UNUSED_CATCH_STACK &&
|
||||
error.errorCode != HintCode.UNUSED_ELEMENT &&
|
||||
error.errorCode != HintCode.UNUSED_FIELD &&
|
||||
error.errorCode != HintCode.UNUSED_IMPORT &&
|
||||
error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE;
|
||||
error.errorCode != WarningCode.UNUSED_FIELD &&
|
||||
error.errorCode != WarningCode.UNUSED_IMPORT &&
|
||||
error.errorCode != WarningCode.UNUSED_LOCAL_VARIABLE;
|
||||
}), isEmpty);
|
||||
}
|
||||
testUnitElement = testUnit.declaredElement!;
|
||||
|
|
|
@ -9,7 +9,7 @@ import 'package:analysis_server/src/services/correction/fix/data_driven/transfor
|
|||
import 'package:analysis_server/src/services/correction/fix/data_driven/transform_set.dart';
|
||||
import 'package:analysis_server/src/services/correction/fix/data_driven/transform_set_manager.dart';
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/src/dart/error/hint_codes.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
|
||||
import '../fix_processor.dart';
|
||||
|
@ -46,7 +46,7 @@ abstract class DataDrivenFixProcessorTest extends FixProcessorTest {
|
|||
/// A method that can be used as an error filter to ignore any unused_import
|
||||
/// diagnostics.
|
||||
bool ignoreUnusedImport(AnalysisError error) =>
|
||||
error.errorCode != HintCode.UNUSED_IMPORT;
|
||||
error.errorCode != WarningCode.UNUSED_IMPORT;
|
||||
|
||||
/// Set the content of the library that defines the element referenced by the
|
||||
/// data on which this test is based.
|
||||
|
|
|
@ -94,7 +94,7 @@ import 'dart:math';
|
|||
import 'dart:async';
|
||||
void f() {}
|
||||
''');
|
||||
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
|
||||
await assertHasFixAllFix(WarningCode.UNUSED_IMPORT, '''
|
||||
void f() {}
|
||||
''');
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ var tau = math.pi * 2;
|
|||
|
||||
void f() {}
|
||||
''');
|
||||
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
|
||||
await assertHasFixAllFix(WarningCode.UNUSED_IMPORT, '''
|
||||
import 'dart:math' as math;
|
||||
|
||||
var tau = math.pi * 2;
|
||||
|
@ -126,7 +126,7 @@ void f() {}
|
|||
import 'dart:math'; import 'dart:math'; import 'dart:math';
|
||||
void f() {}
|
||||
''');
|
||||
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
|
||||
await assertHasFixAllFix(WarningCode.UNUSED_IMPORT, '''
|
||||
|
||||
void f() {}
|
||||
''');
|
||||
|
@ -137,7 +137,7 @@ void f() {}
|
|||
import 'dart:math'; import 'dart:math'; import 'dart:math';
|
||||
void f() {}
|
||||
''');
|
||||
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
|
||||
await assertHasFixAllFix(WarningCode.UNUSED_IMPORT, '''
|
||||
import 'dart:math';
|
||||
void f() {}
|
||||
''');
|
||||
|
@ -150,7 +150,7 @@ import 'dart:math';
|
|||
import 'dart:math';
|
||||
void f() {}
|
||||
''');
|
||||
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
|
||||
await assertHasFixAllFix(WarningCode.UNUSED_IMPORT, '''
|
||||
void f() {}
|
||||
''');
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
import "package:analyzer/error/error.dart";
|
||||
import "package:analyzer/src/error/analyzer_error_code.dart";
|
||||
import "package:analyzer/src/error/codes.g.dart";
|
||||
|
||||
class HintCode extends AnalyzerErrorCode {
|
||||
/// When the target expression uses '?.' operator, it can be `null`, so all the
|
||||
|
@ -210,41 +211,9 @@ class HintCode extends AnalyzerErrorCode {
|
|||
uniqueName: 'UNUSED_ELEMENT_PARAMETER',
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// 0: the name of the unused field
|
||||
static const HintCode UNUSED_FIELD = HintCode(
|
||||
'UNUSED_FIELD',
|
||||
"The value of the field '{0}' isn't used.",
|
||||
correctionMessage: "Try removing the field, or using it.",
|
||||
hasPublishedDocs: true,
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// 0: the content of the unused import's URI
|
||||
static const HintCode UNUSED_IMPORT = HintCode(
|
||||
'UNUSED_IMPORT',
|
||||
"Unused import: '{0}'.",
|
||||
correctionMessage: "Try removing the import directive.",
|
||||
hasPublishedDocs: true,
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// 0: the name of the unused variable
|
||||
static const HintCode UNUSED_LOCAL_VARIABLE = HintCode(
|
||||
'UNUSED_LOCAL_VARIABLE',
|
||||
"The value of the local variable '{0}' isn't used.",
|
||||
correctionMessage: "Try removing the variable or using it.",
|
||||
hasPublishedDocs: true,
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// 0: the name that is shown but not used
|
||||
static const HintCode UNUSED_SHOWN_NAME = HintCode(
|
||||
'UNUSED_SHOWN_NAME',
|
||||
"The name {0} is shown, but isn't used.",
|
||||
correctionMessage: "Try removing the name from the list of shown members.",
|
||||
hasPublishedDocs: true,
|
||||
);
|
||||
/// This is the deprecated alias for [WarningCode.UNUSED_LOCAL_VARIABLE].
|
||||
static const WarningCode UNUSED_LOCAL_VARIABLE =
|
||||
WarningCode.UNUSED_LOCAL_VARIABLE;
|
||||
|
||||
/// Initialize a newly created error code to have the given [name].
|
||||
const HintCode(
|
||||
|
|
|
@ -7151,11 +7151,23 @@ class WarningCode extends AnalyzerErrorCode {
|
|||
static const HintCode UNUSED_ELEMENT_PARAMETER =
|
||||
HintCode.UNUSED_ELEMENT_PARAMETER;
|
||||
|
||||
/// This is the new replacement for [HintCode.UNUSED_FIELD].
|
||||
static const HintCode UNUSED_FIELD = HintCode.UNUSED_FIELD;
|
||||
/// Parameters:
|
||||
/// 0: the name of the unused field
|
||||
static const WarningCode UNUSED_FIELD = WarningCode(
|
||||
'UNUSED_FIELD',
|
||||
"The value of the field '{0}' isn't used.",
|
||||
correctionMessage: "Try removing the field, or using it.",
|
||||
hasPublishedDocs: true,
|
||||
);
|
||||
|
||||
/// This is the new replacement for [HintCode.UNUSED_IMPORT].
|
||||
static const HintCode UNUSED_IMPORT = HintCode.UNUSED_IMPORT;
|
||||
/// Parameters:
|
||||
/// 0: the content of the unused import's URI
|
||||
static const WarningCode UNUSED_IMPORT = WarningCode(
|
||||
'UNUSED_IMPORT',
|
||||
"Unused import: '{0}'.",
|
||||
correctionMessage: "Try removing the import directive.",
|
||||
hasPublishedDocs: true,
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// 0: the label that isn't used
|
||||
|
@ -7168,8 +7180,14 @@ class WarningCode extends AnalyzerErrorCode {
|
|||
hasPublishedDocs: true,
|
||||
);
|
||||
|
||||
/// This is the new replacement for [HintCode.UNUSED_LOCAL_VARIABLE].
|
||||
static const HintCode UNUSED_LOCAL_VARIABLE = HintCode.UNUSED_LOCAL_VARIABLE;
|
||||
/// Parameters:
|
||||
/// 0: the name of the unused variable
|
||||
static const WarningCode UNUSED_LOCAL_VARIABLE = WarningCode(
|
||||
'UNUSED_LOCAL_VARIABLE',
|
||||
"The value of the local variable '{0}' isn't used.",
|
||||
correctionMessage: "Try removing the variable or using it.",
|
||||
hasPublishedDocs: true,
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// 0: the name of the annotated method, property or function
|
||||
|
@ -7199,6 +7217,15 @@ class WarningCode extends AnalyzerErrorCode {
|
|||
uniqueName: 'UNUSED_RESULT_WITH_MESSAGE',
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// 0: the name that is shown but not used
|
||||
static const WarningCode UNUSED_SHOWN_NAME = WarningCode(
|
||||
'UNUSED_SHOWN_NAME',
|
||||
"The name {0} is shown, but isn't used.",
|
||||
correctionMessage: "Try removing the name from the list of shown members.",
|
||||
hasPublishedDocs: true,
|
||||
);
|
||||
|
||||
/// Initialize a newly created error code to have the given [name].
|
||||
const WarningCode(
|
||||
String name,
|
||||
|
|
|
@ -601,10 +601,6 @@ const List<ErrorCode> errorCodeValues = [
|
|||
HintCode.UNREACHABLE_SWITCH_CASE,
|
||||
HintCode.UNUSED_ELEMENT,
|
||||
HintCode.UNUSED_ELEMENT_PARAMETER,
|
||||
HintCode.UNUSED_FIELD,
|
||||
HintCode.UNUSED_IMPORT,
|
||||
HintCode.UNUSED_LOCAL_VARIABLE,
|
||||
HintCode.UNUSED_SHOWN_NAME,
|
||||
LanguageCode.IMPLICIT_DYNAMIC_FIELD,
|
||||
LanguageCode.IMPLICIT_DYNAMIC_FUNCTION,
|
||||
LanguageCode.IMPLICIT_DYNAMIC_INVOKE,
|
||||
|
@ -1014,7 +1010,11 @@ const List<ErrorCode> errorCodeValues = [
|
|||
WarningCode.UNNECESSARY_WILDCARD_PATTERN,
|
||||
WarningCode.UNUSED_CATCH_CLAUSE,
|
||||
WarningCode.UNUSED_CATCH_STACK,
|
||||
WarningCode.UNUSED_FIELD,
|
||||
WarningCode.UNUSED_IMPORT,
|
||||
WarningCode.UNUSED_LABEL,
|
||||
WarningCode.UNUSED_LOCAL_VARIABLE,
|
||||
WarningCode.UNUSED_RESULT,
|
||||
WarningCode.UNUSED_RESULT_WITH_MESSAGE,
|
||||
WarningCode.UNUSED_SHOWN_NAME,
|
||||
];
|
||||
|
|
|
@ -405,8 +405,8 @@ class ImportsVerifier {
|
|||
// only way for it to be `null` is if the import contains a string
|
||||
// interpolation, in which case the import wouldn't have resolved and
|
||||
// would not have been included in [_unusedImports].
|
||||
errorReporter
|
||||
.reportErrorForNode(HintCode.UNUSED_IMPORT, uri, [uri.stringValue!]);
|
||||
errorReporter.reportErrorForNode(
|
||||
WarningCode.UNUSED_IMPORT, uri, [uri.stringValue!]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -432,7 +432,7 @@ class ImportsVerifier {
|
|||
// Only generate a hint if we won't also generate a
|
||||
// "duplicate_shown_name" hint for the same identifier.
|
||||
reporter.reportErrorForNode(
|
||||
HintCode.UNUSED_SHOWN_NAME, identifier, [identifier.name]);
|
||||
WarningCode.UNUSED_SHOWN_NAME, identifier, [identifier.name]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -449,8 +449,9 @@ class GatherUsedLocalElementsVisitor extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
|
||||
/// Instances of the class [UnusedLocalElementsVerifier] traverse an AST
|
||||
/// looking for cases of [HintCode.UNUSED_ELEMENT], [HintCode.UNUSED_FIELD],
|
||||
/// [HintCode.UNUSED_LOCAL_VARIABLE], etc.
|
||||
/// looking for cases of [WarningCode.UNUSED_ELEMENT],
|
||||
/// [WarningCode.UNUSED_FIELD],
|
||||
/// [WarningCode.UNUSED_LOCAL_VARIABLE], etc.
|
||||
class UnusedLocalElementsVerifier extends RecursiveAstVisitor<void> {
|
||||
/// The error listener to which errors will be reported.
|
||||
final AnalysisErrorListener _errorListener;
|
||||
|
@ -902,7 +903,7 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor<void> {
|
|||
void _visitFieldElement(FieldElement element) {
|
||||
if (!_isReadMember(element)) {
|
||||
_reportErrorForElement(
|
||||
HintCode.UNUSED_FIELD, element, [element.displayName]);
|
||||
WarningCode.UNUSED_FIELD, element, [element.displayName]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -921,7 +922,7 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor<void> {
|
|||
} else if (_usedElements.isCatchStackTrace(element)) {
|
||||
errorCode = WarningCode.UNUSED_CATCH_STACK;
|
||||
} else {
|
||||
errorCode = HintCode.UNUSED_LOCAL_VARIABLE;
|
||||
errorCode = WarningCode.UNUSED_LOCAL_VARIABLE;
|
||||
}
|
||||
_reportErrorForElement(errorCode, element, [element.displayName]);
|
||||
}
|
||||
|
|
|
@ -19995,138 +19995,9 @@ HintCode:
|
|||
comment: |-
|
||||
Parameters:
|
||||
0: the name of the parameter that is declared but not used
|
||||
UNUSED_FIELD:
|
||||
problemMessage: "The value of the field '{0}' isn't used."
|
||||
correctionMessage: Try removing the field, or using it.
|
||||
hasPublishedDocs: true
|
||||
comment: |-
|
||||
Parameters:
|
||||
0: the name of the unused field
|
||||
documentation: |-
|
||||
#### Description
|
||||
|
||||
The analyzer produces this diagnostic when a private field is declared but
|
||||
never read, even if it's written in one or more places.
|
||||
|
||||
#### Example
|
||||
|
||||
The following code produces this diagnostic because the field
|
||||
`_originalValue` isn't read anywhere in the library:
|
||||
|
||||
```dart
|
||||
class C {
|
||||
final String [!_originalValue!];
|
||||
final String _currentValue;
|
||||
|
||||
C(this._originalValue) : _currentValue = _originalValue;
|
||||
|
||||
String get value => _currentValue;
|
||||
}
|
||||
```
|
||||
|
||||
It might appear that the field `_originalValue` is being read in the
|
||||
initializer (`_currentValue = _originalValue`), but that is actually a
|
||||
reference to the parameter of the same name, not a reference to the field.
|
||||
|
||||
#### Common fixes
|
||||
|
||||
If the field isn't needed, then remove it.
|
||||
|
||||
If the field was intended to be used, then add the missing code.
|
||||
UNUSED_IMPORT:
|
||||
problemMessage: "Unused import: '{0}'."
|
||||
correctionMessage: Try removing the import directive.
|
||||
hasPublishedDocs: true
|
||||
comment: |-
|
||||
Parameters:
|
||||
0: the content of the unused import's URI
|
||||
documentation: |-
|
||||
#### Description
|
||||
|
||||
The analyzer produces this diagnostic when an import isn't needed because
|
||||
none of the names that are imported are referenced within the importing
|
||||
library.
|
||||
|
||||
#### Example
|
||||
|
||||
The following code produces this diagnostic because nothing defined in
|
||||
`dart:async` is referenced in the library:
|
||||
|
||||
```dart
|
||||
import [!'dart:async'!];
|
||||
|
||||
void main() {}
|
||||
```
|
||||
|
||||
#### Common fixes
|
||||
|
||||
If the import isn't needed, then remove it.
|
||||
|
||||
If some of the imported names are intended to be used, then add the missing
|
||||
code.
|
||||
UNUSED_LOCAL_VARIABLE:
|
||||
problemMessage: "The value of the local variable '{0}' isn't used."
|
||||
correctionMessage: Try removing the variable or using it.
|
||||
hasPublishedDocs: true
|
||||
comment: |-
|
||||
Parameters:
|
||||
0: the name of the unused variable
|
||||
documentation: |-
|
||||
#### Description
|
||||
|
||||
The analyzer produces this diagnostic when a local variable is declared but
|
||||
never read, even if it's written in one or more places.
|
||||
|
||||
#### Example
|
||||
|
||||
The following code produces this diagnostic because the value of `count` is
|
||||
never read:
|
||||
|
||||
```dart
|
||||
void main() {
|
||||
int [!count!] = 0;
|
||||
}
|
||||
```
|
||||
|
||||
#### Common fixes
|
||||
|
||||
If the variable isn't needed, then remove it.
|
||||
|
||||
If the variable was intended to be used, then add the missing code.
|
||||
UNUSED_SHOWN_NAME:
|
||||
problemMessage: "The name {0} is shown, but isn't used."
|
||||
correctionMessage: Try removing the name from the list of shown members.
|
||||
hasPublishedDocs: true
|
||||
comment: |-
|
||||
Parameters:
|
||||
0: the name that is shown but not used
|
||||
documentation: |-
|
||||
#### Description
|
||||
|
||||
The analyzer produces this diagnostic when a show combinator includes a
|
||||
name that isn't used within the library. Because it isn't referenced, the
|
||||
name can be removed.
|
||||
|
||||
#### Example
|
||||
|
||||
The following code produces this diagnostic because the function `max`
|
||||
isn't used:
|
||||
|
||||
```dart
|
||||
import 'dart:math' show min, [!max!];
|
||||
|
||||
var x = min(0, 1);
|
||||
```
|
||||
|
||||
#### Common fixes
|
||||
|
||||
Either use the name or remove it:
|
||||
|
||||
```dart
|
||||
import 'dart:math' show min;
|
||||
|
||||
var x = min(0, 1);
|
||||
```
|
||||
aliasFor: WarningCode.UNUSED_LOCAL_VARIABLE
|
||||
comment: This is the deprecated alias for [WarningCode.UNUSED_LOCAL_VARIABLE].
|
||||
LanguageCode:
|
||||
IMPLICIT_DYNAMIC_FIELD:
|
||||
problemMessage: "Missing field type for '{0}'."
|
||||
|
@ -25275,11 +25146,74 @@ WarningCode:
|
|||
aliasFor: HintCode.UNUSED_ELEMENT_PARAMETER
|
||||
comment: This is the new replacement for [HintCode.UNUSED_ELEMENT_PARAMETER].
|
||||
UNUSED_FIELD:
|
||||
aliasFor: HintCode.UNUSED_FIELD
|
||||
comment: This is the new replacement for [HintCode.UNUSED_FIELD].
|
||||
problemMessage: "The value of the field '{0}' isn't used."
|
||||
correctionMessage: Try removing the field, or using it.
|
||||
hasPublishedDocs: true
|
||||
comment: |-
|
||||
Parameters:
|
||||
0: the name of the unused field
|
||||
documentation: |-
|
||||
#### Description
|
||||
|
||||
The analyzer produces this diagnostic when a private field is declared but
|
||||
never read, even if it's written in one or more places.
|
||||
|
||||
#### Example
|
||||
|
||||
The following code produces this diagnostic because the field
|
||||
`_originalValue` isn't read anywhere in the library:
|
||||
|
||||
```dart
|
||||
class C {
|
||||
final String [!_originalValue!];
|
||||
final String _currentValue;
|
||||
|
||||
C(this._originalValue) : _currentValue = _originalValue;
|
||||
|
||||
String get value => _currentValue;
|
||||
}
|
||||
```
|
||||
|
||||
It might appear that the field `_originalValue` is being read in the
|
||||
initializer (`_currentValue = _originalValue`), but that is actually a
|
||||
reference to the parameter of the same name, not a reference to the field.
|
||||
|
||||
#### Common fixes
|
||||
|
||||
If the field isn't needed, then remove it.
|
||||
|
||||
If the field was intended to be used, then add the missing code.
|
||||
UNUSED_IMPORT:
|
||||
aliasFor: HintCode.UNUSED_IMPORT
|
||||
comment: This is the new replacement for [HintCode.UNUSED_IMPORT].
|
||||
problemMessage: "Unused import: '{0}'."
|
||||
correctionMessage: Try removing the import directive.
|
||||
hasPublishedDocs: true
|
||||
comment: |-
|
||||
Parameters:
|
||||
0: the content of the unused import's URI
|
||||
documentation: |-
|
||||
#### Description
|
||||
|
||||
The analyzer produces this diagnostic when an import isn't needed because
|
||||
none of the names that are imported are referenced within the importing
|
||||
library.
|
||||
|
||||
#### Example
|
||||
|
||||
The following code produces this diagnostic because nothing defined in
|
||||
`dart:async` is referenced in the library:
|
||||
|
||||
```dart
|
||||
import [!'dart:async'!];
|
||||
|
||||
void main() {}
|
||||
```
|
||||
|
||||
#### Common fixes
|
||||
|
||||
If the import isn't needed, then remove it.
|
||||
|
||||
If some of the imported names are intended to be used, then add the missing
|
||||
code.
|
||||
UNUSED_LABEL:
|
||||
problemMessage: "The label '{0}' isn't used."
|
||||
correctionMessage: "Try removing the label, or using it in either a 'break' or 'continue' statement."
|
||||
|
@ -25332,8 +25266,34 @@ WarningCode:
|
|||
```
|
||||
TODO(brianwilkerson) Highlight the identifier without the colon.
|
||||
UNUSED_LOCAL_VARIABLE:
|
||||
aliasFor: HintCode.UNUSED_LOCAL_VARIABLE
|
||||
comment: This is the new replacement for [HintCode.UNUSED_LOCAL_VARIABLE].
|
||||
problemMessage: "The value of the local variable '{0}' isn't used."
|
||||
correctionMessage: Try removing the variable or using it.
|
||||
hasPublishedDocs: true
|
||||
comment: |-
|
||||
Parameters:
|
||||
0: the name of the unused variable
|
||||
documentation: |-
|
||||
#### Description
|
||||
|
||||
The analyzer produces this diagnostic when a local variable is declared but
|
||||
never read, even if it's written in one or more places.
|
||||
|
||||
#### Example
|
||||
|
||||
The following code produces this diagnostic because the value of `count` is
|
||||
never read:
|
||||
|
||||
```dart
|
||||
void main() {
|
||||
int [!count!] = 0;
|
||||
}
|
||||
```
|
||||
|
||||
#### Common fixes
|
||||
|
||||
If the variable isn't needed, then remove it.
|
||||
|
||||
If the variable was intended to be used, then add the missing code.
|
||||
UNUSED_RESULT:
|
||||
problemMessage: "The value of '{0}' should be used."
|
||||
correctionMessage: Try using the result by invoking a member, passing it to a function, or returning it from this function.
|
||||
|
@ -25421,3 +25381,37 @@ WarningCode:
|
|||
Parameters:
|
||||
0: the name of the annotated method, property or function
|
||||
1: message details
|
||||
UNUSED_SHOWN_NAME:
|
||||
problemMessage: "The name {0} is shown, but isn't used."
|
||||
correctionMessage: Try removing the name from the list of shown members.
|
||||
hasPublishedDocs: true
|
||||
comment: |-
|
||||
Parameters:
|
||||
0: the name that is shown but not used
|
||||
documentation: |-
|
||||
#### Description
|
||||
|
||||
The analyzer produces this diagnostic when a show combinator includes a
|
||||
name that isn't used within the library. Because it isn't referenced, the
|
||||
name can be removed.
|
||||
|
||||
#### Example
|
||||
|
||||
The following code produces this diagnostic because the function `max`
|
||||
isn't used:
|
||||
|
||||
```dart
|
||||
import 'dart:math' show min, [!max!];
|
||||
|
||||
var x = min(0, 1);
|
||||
```
|
||||
|
||||
#### Common fixes
|
||||
|
||||
Either use the name or remove it:
|
||||
|
||||
```dart
|
||||
import 'dart:math' show min;
|
||||
|
||||
var x = min(0, 1);
|
||||
```
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/dart/error/hint_codes.dart';
|
||||
import 'package:analyzer/src/error/codes.g.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -409,7 +409,7 @@ class A {
|
|||
await assertErrorsInCode('''
|
||||
import 'dart:math' show pi;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
var pi = findElement
|
||||
.import('dart:math')
|
||||
|
@ -423,7 +423,7 @@ import 'dart:math' show pi;
|
|||
await assertErrorsInCode('''
|
||||
import 'dart:math' as p show pi hide ln10;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
var mathNamespace =
|
||||
findElement.import('dart:math').importedLibrary!.exportNamespace;
|
||||
|
@ -437,7 +437,7 @@ import 'dart:math' as p show pi hide ln10;
|
|||
await assertErrorsInCode('''
|
||||
import 'dart:math';
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
expect(findNode.import('dart:math').element!.importedLibrary!.name,
|
||||
'dart.math');
|
||||
|
@ -447,7 +447,7 @@ import 'dart:math';
|
|||
await assertErrorsInCode('''
|
||||
import 'dart:math' as p;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
expect(findNode.import('dart:math').element!.importedLibrary!.name,
|
||||
'dart.math');
|
||||
|
@ -461,7 +461,7 @@ final int v2 = 0;
|
|||
await assertErrorsInCode('''
|
||||
import 'lib1.dart' show v1, v2;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
var importedVariables = findNode
|
||||
.import('lib1.dart')
|
||||
|
|
|
@ -295,7 +295,7 @@ main() {
|
|||
new N2();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_SHOWN_NAME, 44, 1),
|
||||
error(WarningCode.UNUSED_SHOWN_NAME, 44, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -493,7 +493,7 @@ f() {
|
|||
-x;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 14, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 14, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -567,7 +567,7 @@ main() {
|
|||
F f = (int i) async => i;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 43, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 43, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -694,7 +694,7 @@ f(list) async {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 33, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 33, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -705,7 +705,7 @@ f(list) async* {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 34, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 34, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -788,7 +788,7 @@ f() {
|
|||
dynamic x;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 16, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 16, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -1054,7 +1054,7 @@ main() {
|
|||
const int x = 0;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 21, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 21, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -1171,7 +1171,7 @@ main() {
|
|||
var v = dynamic;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 15, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -1665,8 +1665,8 @@ library test;
|
|||
import 'lib.dart';
|
||||
import 'lib.dart';
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 21, 10),
|
||||
error(HintCode.UNUSED_IMPORT, 40, 10),
|
||||
error(WarningCode.UNUSED_IMPORT, 21, 10),
|
||||
error(WarningCode.UNUSED_IMPORT, 40, 10),
|
||||
error(WarningCode.DUPLICATE_IMPORT, 40, 10),
|
||||
]);
|
||||
}
|
||||
|
@ -1680,8 +1680,8 @@ library test;
|
|||
import 'lib1.dart';
|
||||
import 'lib2.dart';
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 21, 11),
|
||||
error(HintCode.UNUSED_IMPORT, 41, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 21, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 41, 11),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -1992,9 +1992,9 @@ class A {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 26, 5),
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 41, 5),
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 56, 5),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 26, 5),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 41, 5),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 56, 5),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -2188,7 +2188,7 @@ void main() {
|
|||
String p = z;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 93, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 93, 1),
|
||||
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 97, 1),
|
||||
]);
|
||||
var z = result.unit.declaredElement!.topLevelVariables
|
||||
|
@ -2245,7 +2245,7 @@ h(bool b) {
|
|||
Map<num, String> m = (b ? f : g)('x');
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 104, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 104, 1),
|
||||
]);
|
||||
var parameter = findNode.stringLiteral("'x'").staticParameterElement;
|
||||
expect(parameter!.library, isNull);
|
||||
|
@ -2466,7 +2466,7 @@ f2() {
|
|||
!dynamic;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 47, 7),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 47, 7),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -2598,7 +2598,7 @@ f() {
|
|||
var m = {'a' : 0, 'b' : 1};
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 12, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 12, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -2949,7 +2949,7 @@ f() {
|
|||
var x = new A.x();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 35, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 35, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -2962,7 +2962,7 @@ f(A a) {
|
|||
var x = a.x();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 36, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 36, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -2975,7 +2975,7 @@ f(A a) {
|
|||
var x = a.x;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 36, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 36, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -3273,7 +3273,7 @@ void testNewSet(Set<C> setEls) {
|
|||
newSet: <T>() => customNewSet = new Set<T>());
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 51, 12),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 51, 12),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -3379,7 +3379,7 @@ main(FuncAtoDyn f) {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 115, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 115, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -3394,7 +3394,7 @@ main(FuncDynToVoid f) {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 124, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 124, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ f(var message, var dynamic_) {
|
|||
int s = message;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 94, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 94, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ f(var message) {
|
|||
int s = message;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 119, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 119, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ f(var message) {
|
|||
String s = message;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 100, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 100, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ class C {
|
|||
}
|
||||
}''', [
|
||||
error(ParserErrorCode.EXPECTED_TOKEN, 26, 3),
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 26, 3),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 26, 3),
|
||||
error(HintCode.UNUSED_ELEMENT, 30, 1),
|
||||
error(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, 32, 2),
|
||||
]);
|
||||
|
|
|
@ -543,8 +543,8 @@ f() {
|
|||
for (int x in list) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 40, 1),
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 65, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 40, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 65, 1),
|
||||
]);
|
||||
verifyTestResolved();
|
||||
}
|
||||
|
@ -611,7 +611,7 @@ void main() {
|
|||
var y = new C().x;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 124, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 124, 1),
|
||||
]);
|
||||
verifyTestResolved();
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ f() async {
|
|||
String a = await fi(); // Warning: int not assignable to String
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 58, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 58, 1),
|
||||
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 62, 10),
|
||||
]);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ f(Stream<int> stream) async {
|
|||
await for (int i in stream) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 47, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 47, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ f(Stream<String> stream) async {
|
|||
await for (int i in stream) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 50, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 50, 1),
|
||||
error(CompileTimeErrorCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, 55, 6),
|
||||
]);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ f(Stream<num> stream) async {
|
|||
await for (int i in stream) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 47, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 47, 1),
|
||||
error(CompileTimeErrorCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, 52, 6),
|
||||
]);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ f(Stream<int> stream) async {
|
|||
await for (var i in stream) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 47, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 47, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ f(Stream<int> stream) async {
|
|||
await for (i in stream) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 41, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 41, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ f(Stream<String> stream) async {
|
|||
await for (i in stream) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 44, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 44, 1),
|
||||
error(CompileTimeErrorCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, 65, 6),
|
||||
]);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ f(Stream stream) async {
|
|||
await for (int i in stream) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 42, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 42, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ f(Stream<int> stream) async {
|
|||
await for (num i in stream) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 47, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 47, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ f() {
|
|||
for (int i in <int>[]) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ f() {
|
|||
for (int i in <String>[]) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
error(CompileTimeErrorCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, 22, 10),
|
||||
]);
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ f() {
|
|||
for (var i in d) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 46, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 46, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ f() {
|
|||
for (int i in iterable) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 37, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 37, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ f() {
|
|||
for (var i in <int>[]) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ f() {
|
|||
for (i in <int>[]) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 12, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 12, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ f() {
|
|||
for (i in <String>[]) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 12, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 12, 1),
|
||||
error(CompileTimeErrorCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, 27, 10),
|
||||
]);
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ f() {
|
|||
for (int i in []) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ f(List o) { // Could be [].
|
|||
for (var i in o) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 39, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 39, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ class Foo<T extends Iterable<int>> {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 81, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 81, 1),
|
||||
error(CompileTimeErrorCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, 86, 8),
|
||||
]);
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ class Foo<T extends Iterable<int>> {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 78, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 78, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ f() {
|
|||
for (num i in <int>[]) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -391,7 +391,7 @@ g(Object p) {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_ELEMENT, 16, 1),
|
||||
error(WarningCode.UNUSED_ELEMENT, 16, 1),
|
||||
error(CompileTimeErrorCode.UNDEFINED_GETTER, 57, 6),
|
||||
]);
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ f() async {
|
|||
Future<int> b = await ffi();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 61, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 61, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -503,7 +503,7 @@ void main() {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 271, 4),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 271, 4),
|
||||
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 289, 2),
|
||||
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 304, 2),
|
||||
]);
|
||||
|
@ -515,7 +515,7 @@ f() {
|
|||
for (int i in <num>[]) {}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 17, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ mixin StrongModeLocalInferenceTestCases on PubPackageResolutionTest {
|
|||
await assertErrorsInCode(code, [
|
||||
if (isNullSafetyEnabled)
|
||||
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 32, 4),
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 60, 1),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 60, 1),
|
||||
]);
|
||||
|
||||
List<Statement> statements =
|
||||
|
|
|
@ -1484,14 +1484,6 @@ part of 'b.dart';
|
|||
}, throwsArgumentError);
|
||||
}
|
||||
|
||||
test_hint() async {
|
||||
await assertErrorsInCode(r'''
|
||||
import 'dart:math';
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
}
|
||||
|
||||
test_hint_in_third_party() async {
|
||||
var aPath = convertPath('/workspace/third_party/dart/aaa/lib/a.dart');
|
||||
newFile(aPath, r'''
|
||||
|
@ -2605,6 +2597,14 @@ import 'foo:bar';
|
|||
]);
|
||||
}
|
||||
|
||||
test_warning() async {
|
||||
await assertErrorsInCode(r'''
|
||||
import 'dart:math';
|
||||
''', [
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
}
|
||||
|
||||
void _assertResolvedFiles(
|
||||
List<File> expected, {
|
||||
bool andClear = true,
|
||||
|
|
|
@ -29,7 +29,7 @@ import 'c.dart';
|
|||
|
||||
await resolveFile2(b.path);
|
||||
assertErrorsInResult([
|
||||
error(HintCode.UNUSED_IMPORT, 33, 8),
|
||||
error(WarningCode.UNUSED_IMPORT, 33, 8),
|
||||
]);
|
||||
|
||||
final node = findNode.import('c.dart');
|
||||
|
|
|
@ -35,7 +35,7 @@ main() {
|
|||
a.loadLibrary();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 22, 8),
|
||||
error(WarningCode.UNUSED_IMPORT, 22, 8),
|
||||
]);
|
||||
|
||||
var node = findNode.methodInvocation('loadLibrary()');
|
||||
|
@ -4473,7 +4473,7 @@ main() {
|
|||
math?.loadLibrary();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
error(CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, 49, 4),
|
||||
]);
|
||||
|
||||
|
@ -6199,7 +6199,7 @@ main() {
|
|||
math.loadLibrary();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
|
||||
var node = findNode.methodInvocation('loadLibrary()');
|
||||
|
@ -6252,7 +6252,7 @@ main() {
|
|||
math.loadLibrary(1 + 2);
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 66, 5),
|
||||
]);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ main() {
|
|||
a.loadLibrary;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 22, 8),
|
||||
error(WarningCode.UNUSED_IMPORT, 22, 8),
|
||||
]);
|
||||
|
||||
var import = findElement.importFind('package:test/a.dart');
|
||||
|
|
|
@ -19,7 +19,7 @@ class BuiltInIdentifierAsPrefixNameTest extends PubPackageResolutionTest {
|
|||
await assertErrorsInCode('''
|
||||
import 'dart:async' as abstract;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 12),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 12),
|
||||
error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_PREFIX_NAME, 23, 8),
|
||||
]);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import 'dart:async' as abstract;
|
|||
await assertErrorsInCode('''
|
||||
import 'dart:async' as Function;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 12),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 12),
|
||||
error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_PREFIX_NAME, 23, 8),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ extension on String {
|
|||
int get foo => 0;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 35, 3),
|
||||
error(WarningCode.UNUSED_FIELD, 35, 3),
|
||||
error(_errorCode, 35, 3),
|
||||
error(HintCode.UNUSED_ELEMENT, 54, 3),
|
||||
]);
|
||||
|
|
|
@ -25,7 +25,7 @@ class ImportInternalLibraryTest extends PubPackageResolutionTest {
|
|||
import 'dart:_internal';
|
||||
''', [
|
||||
error(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, 7, 16),
|
||||
error(HintCode.UNUSED_IMPORT, 7, 16),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 16),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -557,8 +557,8 @@ void main() {
|
|||
b += 3;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 19, 6),
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 116, 1),
|
||||
error(WarningCode.UNUSED_FIELD, 19, 6),
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 116, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ import 'package:meta/meta.dart';
|
|||
assertErrorsInResult([
|
||||
error(WarningCode.INVALID_INTERNAL_ANNOTATION, 33, 9),
|
||||
error(HintCode.UNUSED_ELEMENT, 48, 2),
|
||||
error(HintCode.UNUSED_FIELD, 52, 3),
|
||||
error(WarningCode.UNUSED_FIELD, 52, 3),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,7 @@ enum E {@internal _one}
|
|||
|
||||
assertErrorsInResult([
|
||||
error(WarningCode.INVALID_INTERNAL_ANNOTATION, 41, 9),
|
||||
error(HintCode.UNUSED_FIELD, 51, 4),
|
||||
error(WarningCode.UNUSED_FIELD, 51, 4),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ class C {
|
|||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
error(HintCode.UNUSED_FIELD, 59, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 59, 2),
|
||||
error(WarningCode.INVALID_INTERNAL_ANNOTATION, 59, 6),
|
||||
]);
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ class C {
|
|||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
error(HintCode.UNUSED_FIELD, 66, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 66, 2),
|
||||
error(WarningCode.INVALID_INTERNAL_ANNOTATION, 66, 6),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -367,7 +367,7 @@ import 'package:meta/meta.dart';
|
|||
import 'package:foo/src/a.dart';
|
||||
''', [
|
||||
error(WarningCode.INVALID_USE_OF_INTERNAL_MEMBER, 0, 32),
|
||||
error(HintCode.UNUSED_IMPORT, 7, 24),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 24),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -413,7 +413,7 @@ class A {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 49, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 49, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ void main() {
|
|||
''');
|
||||
|
||||
await _resolveFile('$testPackageLibPath/lib1.dart', [
|
||||
error(HintCode.UNUSED_FIELD, 86, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 86, 2),
|
||||
]);
|
||||
await _resolveFile('$testPackageLibPath/lib2.dart', [
|
||||
error(WarningCode.INVALID_USE_OF_VISIBLE_FOR_TEMPLATE_MEMBER, 41, 1),
|
||||
|
@ -380,7 +380,7 @@ void main() {
|
|||
''');
|
||||
|
||||
await _resolveFile('$testPackageLibPath/lib1.dart', [
|
||||
error(HintCode.UNUSED_FIELD, 65, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 65, 2),
|
||||
]);
|
||||
await _resolveFile('$testPackageLibPath/lib2.dart', [
|
||||
error(WarningCode.INVALID_USE_OF_VISIBLE_FOR_TEMPLATE_MEMBER, 41, 13),
|
||||
|
@ -536,7 +536,7 @@ void main() {
|
|||
''');
|
||||
|
||||
await _resolveFile('$testPackageLibPath/lib1.dart', [
|
||||
error(HintCode.UNUSED_FIELD, 65, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 65, 2),
|
||||
]);
|
||||
await _resolveFile('$testPackageLibPath/lib2.dart', [
|
||||
error(WarningCode.INVALID_USE_OF_VISIBLE_FOR_TEMPLATE_MEMBER, 41, 1),
|
||||
|
|
|
@ -325,7 +325,7 @@ void main() {
|
|||
''');
|
||||
|
||||
await _resolveFile('$testPackageRootPath/lib1.dart', [
|
||||
error(HintCode.UNUSED_FIELD, 49, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 49, 2),
|
||||
]);
|
||||
await _resolveFile('$testPackageRootPath/lib2.dart', [
|
||||
error(WarningCode.INVALID_USE_OF_VISIBLE_FOR_TESTING_MEMBER, 40, 12,
|
||||
|
@ -450,7 +450,7 @@ void main() {
|
|||
''');
|
||||
|
||||
await _resolveFile('$testPackageRootPath/lib1.dart', [
|
||||
error(HintCode.UNUSED_FIELD, 49, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 49, 2),
|
||||
]);
|
||||
await _resolveFile('$testPackageRootPath/lib2.dart', [
|
||||
error(WarningCode.INVALID_USE_OF_VISIBLE_FOR_TESTING_MEMBER, 40, 1),
|
||||
|
|
|
@ -29,7 +29,7 @@ class C {
|
|||
}
|
||||
''', [
|
||||
error(WarningCode.INVALID_VISIBILITY_ANNOTATION, 45, 18),
|
||||
error(HintCode.UNUSED_FIELD, 68, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 68, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,8 @@ class C {
|
|||
''', [
|
||||
error(WarningCode.INVALID_VISIBILITY_ANNOTATION, 45, 18),
|
||||
error(WarningCode.INVALID_VISIBILITY_ANNOTATION, 45, 18),
|
||||
error(HintCode.UNUSED_FIELD, 68, 2),
|
||||
error(HintCode.UNUSED_FIELD, 76, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 68, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 76, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ class C {
|
|||
}
|
||||
''', [
|
||||
error(WarningCode.INVALID_VISIBILITY_ANNOTATION, 45, 18),
|
||||
error(HintCode.UNUSED_FIELD, 68, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 68, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,35 +17,37 @@ main() {
|
|||
@reflectiveTest
|
||||
class MockSdkTest extends PubPackageResolutionTest {
|
||||
test_dart_async() async {
|
||||
await _assertOnlyHintsInLibraryUri('dart:async');
|
||||
await _assertOnlyWarningsInLibraryUri('dart:async');
|
||||
}
|
||||
|
||||
test_dart_convert() async {
|
||||
await _assertOnlyHintsInLibraryUri('dart:convert');
|
||||
await _assertOnlyWarningsInLibraryUri('dart:convert');
|
||||
}
|
||||
|
||||
test_dart_core() async {
|
||||
await _assertOnlyHintsInLibraryUri('dart:core');
|
||||
await _assertOnlyWarningsInLibraryUri('dart:core');
|
||||
}
|
||||
|
||||
test_dart_math() async {
|
||||
await _assertOnlyHintsInLibraryUri('dart:math');
|
||||
await _assertOnlyWarningsInLibraryUri('dart:math');
|
||||
}
|
||||
|
||||
void _assertOnlyHintsInLibrary(ResolvedLibraryResult coreResolvedResult) {
|
||||
for (var resolvedUnit in coreResolvedResult.units) {
|
||||
_assertOnlyHintsInUnit(resolvedUnit);
|
||||
_assertOnlyWarningsInUnit(resolvedUnit);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _assertOnlyHintsInLibraryUri(String uriStr) async {
|
||||
Future<void> _assertOnlyWarningsInLibraryUri(String uriStr) async {
|
||||
var coreResolvedResult = await _resolvedLibraryByUri(uriStr);
|
||||
_assertOnlyHintsInLibrary(coreResolvedResult);
|
||||
}
|
||||
|
||||
void _assertOnlyHintsInUnit(ResolvedUnitResult resolvedUnit) {
|
||||
void _assertOnlyWarningsInUnit(ResolvedUnitResult resolvedUnit) {
|
||||
var notHints = resolvedUnit.errors
|
||||
.where((element) => element.errorCode.type != ErrorType.HINT)
|
||||
.where((element) =>
|
||||
element.errorCode.type != ErrorType.HINT &&
|
||||
element.errorCode.type != ErrorType.STATIC_WARNING)
|
||||
.toList();
|
||||
assertErrorsInList(notHints, []);
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ f() {
|
|||
p?.loadLibrary();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 10),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 10),
|
||||
error(CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, 41, 1),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ f(int a) {
|
|||
return x;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 12),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 12),
|
||||
error(CompileTimeErrorCode.PREFIX_SHADOWED_BY_LOCAL_DECLARATION, 39, 1),
|
||||
]);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ f() {
|
|||
return [x, a];
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 12),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 12),
|
||||
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 34, 1,
|
||||
contextMessages: [message('$testPackageLibPath/test.dart', 60, 1)]),
|
||||
error(CompileTimeErrorCode.PREFIX_SHADOWED_BY_LOCAL_DECLARATION, 34, 1),
|
||||
|
@ -62,7 +62,7 @@ f() {
|
|||
return [x, a];
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 12),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 12),
|
||||
error(CompileTimeErrorCode.PREFIX_SHADOWED_BY_LOCAL_DECLARATION, 47, 1),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class A {
|
|||
A({this._p = 0});
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 16, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 16, 2),
|
||||
error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 30, 2),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ export 'lib1.dart' hide a;
|
|||
await assertErrorsInCode(r'''
|
||||
import 'lib1.dart' hide a;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNDEFINED_HIDDEN_NAME, 24, 1),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ export 'lib1.dart' show a;
|
|||
await assertErrorsInCode(r'''
|
||||
import 'lib1.dart' show a;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNDEFINED_SHOWN_NAME, 24, 1),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -195,7 +195,7 @@ class A {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 16, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 16, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ class A {
|
|||
A() : _f = 0;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 16, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 16, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,7 @@ extension Bar on Foo {
|
|||
static final _baz = 7;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 51, 4),
|
||||
error(WarningCode.UNUSED_FIELD, 51, 4),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,7 @@ class A {
|
|||
A(this._f);
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 16, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 16, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -239,7 +239,7 @@ mixin M {
|
|||
}
|
||||
class Bar with M {}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 16, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 16, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -250,7 +250,7 @@ class Foo {
|
|||
}
|
||||
mixin M on Foo {}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 18, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 18, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,7 @@ class A {
|
|||
int _f = 0;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 16, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 16, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -285,7 +285,7 @@ class A {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 16, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 16, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -298,7 +298,7 @@ class A {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 16, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 16, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ class _A {
|
|||
}
|
||||
void main() => print(_A);
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 27, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 27, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -319,7 +319,7 @@ extension _A on String {
|
|||
static String f1 = "x";
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 41, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 41, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -330,7 +330,7 @@ mixin _A {
|
|||
}
|
||||
void main() => print(_A);
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 27, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 27, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ class A {
|
|||
int _f = 0;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 37, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 37, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -357,7 +357,7 @@ f(A a) {
|
|||
a._f = 2;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 16, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 16, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -383,7 +383,7 @@ void f() {
|
|||
_E;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 12, 1),
|
||||
error(WarningCode.UNUSED_FIELD, 12, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ void f() {
|
|||
_E.v;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 34, 3),
|
||||
error(WarningCode.UNUSED_FIELD, 34, 3),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -472,7 +472,7 @@ enum E {
|
|||
_v
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 11, 2),
|
||||
error(WarningCode.UNUSED_FIELD, 11, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -496,7 +496,7 @@ enum E {
|
|||
final int _foo = 0;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 26, 4),
|
||||
error(WarningCode.UNUSED_FIELD, 26, 4),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ import 'lib1.dart';
|
|||
import 'lib1.dart' as one;
|
||||
one.A a = one.A();
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ import 'lib1.dart' as one;
|
|||
import 'lib2.dart' as one;
|
||||
one.A a = one.A();
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 34, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 34, 11),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ import 'dart:io' as prefix;
|
|||
import 'a.dart' as prefix;
|
||||
prefix.File? f;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 9),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 9),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -352,7 +352,7 @@ extension E on String {
|
|||
await assertErrorsInCode('''
|
||||
import 'lib1.dart' as lib1;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -380,7 +380,7 @@ import 'lib1.dart';
|
|||
import 'lib1.dart' hide A;
|
||||
A? a;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 27, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 27, 11),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -424,7 +424,7 @@ f() {
|
|||
''.b();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ import 'lib1.dart' show A;
|
|||
import 'lib1.dart' show B;
|
||||
A a = A();
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 34, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 34, 11),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -451,7 +451,7 @@ import 'dart:io';
|
|||
import 'lib1.dart';
|
||||
File? f;
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 9),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 9),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -460,7 +460,7 @@ File? f;
|
|||
await assertErrorsInCode(r'''
|
||||
import 'lib1.dart';
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 11),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 11),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ f() {
|
|||
s.length;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_SHOWN_NAME, 24, 1),
|
||||
error(WarningCode.UNUSED_SHOWN_NAME, 24, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ class B {}
|
|||
import 'lib1.dart' show A, B;
|
||||
A a = A();
|
||||
''', [
|
||||
error(HintCode.UNUSED_SHOWN_NAME, 27, 1),
|
||||
error(WarningCode.UNUSED_SHOWN_NAME, 27, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ class B {}
|
|||
import 'lib1.dart' as p show A, B;
|
||||
p.A a = p.A();
|
||||
''', [
|
||||
error(HintCode.UNUSED_SHOWN_NAME, 32, 1),
|
||||
error(WarningCode.UNUSED_SHOWN_NAME, 32, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -182,8 +182,8 @@ import 'lib1.dart' show C, D;
|
|||
A a = A();
|
||||
C c = C();
|
||||
''', [
|
||||
error(HintCode.UNUSED_SHOWN_NAME, 27, 1),
|
||||
error(HintCode.UNUSED_SHOWN_NAME, 57, 1),
|
||||
error(WarningCode.UNUSED_SHOWN_NAME, 27, 1),
|
||||
error(WarningCode.UNUSED_SHOWN_NAME, 57, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,7 @@ int a = var1;
|
|||
int b = var2;
|
||||
int c = var3;
|
||||
''', [
|
||||
error(HintCode.UNUSED_SHOWN_NAME, 66, 4),
|
||||
error(WarningCode.UNUSED_SHOWN_NAME, 66, 4),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ import 'unknown.dart';
|
|||
await assertErrorsInCode('''
|
||||
import 'target.dart';
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 13),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 13),
|
||||
]);
|
||||
|
||||
// Remove the overlay in the same way as AnalysisServer.
|
||||
|
@ -133,7 +133,7 @@ import 'target.dart';
|
|||
// file is not being reanalyzed.
|
||||
await resolveTestFile();
|
||||
assertErrorsInResult([
|
||||
error(HintCode.UNUSED_IMPORT, 0, 0),
|
||||
error(WarningCode.UNUSED_IMPORT, 0, 0),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ class B extends A {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 8),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 8),
|
||||
]);
|
||||
var import = findElement.importFind('package:test/a.dart');
|
||||
_checkGetterDifferent(import.topSet('foo'));
|
||||
|
@ -132,7 +132,7 @@ class B extends A {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 8),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 8),
|
||||
]);
|
||||
var import = findElement.importFind('package:test/a.dart');
|
||||
_checkGetterRequested(import.topGet('foo'));
|
||||
|
@ -292,7 +292,7 @@ class B extends A {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 8),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 8),
|
||||
]);
|
||||
var import = findElement.importFind('package:test/a.dart');
|
||||
_checkMethodRequested(import.topFunction('foo'));
|
||||
|
@ -546,7 +546,7 @@ class B extends A {
|
|||
}
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 7, 8),
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 8),
|
||||
]);
|
||||
var import = findElement.importFind('package:test/a.dart');
|
||||
_checkSetterRequested(import.topSet('foo'));
|
||||
|
|
|
@ -2629,8 +2629,8 @@ class Child extends helper.Base {
|
|||
String _m1() => null;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 83, 3),
|
||||
error(HintCode.UNUSED_FIELD, 94, 3),
|
||||
error(WarningCode.UNUSED_FIELD, 83, 3),
|
||||
error(WarningCode.UNUSED_FIELD, 94, 3),
|
||||
error(HintCode.UNUSED_ELEMENT, 109, 3),
|
||||
]);
|
||||
}
|
||||
|
@ -3018,8 +3018,8 @@ void main() {
|
|||
print((dyn) ? false : true);
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_FIELD, 247, 11),
|
||||
error(HintCode.UNUSED_FIELD, 273, 9),
|
||||
error(WarningCode.UNUSED_FIELD, 247, 11),
|
||||
error(WarningCode.UNUSED_FIELD, 273, 9),
|
||||
error(CompileTimeErrorCode.NON_BOOL_CONDITION, 1311, 1),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ $snippet
|
|||
if (results is ErrorsResult) {
|
||||
Iterable<AnalysisError> errors = results.errors.where((error) {
|
||||
ErrorCode errorCode = error.errorCode;
|
||||
return errorCode != HintCode.UNUSED_IMPORT &&
|
||||
return errorCode != WarningCode.UNUSED_IMPORT &&
|
||||
errorCode != HintCode.UNUSED_LOCAL_VARIABLE;
|
||||
});
|
||||
if (errors.isNotEmpty) {
|
||||
|
|
|
@ -109,10 +109,10 @@ class AbstractSingleUnitTest extends AbstractContextTest {
|
|||
return error.errorCode != WarningCode.DEAD_CODE &&
|
||||
error.errorCode != WarningCode.UNUSED_CATCH_CLAUSE &&
|
||||
error.errorCode != WarningCode.UNUSED_CATCH_STACK &&
|
||||
error.errorCode != HintCode.UNUSED_ELEMENT &&
|
||||
error.errorCode != HintCode.UNUSED_FIELD &&
|
||||
error.errorCode != HintCode.UNUSED_IMPORT &&
|
||||
error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE;
|
||||
error.errorCode != WarningCode.UNUSED_ELEMENT &&
|
||||
error.errorCode != WarningCode.UNUSED_FIELD &&
|
||||
error.errorCode != WarningCode.UNUSED_IMPORT &&
|
||||
error.errorCode != WarningCode.UNUSED_LOCAL_VARIABLE;
|
||||
}), isEmpty);
|
||||
}
|
||||
findNode = FindNode(testCode, testUnit);
|
||||
|
|
|
@ -45,11 +45,11 @@ class AbstractSingleUnitTest extends AbstractContextTest {
|
|||
return error.errorCode != WarningCode.DEAD_CODE &&
|
||||
error.errorCode != WarningCode.UNUSED_CATCH_CLAUSE &&
|
||||
error.errorCode != WarningCode.UNUSED_CATCH_STACK &&
|
||||
error.errorCode != HintCode.UNUSED_ELEMENT &&
|
||||
error.errorCode != HintCode.UNUSED_ELEMENT_PARAMETER &&
|
||||
error.errorCode != HintCode.UNUSED_FIELD &&
|
||||
error.errorCode != HintCode.UNUSED_IMPORT &&
|
||||
error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE;
|
||||
error.errorCode != WarningCode.UNUSED_ELEMENT &&
|
||||
error.errorCode != WarningCode.UNUSED_ELEMENT_PARAMETER &&
|
||||
error.errorCode != WarningCode.UNUSED_FIELD &&
|
||||
error.errorCode != WarningCode.UNUSED_IMPORT &&
|
||||
error.errorCode != WarningCode.UNUSED_LOCAL_VARIABLE;
|
||||
}), isEmpty);
|
||||
}
|
||||
testUnitElement = testUnit!.declaredElement;
|
||||
|
|
|
@ -3,6 +3,9 @@ analyzer:
|
|||
dead_code: info
|
||||
getter_not_subtype_setter_types: info
|
||||
missing_enum_constant_in_switch: info
|
||||
unused_element: info
|
||||
unused_field: info
|
||||
unused_import: info
|
||||
unused_local_variable: info
|
||||
|
||||
exclude:
|
||||
|
|
|
@ -337,7 +337,7 @@ class ValidateCommentCodeSamplesVisitor extends GeneralizingAstVisitor {
|
|||
// Filter out unused imports, since we speculatively add imports to some
|
||||
// samples.
|
||||
errors.removeWhere(
|
||||
(e) => e.errorCode == HintCode.UNUSED_IMPORT,
|
||||
(e) => e.errorCode == WarningCode.UNUSED_IMPORT,
|
||||
);
|
||||
|
||||
// Also, don't worry about 'unused_local_variable' and related; this may
|
||||
|
|
Loading…
Reference in a new issue