[analyzer] Remove many instances of the word 'hint'

I took care to leave code and comments which _does still_ refer to the
remaining Hints. This CL is not super complete, but I think addresses
most of the outdated text refering to Hints. I will do another round
after migrating more to Warnings.

Bug: https://github.com/dart-lang/sdk/issues/50796
Change-Id: Iab58dbbfbdef86e21dd65b2a96d8e34e3e7e54ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290440
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Sam Rawlins 2023-03-23 03:59:55 +00:00 committed by Commit Queue
parent be7d6f6b2b
commit f8c6f2135d
10 changed files with 192 additions and 198 deletions

View file

@ -58,10 +58,10 @@ reflecting that.
### P2
* Incorrect analysis errors or warnings, on edge cases with simple workaround
* Incorrect analysis errors, on edge cases with simple workaround
* EXAMPLE: Disabling the error or warning 'fixes' the issue and unblocks
users.
* Incorrect analysis infos/hints, on edge cases
* Incorrect analysis warnings, on edge cases
* Incorrect resolution of symbols or libraries, edge cases only with workarounds
* Incorrect data from analyzer API, edge cases without workaround
* Automation resulting in incorrect code, edge cases
@ -75,8 +75,8 @@ reflecting that.
* Uncaught exceptions caught by a fuzzer, but believed to be theoretical
situations only
* Incorrect analysis errors or warnings, theoretical
* Incorrect analysis infos/hints, on edge cases with workaround
* Incorrect analysis errors, theoretical
* Incorrect analysis warnings, on edge cases with workaround
* Incorrect resolution of symbols or libraries, theoretical
* Incorrect data from analyzer API, edge case with workaround available
* Performance regression impacting edge cases with workaround or without
@ -89,7 +89,7 @@ reflecting that.
### P4
* Incorrect analysis infos/hints, theoretical
* Incorrect analysis warnings, theoretical
* Incorrect data from analyzer API, theoretical
* Theoretical performance problems
* An enhancement that may have some evidence that it isn't a good idea to
@ -122,8 +122,7 @@ reflecting that.
* "corrupted code" - Modification of source code in such a way that it is
more than just a bit wrong or having some symbols that don't exist, but is
not valid Dart and would be painful to manually correct.
* "diagnostic" - An error, warning, hint, or lint generated by the analyzer
or linter.
* "diagnostic" - An error, warning, or lint generated by the analyzer.
* "incorrect code" - Modification of code in a way that is known to be wrong,
but would be trivial to figure out how to fix for the human using the tool.
* "key users" - Flutter, Pub, Fuchsia, Dart, Google/1P

View file

@ -35,8 +35,8 @@ abstract class AnalysisOptions {
/// analysis.
List<String> get excludePatterns;
/// Return `true` if analysis is to generate hint results (e.g. type inference
/// based information and pub best practices).
/// Return `true` if analysis is to generate hint results (e.g. best practices
/// and analysis based on certain annotations).
bool get hint;
/// Return `true` if analysis is to generate lint warnings.

View file

@ -24,7 +24,7 @@ class ErrorConfig {
/// Create an error config for the given error code map.
/// For example:
/// new ErrorConfig({'missing_return' : 'error'});
/// will create a processor config that turns `missing_return` hints into
/// will create a processor config that turns `missing_return` warnings into
/// errors.
ErrorConfig(YamlNode? codeMap) {
_processMap(codeMap);

View file

@ -250,7 +250,7 @@ class LibraryAnalyzer {
);
}
/// Compute diagnostics in [units], including errors and warnings, hints,
/// Compute diagnostics in [units], including errors and warnings,
/// lints, and a few other cases.
void _computeDiagnostics(Map<FileState, CompilationUnitImpl> units) {
units.forEach((file, unit) {
@ -274,7 +274,7 @@ class LibraryAnalyzer {
}
var usedElements = UsedLocalElements.merge(usedLocalElements);
units.forEach((file, unit) {
_computeHints(
_computeWarnings(
file,
unit,
usedImportedElements: usedImportedElements,
@ -322,85 +322,6 @@ class LibraryAnalyzer {
}
}
void _computeHints(
FileState file,
CompilationUnit unit, {
required List<UsedImportedElements> usedImportedElements,
required UsedLocalElements usedElements,
}) {
AnalysisErrorListener errorListener = _getErrorListener(file);
ErrorReporter errorReporter = _getErrorReporter(file);
if (!_libraryElement.isNonNullableByDefault) {
unit.accept(
LegacyDeadCodeVerifier(
errorReporter,
typeSystem: _typeSystem,
),
);
}
UnicodeTextVerifier(errorReporter).verify(unit, file.content);
unit.accept(DeadCodeVerifier(errorReporter));
unit.accept(
BestPracticesVerifier(
errorReporter,
_typeProvider,
_libraryElement,
unit,
file.content,
declaredVariables: _declaredVariables,
typeSystem: _typeSystem,
inheritanceManager: _inheritance,
analysisOptions: _analysisOptions,
workspacePackage: _library.file.workspacePackage,
),
);
unit.accept(OverrideVerifier(
_inheritance,
_libraryElement,
errorReporter,
));
TodoFinder(errorReporter).findIn(unit);
LanguageVersionOverrideVerifier(errorReporter).verify(unit);
// Verify imports.
{
ImportsVerifier verifier = ImportsVerifier();
verifier.addImports(unit);
usedImportedElements.forEach(verifier.removeUsedElements);
verifier.generateDuplicateExportHints(errorReporter);
verifier.generateDuplicateImportHints(errorReporter);
verifier.generateDuplicateShownHiddenNameHints(errorReporter);
verifier.generateUnusedImportHints(errorReporter);
verifier.generateUnusedShownNameHints(errorReporter);
verifier.generateUnnecessaryImportHints(
errorReporter, usedImportedElements);
}
// Unused local elements.
{
UnusedLocalElementsVerifier visitor = UnusedLocalElementsVerifier(
errorListener, usedElements, _inheritance, _libraryElement);
unit.accept(visitor);
}
//
// Find code that uses features from an SDK version that does not satisfy
// the SDK constraints specified in analysis options.
//
var sdkVersionConstraint = _analysisOptions.sdkVersionConstraint;
if (sdkVersionConstraint != null) {
SdkConstraintVerifier verifier = SdkConstraintVerifier(
errorReporter, _libraryElement, _typeProvider, sdkVersionConstraint);
unit.accept(verifier);
}
}
void _computeLints(
FileState file,
LinterContextUnit currentUnit,
@ -478,6 +399,85 @@ class LibraryAnalyzer {
unit.accept(FfiVerifier(_typeSystem, errorReporter));
}
void _computeWarnings(
FileState file,
CompilationUnit unit, {
required List<UsedImportedElements> usedImportedElements,
required UsedLocalElements usedElements,
}) {
AnalysisErrorListener errorListener = _getErrorListener(file);
ErrorReporter errorReporter = _getErrorReporter(file);
if (!_libraryElement.isNonNullableByDefault) {
unit.accept(
LegacyDeadCodeVerifier(
errorReporter,
typeSystem: _typeSystem,
),
);
}
UnicodeTextVerifier(errorReporter).verify(unit, file.content);
unit.accept(DeadCodeVerifier(errorReporter));
unit.accept(
BestPracticesVerifier(
errorReporter,
_typeProvider,
_libraryElement,
unit,
file.content,
declaredVariables: _declaredVariables,
typeSystem: _typeSystem,
inheritanceManager: _inheritance,
analysisOptions: _analysisOptions,
workspacePackage: _library.file.workspacePackage,
),
);
unit.accept(OverrideVerifier(
_inheritance,
_libraryElement,
errorReporter,
));
TodoFinder(errorReporter).findIn(unit);
LanguageVersionOverrideVerifier(errorReporter).verify(unit);
// Verify imports.
{
ImportsVerifier verifier = ImportsVerifier();
verifier.addImports(unit);
usedImportedElements.forEach(verifier.removeUsedElements);
verifier.generateDuplicateExportWarnings(errorReporter);
verifier.generateDuplicateImportWarnings(errorReporter);
verifier.generateDuplicateShownHiddenNameWarnings(errorReporter);
verifier.generateUnusedImportHints(errorReporter);
verifier.generateUnusedShownNameHints(errorReporter);
verifier.generateUnnecessaryImportHints(
errorReporter, usedImportedElements);
}
// Unused local elements.
{
UnusedLocalElementsVerifier visitor = UnusedLocalElementsVerifier(
errorListener, usedElements, _inheritance, _libraryElement);
unit.accept(visitor);
}
//
// Find code that uses features from an SDK version that does not satisfy
// the SDK constraints specified in analysis options.
//
var sdkVersionConstraint = _analysisOptions.sdkVersionConstraint;
if (sdkVersionConstraint != null) {
SdkConstraintVerifier verifier = SdkConstraintVerifier(
errorReporter, _libraryElement, _typeProvider, sdkVersionConstraint);
unit.accept(verifier);
}
}
/// Return a subset of the given [errors] that are not marked as ignored in
/// the [file].
List<AnalysisError> _filterIgnoredErrors(

View file

@ -794,10 +794,10 @@ class TypeSystemImpl implements TypeSystem {
// If the subtype relation goes the other way, allow the implicit downcast.
if (isSubtypeOf(toType, fromType)) {
// TODO(leafp,jmesserly): we emit warnings/hints for these in
// src/task/strong/checker.dart, which is a bit inconsistent. That
// code should be handled into places that use isAssignableTo, such as
// ErrorVerifier.
// TODO(leafp,jmesserly): we emit warnings for these in
// `src/task/strong/checker.dart`, which is a bit inconsistent. That code
// should be handled into places that use `isAssignableTo`, such as
// [ErrorVerifier].
return true;
}

View file

@ -292,8 +292,9 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
}
} else {
// Something other than a declaration was annotated. Whatever this is,
// it probably warrants a Hint, but this has not been specified on
// visibleForTemplate or visibleForTesting, so leave it alone for now.
// it probably warrants a Warning, but this has not been specified on
// `visibleForTemplate` or `visibleForTesting`, so leave it alone for
// now.
}
}
@ -412,8 +413,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
}
try {
// Commented out until we decide that we want this hint in the analyzer
// checkForOverrideEqualsButNotHashCode(node);
_checkForImmutable(node);
_checkForInvalidSealedSuperclass(node);
super.visitClassDeclaration(node);
@ -459,7 +458,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
var element = node.declaredElement as ConstructorElementImpl;
if (!_isNonNullableByDefault && element.isFactory) {
if (node.body is BlockFunctionBody) {
// Check the block for a return statement, if not, create the hint.
// Check the block for a return statement.
if (!ExitDetector.exits(node.body)) {
_errorReporter.reportErrorForNode(
WarningCode.MISSING_RETURN, node, [node.returnType.name]);
@ -729,8 +728,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
_inDoNotStoreMember = true;
}
try {
// This was determined to not be a good hint, see: dartbug.com/16029
//checkForOverridingPrivateMember(node);
_checkForMissingReturn(node.body, node);
_mustCallSuperVerifier.checkMethodDeclaration(node);
_checkForUnnecessaryNoSuchMethod(node);
@ -775,7 +772,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
@override
void visitMethodInvocation(MethodInvocation node) {
_deprecatedVerifier.methodInvocation(node);
_checkForNullAwareHints(node, node.operator);
_checkForNullAwareWarnings(node, node.operator);
_errorHandlerVerifier.verifyMethodInvocation(node);
_nullSafeApiVerifier.methodInvocation(node);
super.visitMethodInvocation(node);
@ -843,7 +840,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
@override
void visitPropertyAccess(PropertyAccess node) {
_checkForNullAwareHints(node, node.operator);
_checkForNullAwareWarnings(node, node.operator);
super.visitPropertyAccess(node);
}
@ -905,14 +902,15 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
}
}
/// Check for the passed is expression for the unnecessary type check hint
/// codes as well as null checks expressed using an is expression.
/// Checks for the passed [IsExpression] for the unnecessary type check
/// warning codes as well as null checks expressed using an
/// [IsExpression].
///
/// @param node the is expression to check
/// @return `true` if and only if a hint code is generated on the passed node
/// See [HintCode.TYPE_CHECK_IS_NOT_NULL], [HintCode.TYPE_CHECK_IS_NULL],
/// [HintCode.UNNECESSARY_TYPE_CHECK_TRUE], and
/// [HintCode.UNNECESSARY_TYPE_CHECK_FALSE].
/// Returns `true` if a warning code is generated on [node].
/// See [WarningCode.TYPE_CHECK_IS_NOT_NULL],
/// [WarningCode.TYPE_CHECK_IS_NULL],
/// [WarningCode.UNNECESSARY_TYPE_CHECK_TRUE], and
/// [WarningCode.UNNECESSARY_TYPE_CHECK_FALSE].
bool _checkAllTypeChecks(IsExpression node) {
var leftNode = node.expression;
var rightNode = node.type;
@ -921,8 +919,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
void report() {
_errorReporter.reportErrorForNode(
node.notOperator == null
? HintCode.UNNECESSARY_TYPE_CHECK_TRUE
: HintCode.UNNECESSARY_TYPE_CHECK_FALSE,
? WarningCode.UNNECESSARY_TYPE_CHECK_TRUE
: WarningCode.UNNECESSARY_TYPE_CHECK_FALSE,
node,
);
}
@ -1061,7 +1059,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
///
/// If [node] is marked with [immutable] or inherits from a class or mixin
/// marked with [immutable], this function searches the fields of [node] and
/// its superclasses, reporting a hint if any non-final instance fields are
/// its superclasses, reporting a warning if any non-final instance fields are
/// found.
void _checkForImmutable(NamedCompilationUnitMember node) {
/// Return `true` if the given class [element] is annotated with the
@ -1358,10 +1356,10 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
if (constructorName.name != null) {
fullConstructorName = '$fullConstructorName.${constructorName.name}';
}
var hint = node.keyword?.keyword == Keyword.NEW
var warning = node.keyword?.keyword == Keyword.NEW
? WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW
: WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR;
_errorReporter.reportErrorForNode(hint, node, [fullConstructorName]);
_errorReporter.reportErrorForNode(warning, node, [fullConstructorName]);
}
}
@ -1391,13 +1389,10 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
return false;
}
/// Generate a hint for functions or methods that have a return type, but do
/// not have a return statement on all branches. At the end of blocks with no
/// return, Dart implicitly returns `null`. Avoiding these implicit returns
/// is considered a best practice.
///
/// Note: for async functions/methods, this hint only applies when the
/// function has a return type that Future<Null> is not assignable to.
/// Generates a warning for functions that have a potentially non-nullable
/// return type, but do not have a return statement on all branches. At the
/// end of blocks with no return, Dart implicitly returns `null`. Avoiding
/// these implicit returns is considered a best practice.
///
/// See [WarningCode.MISSING_RETURN].
void _checkForMissingReturn(FunctionBody body, AstNode functionNode) {
@ -1465,8 +1460,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
}
}
/// Produce several null-aware related hints.
void _checkForNullAwareHints(Expression node, Token? operator) {
/// Produce several null-aware related warnings.
void _checkForNullAwareWarnings(Expression node, Token? operator) {
if (_isNonNullableByDefault) {
return;
}
@ -1565,10 +1560,10 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
}
}
/// Generate a hint for `noSuchMethod` methods that do nothing except of
/// calling another `noSuchMethod` that is not defined by `Object`.
/// Generates a warning for `noSuchMethod` methods that do nothing except of
/// calling another `noSuchMethod` which is not defined by `Object`.
///
/// Return `true` if and only if a hint code is generated on the passed node.
/// Returns `true` if a warning code is generated for [node].
bool _checkForUnnecessaryNoSuchMethod(MethodDeclaration node) {
if (node.name.lexeme != FunctionElement.NO_SUCH_METHOD_METHOD_NAME) {
return false;
@ -2014,18 +2009,18 @@ class _InvalidAccessVerifier {
: _inTemplateSource =
_library.source.fullName.contains(_templateExtension);
/// Produces a hint if [identifier] is accessed from an invalid location.
/// Produces a warning if [identifier] is accessed from an invalid location.
///
/// In particular, a hint is produced in either of the two following cases:
/// In particular, a warning is produced in either of the two following cases:
///
/// * The element associated with [identifier] is annotated with [internal],
/// and is accessed from outside the package in which the element is
/// declared.
/// * The element associated with [identifier] is annotated with [protected],
/// [visibleForTesting], and/or [visibleForTemplate], and is accessed from a
/// [visibleForTesting], and/or `visibleForTemplate`, and is accessed from a
/// location which is invalid as per the rules of each such annotation.
/// Conversely, if the element is annotated with more than one of these
/// annotations, the access is valid (and no hint will be produced) if it
/// annotations, the access is valid (and no warning is produced) if it
/// conforms to the rules of at least one of the annotations.
void verify(SimpleIdentifier identifier) {
if (identifier.inDeclarationContext() || _inCommentReference(identifier)) {

View file

@ -6090,8 +6090,8 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// This hint is generated anywhere a @factory annotation is associated with
/// anything other than a method.
/// This warning is generated anywhere a @factory annotation is associated
/// with anything other than a method.
static const WarningCode INVALID_FACTORY_ANNOTATION = WarningCode(
'INVALID_FACTORY_ANNOTATION',
"Only methods can be annotated as factories.",
@ -6113,8 +6113,8 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// This hint is generated anywhere an @immutable annotation is associated with
/// anything other than a class.
/// This warning is generated anywhere an @immutable annotation is associated
/// with anything other than a class.
static const WarningCode INVALID_IMMUTABLE_ANNOTATION = WarningCode(
'INVALID_IMMUTABLE_ANNOTATION',
"Only classes can be annotated as being immutable.",
@ -6249,7 +6249,7 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// This hint is generated anywhere where `@nonVirtual` annotates something
/// This warning is generated anywhere where `@nonVirtual` annotates something
/// other than a non-abstract instance member in a class or mixin.
///
/// No Parameters.
@ -6261,7 +6261,7 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// This hint is generated anywhere where an instance member annotated with
/// This warning is generated anywhere where an instance member annotated with
/// `@nonVirtual` is overridden in a subclass.
///
/// Parameters:
@ -6274,7 +6274,7 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// This hint is generated anywhere where `@required` annotates a named
/// This warning is generated anywhere where `@required` annotates a named
/// parameter with a default value.
///
/// Parameters:
@ -6286,7 +6286,7 @@ class WarningCode extends AnalyzerErrorCode {
correctionMessage: "Remove @required.",
);
/// This hint is generated anywhere where `@required` annotates an optional
/// This warning is generated anywhere where `@required` annotates an optional
/// positional parameter.
///
/// Parameters:
@ -6299,8 +6299,8 @@ class WarningCode extends AnalyzerErrorCode {
correctionMessage: "Remove @required.",
);
/// This hint is generated anywhere where `@required` annotates a non optional
/// positional parameter.
/// This warning is generated anywhere where `@required` annotates a
/// non-optional positional parameter.
///
/// Parameters:
/// 0: the name of the member
@ -6311,8 +6311,8 @@ class WarningCode extends AnalyzerErrorCode {
correctionMessage: "Remove @required.",
);
/// This hint is generated anywhere where `@sealed` annotates something other
/// than a class.
/// This warning is generated anywhere where `@sealed` annotates something
/// other than a class.
///
/// No parameters.
static const WarningCode INVALID_SEALED_ANNOTATION = WarningCode(
@ -6330,8 +6330,8 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// This hint is generated anywhere where a member annotated with `@protected`
/// is used outside of an instance member of a subclass.
/// This warning is generated anywhere where a member annotated with
/// `@protected` is used outside of an instance member of a subclass.
///
/// Parameters:
/// 0: the name of the member
@ -6351,7 +6351,7 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// This hint is generated anywhere where a member annotated with
/// This warning is generated anywhere where a member annotated with
/// `@visibleForTemplate` is used outside of a "template" Dart file.
///
/// Parameters:
@ -6363,7 +6363,7 @@ class WarningCode extends AnalyzerErrorCode {
"The member '{0}' can only be used within '{1}' or a template library.",
);
/// This hint is generated anywhere where a member annotated with
/// This warning is generated anywhere where a member annotated with
/// `@visibleForTesting` is used outside the defining library, or a test.
///
/// Parameters:
@ -6376,8 +6376,8 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// This hint is generated anywhere where a private declaration is annotated
/// with `@visibleForTemplate` or `@visibleForTesting`.
/// This warning is generated anywhere where a private declaration is
/// annotated with `@visibleForTemplate` or `@visibleForTesting`.
///
/// Parameters:
/// 0: the name of the member
@ -6434,8 +6434,8 @@ class WarningCode extends AnalyzerErrorCode {
uniqueName: 'MISSING_OVERRIDE_OF_MUST_BE_OVERRIDDEN_TWO',
);
/// Generate a hint for a constructor, function or method invocation where a
/// required parameter is missing.
/// Generates a warning for a constructor, function or method invocation where
/// a required parameter is missing.
///
/// Parameters:
/// 0: the name of the parameter
@ -6445,8 +6445,8 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// Generate a hint for a constructor, function or method invocation where a
/// required parameter is missing.
/// Generates a warning for a constructor, function or method invocation where
/// a required parameter is missing.
///
/// Parameters:
/// 0: the name of the parameter
@ -6469,7 +6469,7 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// This hint is generated anywhere where a `@sealed` class is used as a
/// This warning is generated anywhere where a `@sealed` class is used as a
/// a superclass constraint of a mixin.
///
/// Parameters:
@ -6485,7 +6485,7 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// Generate a hint for classes that inherit from classes annotated with
/// Generates a warning for classes that inherit from classes annotated with
/// `@immutable` but that are not immutable.
///
/// Parameters:
@ -6507,7 +6507,7 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// Generate a hint for non-const instance creation using a constructor
/// Generates a warning for non-const instance creation using a constructor
/// annotated with `@literal`.
///
/// Parameters:
@ -6520,7 +6520,7 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);
/// Generate a hint for non-const instance creation (with the `new` keyword)
/// Generate a warning for non-const instance creation (with the `new` keyword)
/// using a constructor annotated with `@literal`.
///
/// Parameters:

View file

@ -102,21 +102,21 @@ class DeadCodeVerifier extends RecursiveAstVisitor<void> {
Namespace namespace =
NamespaceBuilder().createExportNamespaceForLibrary(library);
NodeList<SimpleIdentifier> names;
ErrorCode hintCode;
ErrorCode warningCode;
if (combinator is HideCombinator) {
names = combinator.hiddenNames;
hintCode = WarningCode.UNDEFINED_HIDDEN_NAME;
warningCode = WarningCode.UNDEFINED_HIDDEN_NAME;
} else {
names = (combinator as ShowCombinator).shownNames;
hintCode = WarningCode.UNDEFINED_SHOWN_NAME;
warningCode = WarningCode.UNDEFINED_SHOWN_NAME;
}
for (SimpleIdentifier name in names) {
String nameStr = name.name;
Element? element = namespace.get(nameStr);
element ??= namespace.get("$nameStr=");
if (element == null) {
_errorReporter
.reportErrorForNode(hintCode, name, [library.identifier, nameStr]);
_errorReporter.reportErrorForNode(
warningCode, name, [library.identifier, nameStr]);
}
}
}

View file

@ -189,7 +189,7 @@ class GatherUsedImportedElementsVisitor extends RecursiveAstVisitor<void> {
/// otherwise a [HintCode.UNUSED_IMPORT] hint is generated with
/// [generateUnusedImportHints].
///
/// Additionally, [generateDuplicateImportHints] generates
/// Additionally, [generateDuplicateImportWarnings] generates
/// [HintCode.DUPLICATE_IMPORT] hints and [HintCode.UNUSED_SHOWN_NAME] hints.
///
/// While this class does not yet have support for an "Organize Imports" action,
@ -316,9 +316,9 @@ class ImportsVerifier {
/// Any time after the defining compilation unit has been visited by this
/// visitor, this method can be called to report an
/// [StaticWarningCode.DUPLICATE_EXPORT] hint for each of the export
/// [WarningCode.DUPLICATE_EXPORT] hint for each of the export
/// directives in the [_duplicateExports] list.
void generateDuplicateExportHints(ErrorReporter errorReporter) {
void generateDuplicateExportWarnings(ErrorReporter errorReporter) {
var length = _duplicateExports.length;
for (var i = 0; i < length; i++) {
errorReporter.reportErrorForNode(
@ -328,9 +328,9 @@ class ImportsVerifier {
/// Any time after the defining compilation unit has been visited by this
/// visitor, this method can be called to report an
/// [StaticWarningCode.DUPLICATE_IMPORT] hint for each of the import
/// [WarningCode.DUPLICATE_IMPORT] hint for each of the import
/// directives in the [_duplicateImports] list.
void generateDuplicateImportHints(ErrorReporter errorReporter) {
void generateDuplicateImportWarnings(ErrorReporter errorReporter) {
var length = _duplicateImports.length;
for (var i = 0; i < length; i++) {
errorReporter.reportErrorForNode(
@ -338,13 +338,13 @@ class ImportsVerifier {
}
}
/// Report a [StaticWarningCode.DUPLICATE_SHOWN_NAME] and
/// [StaticWarningCode.DUPLICATE_HIDDEN_NAME] hints for each duplicate shown
/// or hidden name.
/// Report a [WarningCode.DUPLICATE_SHOWN_NAME] and
/// [WarningCode.DUPLICATE_HIDDEN_NAME] hints for each duplicate shown or
/// hidden name.
///
/// Only call this method after all of the compilation units have been visited
/// by this visitor.
void generateDuplicateShownHiddenNameHints(ErrorReporter reporter) {
void generateDuplicateShownHiddenNameWarnings(ErrorReporter reporter) {
_duplicateHiddenNamesMap.forEach(
(NamespaceDirective directive, List<SimpleIdentifier> identifiers) {
int length = identifiers.length;

View file

@ -22328,8 +22328,8 @@ WarningCode:
INVALID_FACTORY_ANNOTATION:
problemMessage: Only methods can be annotated as factories.
comment: |-
This hint is generated anywhere a @factory annotation is associated with
anything other than a method.
This warning is generated anywhere a @factory annotation is associated
with anything other than a method.
INVALID_FACTORY_METHOD_DECL:
problemMessage: "Factory method '{0}' must have a return type."
comment: |-
@ -22421,8 +22421,8 @@ WarningCode:
INVALID_IMMUTABLE_ANNOTATION:
problemMessage: Only classes can be annotated as being immutable.
comment: |-
This hint is generated anywhere an @immutable annotation is associated with
anything other than a class.
This warning is generated anywhere an @immutable annotation is associated
with anything other than a class.
INVALID_INTERNAL_ANNOTATION:
problemMessage: "Only public elements in a package's private API can be annotated as being internal."
comment: |-
@ -22631,7 +22631,7 @@ WarningCode:
correctionMessage: Try removing '@nonVirtual'.
hasPublishedDocs: true
comment: |-
This hint is generated anywhere where `@nonVirtual` annotates something
This warning is generated anywhere where `@nonVirtual` annotates something
other than a non-abstract instance member in a class or mixin.
No Parameters.
@ -22711,7 +22711,7 @@ WarningCode:
problemMessage: "The member '{0}' is declared non-virtual in '{1}' and can't be overridden in subclasses."
hasPublishedDocs: true
comment: |-
This hint is generated anywhere where an instance member annotated with
This warning is generated anywhere where an instance member annotated with
`@nonVirtual` is overridden in a subclass.
Parameters:
@ -22777,7 +22777,7 @@ WarningCode:
problemMessage: "The type parameter '{0}' is annotated with @required but only named parameters without a default value can be annotated with it."
correctionMessage: Remove @required.
comment: |-
This hint is generated anywhere where `@required` annotates a named
This warning is generated anywhere where `@required` annotates a named
parameter with a default value.
Parameters:
@ -22786,7 +22786,7 @@ WarningCode:
problemMessage: "Incorrect use of the annotation @required on the optional positional parameter '{0}'. Optional positional parameters cannot be required."
correctionMessage: Remove @required.
comment: |-
This hint is generated anywhere where `@required` annotates an optional
This warning is generated anywhere where `@required` annotates an optional
positional parameter.
Parameters:
@ -22795,8 +22795,8 @@ WarningCode:
problemMessage: "Redundant use of the annotation @required on the required positional parameter '{0}'."
correctionMessage: Remove @required.
comment: |-
This hint is generated anywhere where `@required` annotates a non optional
positional parameter.
This warning is generated anywhere where `@required` annotates a
non-optional positional parameter.
Parameters:
0: the name of the member
@ -22841,8 +22841,8 @@ WarningCode:
INVALID_USE_OF_PROTECTED_MEMBER:
problemMessage: "The member '{0}' can only be used within instance members of subclasses of '{1}'."
comment: |-
This hint is generated anywhere where a member annotated with `@protected`
is used outside of an instance member of a subclass.
This warning is generated anywhere where a member annotated with
`@protected` is used outside of an instance member of a subclass.
Parameters:
0: the name of the member
@ -22895,7 +22895,7 @@ WarningCode:
INVALID_USE_OF_VISIBLE_FOR_TEMPLATE_MEMBER:
problemMessage: "The member '{0}' can only be used within '{1}' or a template library."
comment: |-
This hint is generated anywhere where a member annotated with
This warning is generated anywhere where a member annotated with
`@visibleForTemplate` is used outside of a "template" Dart file.
Parameters:
@ -22905,7 +22905,7 @@ WarningCode:
problemMessage: "The member '{0}' can only be used within '{1}' or a test."
hasPublishedDocs: true
comment: |-
This hint is generated anywhere where a member annotated with
This warning is generated anywhere where a member annotated with
`@visibleForTesting` is used outside the defining library, or a test.
Parameters:
@ -22967,8 +22967,8 @@ WarningCode:
problemMessage: "The member '{0}' is annotated with '{1}', but this annotation is only meaningful on declarations of public members."
hasPublishedDocs: true
comment: |-
This hint is generated anywhere where a private declaration is annotated
with `@visibleForTemplate` or `@visibleForTesting`.
This warning is generated anywhere where a private declaration is
annotated with `@visibleForTemplate` or `@visibleForTesting`.
Parameters:
0: the name of the member
@ -23117,8 +23117,8 @@ WarningCode:
correctionMessage: Try removing the '@sealed' annotation.
hasPublishedDocs: true
comment: |-
This hint is generated anywhere where `@sealed` annotates something other
than a class.
This warning is generated anywhere where `@sealed` annotates something
other than a class.
No parameters.
documentation: |-
@ -23233,8 +23233,8 @@ WarningCode:
problemMessage: "The parameter '{0}' is required."
hasPublishedDocs: true
comment: |-
Generate a hint for a constructor, function or method invocation where a
required parameter is missing.
Generates a warning for a constructor, function or method invocation where
a required parameter is missing.
Parameters:
0: the name of the parameter
@ -23280,8 +23280,8 @@ WarningCode:
problemMessage: "The parameter '{0}' is required. {1}."
hasPublishedDocs: true
comment: |-
Generate a hint for a constructor, function or method invocation where a
required parameter is missing.
Generates a warning for a constructor, function or method invocation where
a required parameter is missing.
Parameters:
0: the name of the parameter
@ -23323,7 +23323,7 @@ WarningCode:
correctionMessage: Try composing with this class, or refer to its documentation for more information.
hasPublishedDocs: true
comment: |-
This hint is generated anywhere where a `@sealed` class is used as a
This warning is generated anywhere where a `@sealed` class is used as a
a superclass constraint of a mixin.
Parameters:
@ -23366,7 +23366,7 @@ WarningCode:
problemMessage: "This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: {0}"
hasPublishedDocs: true
comment: |-
Generate a hint for classes that inherit from classes annotated with
Generates a warning for classes that inherit from classes annotated with
`@immutable` but that are not immutable.
Parameters:
@ -23479,7 +23479,7 @@ WarningCode:
correctionMessage: "Try replacing the 'new' keyword with 'const'."
hasPublishedDocs: true
comment: |-
Generate a hint for non-const instance creation (with the `new` keyword)
Generate a warning for non-const instance creation (with the `new` keyword)
using a constructor annotated with `@literal`.
Parameters:
@ -23489,7 +23489,7 @@ WarningCode:
correctionMessage: "Try adding a 'const' keyword."
hasPublishedDocs: true
comment: |-
Generate a hint for non-const instance creation using a constructor
Generates a warning for non-const instance creation using a constructor
annotated with `@literal`.
Parameters: