[analyzer] Move 6 more Hints to be Warnings, INVALID_*
Bug: https://github.com/dart-lang/sdk/issues/50796
Change-Id: Ic46261738fbbd5d0e78a60b520283ea38a28b22b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280063
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
index 6d4e242..0b7d35f 100644
--- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
+++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
@@ -1410,29 +1410,6 @@
status: noFix
HintCode.INFERENCE_FAILURE_ON_UNTYPED_PARAMETER:
status: noFix
-HintCode.INVALID_ANNOTATION_TARGET:
- status: hasFix
-HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT:
- status: needsFix
- notes: |-
- Low priority, because this is likely not encountered often.
-
- The fix is to update the export directive so that the name is no longer
- exported.
-HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY:
- status: needsFix
- notes: |-
- Low priority, because this is likely not encountered often and the only fix
- is not likely to be the most common fix.
-
- The fix is to update the export directive so that the member using the name
- is no longer exported.
-HintCode.INVALID_FACTORY_ANNOTATION:
- status: hasFix
-HintCode.INVALID_FACTORY_METHOD_DECL:
- status: noFix
-HintCode.INVALID_FACTORY_METHOD_IMPL:
- status: noFix
HintCode.INVALID_IMMUTABLE_ANNOTATION:
status: hasFix
HintCode.INVALID_INTERNAL_ANNOTATION:
@@ -2766,6 +2743,29 @@
status: noFix
notes: |-
Fix depends on user's intent, which can't be known.
+WarningCode.INVALID_ANNOTATION_TARGET:
+ status: hasFix
+WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT:
+ status: needsFix
+ notes: |-
+ Low priority, because this is likely not encountered often.
+
+ The fix is to update the export directive so that the name is no longer
+ exported.
+WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY:
+ status: needsFix
+ notes: |-
+ Low priority, because this is likely not encountered often and the only fix
+ is not likely to be the most common fix.
+
+ The fix is to update the export directive so that the member using the name
+ is no longer exported.
+WarningCode.INVALID_FACTORY_ANNOTATION:
+ status: hasFix
+WarningCode.INVALID_FACTORY_METHOD_DECL:
+ status: noFix
+WarningCode.INVALID_FACTORY_METHOD_IMPL:
+ status: noFix
WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE:
status: hasFix
WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT:
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index add363628..5acca6d 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -1351,12 +1351,6 @@
],
// TODO(brianwilkerson) Add a fix to convert the path to a package: import.
// HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE: [],
- HintCode.INVALID_ANNOTATION_TARGET: [
- RemoveAnnotation.new,
- ],
- HintCode.INVALID_FACTORY_ANNOTATION: [
- RemoveAnnotation.new,
- ],
HintCode.INVALID_IMMUTABLE_ANNOTATION: [
RemoveAnnotation.new,
],
@@ -1557,6 +1551,12 @@
WarningCode.DUPLICATE_SHOWN_NAME: [
RemoveNameFromCombinator.new,
],
+ WarningCode.INVALID_ANNOTATION_TARGET: [
+ RemoveAnnotation.new,
+ ],
+ WarningCode.INVALID_FACTORY_ANNOTATION: [
+ RemoveAnnotation.new,
+ ],
WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT: [
UpdateSdkConstraints.version_2_2_2,
],
diff --git a/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart b/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart
index e005786..80d3748 100644
--- a/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart
+++ b/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart
@@ -306,59 +306,6 @@
correctionMessage: "Try specifying the type of the parameter.",
);
- /// Parameters:
- /// 0: the name of the annotation
- /// 1: the list of valid targets
- static const HintCode INVALID_ANNOTATION_TARGET = HintCode(
- 'INVALID_ANNOTATION_TARGET',
- "The annotation '{0}' can only be used on {1}.",
- hasPublishedDocs: true,
- );
-
- /// Parameters:
- /// 0: the name of the element
- static const HintCode INVALID_EXPORT_OF_INTERNAL_ELEMENT = HintCode(
- 'INVALID_EXPORT_OF_INTERNAL_ELEMENT',
- "The member '{0}' can't be exported as a part of a package's public API.",
- correctionMessage: "Try using a hide clause to hide '{0}'.",
- hasPublishedDocs: true,
- );
-
- /// Parameters:
- /// 0: the name of the element
- /// 1: ?
- static const HintCode INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY =
- HintCode(
- 'INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY',
- "The member '{0}' can't be exported as a part of a package's public API, "
- "but is indirectly exported as part of the signature of '{1}'.",
- correctionMessage: "Try using a hide clause to hide '{0}'.",
- hasPublishedDocs: true,
- );
-
- /// This hint is generated anywhere a @factory annotation is associated with
- /// anything other than a method.
- static const HintCode INVALID_FACTORY_ANNOTATION = HintCode(
- 'INVALID_FACTORY_ANNOTATION',
- "Only methods can be annotated as factories.",
- );
-
- /// Parameters:
- /// 0: The name of the method
- static const HintCode INVALID_FACTORY_METHOD_DECL = HintCode(
- 'INVALID_FACTORY_METHOD_DECL',
- "Factory method '{0}' must have a return type.",
- hasPublishedDocs: true,
- );
-
- /// Parameters:
- /// 0: the name of the method
- static const HintCode INVALID_FACTORY_METHOD_IMPL = HintCode(
- 'INVALID_FACTORY_METHOD_IMPL',
- "Factory method '{0}' doesn't return a newly allocated object.",
- hasPublishedDocs: true,
- );
-
/// This hint is generated anywhere an @immutable annotation is associated with
/// anything other than a class.
static const HintCode INVALID_IMMUTABLE_ANNOTATION = HintCode(
diff --git a/pkg/analyzer/lib/src/error/best_practices_verifier.dart b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
index 7e468b3..d0ce1bf 100644
--- a/pkg/analyzer/lib/src/error/best_practices_verifier.dart
+++ b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
@@ -144,8 +144,8 @@
if (parent is MethodDeclaration) {
_checkForInvalidFactory(parent);
} else {
- _errorReporter
- .reportErrorForNode(HintCode.INVALID_FACTORY_ANNOTATION, node, []);
+ _errorReporter.reportErrorForNode(
+ WarningCode.INVALID_FACTORY_ANNOTATION, node, []);
}
} else if (element.isImmutable) {
if (parent is! ClassDeclaration &&
@@ -196,7 +196,7 @@
parent.parent is ExtensionDeclaration ||
parent.parent is EnumDeclaration) {
_errorReporter.reportErrorForNode(
- HintCode.INVALID_ANNOTATION_TARGET,
+ WarningCode.INVALID_ANNOTATION_TARGET,
node,
[node.name.name, 'instance members of classes and mixins'],
);
@@ -207,7 +207,7 @@
parent.parent is ExtensionDeclaration ||
parent.parent is EnumDeclaration) {
_errorReporter.reportErrorForNode(
- HintCode.INVALID_ANNOTATION_TARGET,
+ WarningCode.INVALID_ANNOTATION_TARGET,
node,
[node.name.name, 'instance members of classes and mixins'],
);
@@ -337,8 +337,8 @@
var validKinds = kindNames.commaSeparatedWithOr;
// Annotations always refer to named elements, so we can safely assume
// that `name` is non-`null`.
- _errorReporter.reportErrorForNode(
- HintCode.INVALID_ANNOTATION_TARGET, node.name, [name!, validKinds]);
+ _errorReporter.reportErrorForNode(WarningCode.INVALID_ANNOTATION_TARGET,
+ node.name, [name!, validKinds]);
return;
}
}
@@ -1107,7 +1107,7 @@
if (libraryElement == null) return;
if (libraryElement.hasInternal) {
_errorReporter.reportErrorForNode(
- HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
+ WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
node,
[libraryElement.displayName]);
}
@@ -1116,7 +1116,7 @@
exportNamespace.definedNames.forEach((String name, Element element) {
if (element.hasInternal) {
_errorReporter.reportErrorForNode(
- HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
+ WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
node,
[element.displayName]);
} else if (element is FunctionElement) {
@@ -1129,7 +1129,7 @@
var aliasElement = type?.alias?.element;
if (aliasElement != null && aliasElement.hasInternal) {
_errorReporter.reportErrorForNode(
- HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY,
+ WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY,
node,
[aliasElement.name, element.displayName]);
}
@@ -1144,7 +1144,9 @@
var returnType = decl.returnType?.type;
if (returnType is VoidType) {
_errorReporter.reportErrorForToken(
- HintCode.INVALID_FACTORY_METHOD_DECL, decl.name, [decl.name.lexeme]);
+ WarningCode.INVALID_FACTORY_METHOD_DECL,
+ decl.name,
+ [decl.name.lexeme]);
return;
}
@@ -1173,7 +1175,7 @@
}
_errorReporter.reportErrorForToken(
- HintCode.INVALID_FACTORY_METHOD_IMPL, decl.name, [decl.name.lexeme]);
+ WarningCode.INVALID_FACTORY_METHOD_IMPL, decl.name, [decl.name.lexeme]);
}
void _checkForInvalidSealedSuperclass(NamedCompilationUnitMember node) {
diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart
index fe12053..b92be44 100644
--- a/pkg/analyzer/lib/src/error/codes.g.dart
+++ b/pkg/analyzer/lib/src/error/codes.g.dart
@@ -5754,6 +5754,59 @@
hasPublishedDocs: true,
);
+ /// Parameters:
+ /// 0: the name of the annotation
+ /// 1: the list of valid targets
+ static const WarningCode INVALID_ANNOTATION_TARGET = WarningCode(
+ 'INVALID_ANNOTATION_TARGET',
+ "The annotation '{0}' can only be used on {1}.",
+ hasPublishedDocs: true,
+ );
+
+ /// Parameters:
+ /// 0: the name of the element
+ static const WarningCode INVALID_EXPORT_OF_INTERNAL_ELEMENT = WarningCode(
+ 'INVALID_EXPORT_OF_INTERNAL_ELEMENT',
+ "The member '{0}' can't be exported as a part of a package's public API.",
+ correctionMessage: "Try using a hide clause to hide '{0}'.",
+ hasPublishedDocs: true,
+ );
+
+ /// Parameters:
+ /// 0: the name of the element
+ /// 1: ?
+ static const WarningCode INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY =
+ WarningCode(
+ 'INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY',
+ "The member '{0}' can't be exported as a part of a package's public API, "
+ "but is indirectly exported as part of the signature of '{1}'.",
+ correctionMessage: "Try using a hide clause to hide '{0}'.",
+ hasPublishedDocs: true,
+ );
+
+ /// This hint 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.",
+ );
+
+ /// Parameters:
+ /// 0: The name of the method
+ static const WarningCode INVALID_FACTORY_METHOD_DECL = WarningCode(
+ 'INVALID_FACTORY_METHOD_DECL',
+ "Factory method '{0}' must have a return type.",
+ hasPublishedDocs: true,
+ );
+
+ /// Parameters:
+ /// 0: the name of the method
+ static const WarningCode INVALID_FACTORY_METHOD_IMPL = WarningCode(
+ 'INVALID_FACTORY_METHOD_IMPL',
+ "Factory method '{0}' doesn't return a newly allocated object.",
+ hasPublishedDocs: true,
+ );
+
/// This is the new replacement for [HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR].
static const HintCode NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR =
HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR;
diff --git a/pkg/analyzer/lib/src/error/error_code_values.g.dart b/pkg/analyzer/lib/src/error/error_code_values.g.dart
index 9179526..719d4d7 100644
--- a/pkg/analyzer/lib/src/error/error_code_values.g.dart
+++ b/pkg/analyzer/lib/src/error/error_code_values.g.dart
@@ -595,12 +595,6 @@
HintCode.INFERENCE_FAILURE_ON_INSTANCE_CREATION,
HintCode.INFERENCE_FAILURE_ON_UNINITIALIZED_VARIABLE,
HintCode.INFERENCE_FAILURE_ON_UNTYPED_PARAMETER,
- HintCode.INVALID_ANNOTATION_TARGET,
- HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
- HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY,
- HintCode.INVALID_FACTORY_ANNOTATION,
- HintCode.INVALID_FACTORY_METHOD_DECL,
- HintCode.INVALID_FACTORY_METHOD_IMPL,
HintCode.INVALID_IMMUTABLE_ANNOTATION,
HintCode.INVALID_INTERNAL_ANNOTATION,
HintCode.INVALID_LANGUAGE_VERSION_OVERRIDE_AT_SIGN,
@@ -974,6 +968,12 @@
WarningCode.DUPLICATE_SHOWN_NAME,
WarningCode.EQUAL_ELEMENTS_IN_SET,
WarningCode.EQUAL_KEYS_IN_MAP,
+ WarningCode.INVALID_ANNOTATION_TARGET,
+ WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
+ WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY,
+ WarningCode.INVALID_FACTORY_ANNOTATION,
+ WarningCode.INVALID_FACTORY_METHOD_DECL,
+ WarningCode.INVALID_FACTORY_METHOD_IMPL,
WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE,
WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT,
WarningCode.SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT,
diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml
index da64794..4371a78 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -18352,216 +18352,6 @@
Parameters:
0: the name of the parameter
- INVALID_ANNOTATION_TARGET:
- problemMessage: "The annotation '{0}' can only be used on {1}."
- comment: |-
- Parameters:
- 0: the name of the annotation
- 1: the list of valid targets
- hasPublishedDocs: true
- documentation: |-
- #### Description
-
- The analyzer produces this diagnostic when an annotation is applied to a
- kind of declaration that it doesn't support.
-
- #### Example
-
- The following code produces this diagnostic because the `optionalTypeArgs`
- annotation isn't defined to be valid for top-level variables:
-
- ```dart
- import 'package:meta/meta.dart';
-
- @[!optionalTypeArgs!]
- int x = 0;
- ```
-
- #### Common fixes
-
- Remove the annotation from the declaration.
- INVALID_EXPORT_OF_INTERNAL_ELEMENT:
- problemMessage: "The member '{0}' can't be exported as a part of a package's public API."
- correctionMessage: "Try using a hide clause to hide '{0}'."
- comment: |-
- Parameters:
- 0: the name of the element
- hasPublishedDocs: true
- documentation: |-
- #### Description
-
- The analyzer produces this diagnostic when a [public library][] exports a
- declaration that is marked with the `[internal][meta-internal]`
- annotation.
-
- #### Example
-
- Given a file named `a.dart` in the `src` directory that contains:
-
- ```dart
- %uri="lib/src/a.dart"
- import 'package:meta/meta.dart';
-
- @internal class One {}
- ```
-
- The following code, when found in a [public library][] produces this
- diagnostic because the `export` directive is exporting a name that is only
- intended to be used internally:
-
- ```dart
- [!export 'src/a.dart';!]
- ```
-
- #### Common fixes
-
- If the export is needed, then add a `hide` clause to hide the internal
- names:
-
- ```dart
- export 'src/a.dart' hide One;
- ```
-
- If the export isn't needed, then remove it.
- INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY:
- problemMessage: "The member '{0}' can't be exported as a part of a package's public API, but is indirectly exported as part of the signature of '{1}'."
- correctionMessage: "Try using a hide clause to hide '{0}'."
- comment: |-
- Parameters:
- 0: the name of the element
- 1: ?
- hasPublishedDocs: true
- documentation: |-
- #### Description
-
- The analyzer produces this diagnostic when a [public library][] exports a
- top-level function with a return type or at least one parameter type that
- is marked with the `[internal][meta-internal]` annotation.
-
- #### Example
-
- Given a file named `a.dart` in the `src` directory that contains the
- following:
-
- ```dart
- %uri="lib/src/a.dart"
- import 'package:meta/meta.dart';
-
- @internal
- typedef IntFunction = int Function();
-
- int f(IntFunction g) => g();
- ```
-
- The following code produces this diagnostic because the function `f` has a
- parameter of type `IntFunction`, and `IntFunction` is only intended to be
- used internally:
-
- ```dart
- [!export 'src/a.dart' show f;!]
- ```
-
- #### Common fixes
-
- If the function must be public, then make all the types in the function's
- signature public types.
-
- If the function doesn't need to be exported, then stop exporting it,
- either by removing it from the `show` clause, adding it to the `hide`
- clause, or by removing the export.
- 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.
- INVALID_FACTORY_METHOD_DECL:
- problemMessage: "Factory method '{0}' must have a return type."
- comment: |-
- Parameters:
- 0: The name of the method
- hasPublishedDocs: true
- documentation: |-
- #### Description
-
- The analyzer produces this diagnostic when a method that is annotated with
- the `[factory][meta-factory]` annotation has a return type of `void`.
-
- #### Example
-
- The following code produces this diagnostic because the method `createC`
- is annotated with the `[factory][meta-factory]` annotation but doesn't
- return any value:
-
- ```dart
- import 'package:meta/meta.dart';
-
- class Factory {
- @factory
- void [!createC!]() {}
- }
-
- class C {}
- ```
-
- #### Common fixes
-
- Change the return type to something other than `void`:
-
- ```dart
- import 'package:meta/meta.dart';
-
- class Factory {
- @factory
- C createC() => C();
- }
-
- class C {}
- ```
- INVALID_FACTORY_METHOD_IMPL:
- problemMessage: "Factory method '{0}' doesn't return a newly allocated object."
- comment: |-
- Parameters:
- 0: the name of the method
- hasPublishedDocs: true
- documentation: |-
- #### Description
-
- The analyzer produces this diagnostic when a method that is annotated with
- the `[factory][meta-factory]` annotation doesn't return a newly allocated
- object.
-
- #### Example
-
- The following code produces this diagnostic because the method `createC`
- returns the value of a field rather than a newly created instance of `C`:
-
- ```dart
- import 'package:meta/meta.dart';
-
- class Factory {
- C c = C();
-
- @factory
- C [!createC!]() => c;
- }
-
- class C {}
- ```
-
- #### Common fixes
-
- Change the method to return a newly created instance of the return type:
-
- ```dart
- import 'package:meta/meta.dart';
-
- class Factory {
- @factory
- C createC() => C();
- }
-
- class C {}
- ```
INVALID_IMMUTABLE_ANNOTATION:
problemMessage: Only classes can be annotated as being immutable.
comment: |-
@@ -22758,6 +22548,216 @@
Note that literal maps preserve the order of their entries, so the choice
of which entry to remove might affect the order in which the keys and
values are returned by an iterator.
+ INVALID_ANNOTATION_TARGET:
+ problemMessage: "The annotation '{0}' can only be used on {1}."
+ comment: |-
+ Parameters:
+ 0: the name of the annotation
+ 1: the list of valid targets
+ hasPublishedDocs: true
+ documentation: |-
+ #### Description
+
+ The analyzer produces this diagnostic when an annotation is applied to a
+ kind of declaration that it doesn't support.
+
+ #### Example
+
+ The following code produces this diagnostic because the `optionalTypeArgs`
+ annotation isn't defined to be valid for top-level variables:
+
+ ```dart
+ import 'package:meta/meta.dart';
+
+ @[!optionalTypeArgs!]
+ int x = 0;
+ ```
+
+ #### Common fixes
+
+ Remove the annotation from the declaration.
+ INVALID_EXPORT_OF_INTERNAL_ELEMENT:
+ problemMessage: "The member '{0}' can't be exported as a part of a package's public API."
+ correctionMessage: "Try using a hide clause to hide '{0}'."
+ comment: |-
+ Parameters:
+ 0: the name of the element
+ hasPublishedDocs: true
+ documentation: |-
+ #### Description
+
+ The analyzer produces this diagnostic when a [public library][] exports a
+ declaration that is marked with the `[internal][meta-internal]`
+ annotation.
+
+ #### Example
+
+ Given a file named `a.dart` in the `src` directory that contains:
+
+ ```dart
+ %uri="lib/src/a.dart"
+ import 'package:meta/meta.dart';
+
+ @internal class One {}
+ ```
+
+ The following code, when found in a [public library][] produces this
+ diagnostic because the `export` directive is exporting a name that is only
+ intended to be used internally:
+
+ ```dart
+ [!export 'src/a.dart';!]
+ ```
+
+ #### Common fixes
+
+ If the export is needed, then add a `hide` clause to hide the internal
+ names:
+
+ ```dart
+ export 'src/a.dart' hide One;
+ ```
+
+ If the export isn't needed, then remove it.
+ INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY:
+ problemMessage: "The member '{0}' can't be exported as a part of a package's public API, but is indirectly exported as part of the signature of '{1}'."
+ correctionMessage: "Try using a hide clause to hide '{0}'."
+ comment: |-
+ Parameters:
+ 0: the name of the element
+ 1: ?
+ hasPublishedDocs: true
+ documentation: |-
+ #### Description
+
+ The analyzer produces this diagnostic when a [public library][] exports a
+ top-level function with a return type or at least one parameter type that
+ is marked with the `[internal][meta-internal]` annotation.
+
+ #### Example
+
+ Given a file named `a.dart` in the `src` directory that contains the
+ following:
+
+ ```dart
+ %uri="lib/src/a.dart"
+ import 'package:meta/meta.dart';
+
+ @internal
+ typedef IntFunction = int Function();
+
+ int f(IntFunction g) => g();
+ ```
+
+ The following code produces this diagnostic because the function `f` has a
+ parameter of type `IntFunction`, and `IntFunction` is only intended to be
+ used internally:
+
+ ```dart
+ [!export 'src/a.dart' show f;!]
+ ```
+
+ #### Common fixes
+
+ If the function must be public, then make all the types in the function's
+ signature public types.
+
+ If the function doesn't need to be exported, then stop exporting it,
+ either by removing it from the `show` clause, adding it to the `hide`
+ clause, or by removing the export.
+ 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.
+ INVALID_FACTORY_METHOD_DECL:
+ problemMessage: "Factory method '{0}' must have a return type."
+ comment: |-
+ Parameters:
+ 0: The name of the method
+ hasPublishedDocs: true
+ documentation: |-
+ #### Description
+
+ The analyzer produces this diagnostic when a method that is annotated with
+ the `[factory][meta-factory]` annotation has a return type of `void`.
+
+ #### Example
+
+ The following code produces this diagnostic because the method `createC`
+ is annotated with the `[factory][meta-factory]` annotation but doesn't
+ return any value:
+
+ ```dart
+ import 'package:meta/meta.dart';
+
+ class Factory {
+ @factory
+ void [!createC!]() {}
+ }
+
+ class C {}
+ ```
+
+ #### Common fixes
+
+ Change the return type to something other than `void`:
+
+ ```dart
+ import 'package:meta/meta.dart';
+
+ class Factory {
+ @factory
+ C createC() => C();
+ }
+
+ class C {}
+ ```
+ INVALID_FACTORY_METHOD_IMPL:
+ problemMessage: "Factory method '{0}' doesn't return a newly allocated object."
+ comment: |-
+ Parameters:
+ 0: the name of the method
+ hasPublishedDocs: true
+ documentation: |-
+ #### Description
+
+ The analyzer produces this diagnostic when a method that is annotated with
+ the `[factory][meta-factory]` annotation doesn't return a newly allocated
+ object.
+
+ #### Example
+
+ The following code produces this diagnostic because the method `createC`
+ returns the value of a field rather than a newly created instance of `C`:
+
+ ```dart
+ import 'package:meta/meta.dart';
+
+ class Factory {
+ C c = C();
+
+ @factory
+ C [!createC!]() => c;
+ }
+
+ class C {}
+ ```
+
+ #### Common fixes
+
+ Change the method to return a newly created instance of the return type:
+
+ ```dart
+ import 'package:meta/meta.dart';
+
+ class Factory {
+ @factory
+ C createC() => C();
+ }
+
+ class C {}
+ ```
NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR:
aliasFor: HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR
comment: This is the new replacement for [HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR].
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_annotation_target_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_annotation_target_test.dart
index 9923146..7fe155c 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_annotation_target_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_annotation_target_test.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import 'package:analyzer/src/dart/error/hint_codes.dart';
+import 'package:analyzer/src/error/codes.g.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/context_collection_resolution.dart';
@@ -76,7 +76,7 @@
static int f = 0;
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 45, 17),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 45, 17),
]);
}
@@ -88,7 +88,7 @@
static int get f => 0;
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 45, 17),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 45, 17),
]);
}
@@ -100,7 +100,7 @@
static void m() {}
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 45, 17),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 45, 17),
]);
}
@@ -112,7 +112,7 @@
static void set f(int value) {}
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 45, 17),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 45, 17),
]);
}
@@ -125,7 +125,7 @@
C();
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 47, 16),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 47, 16),
]);
}
@@ -139,7 +139,7 @@
void m() {}
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 57, 17),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 57, 17),
]);
}
@@ -152,7 +152,7 @@
void m() {}
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 60, 17),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 60, 17),
]);
}
@@ -174,7 +174,7 @@
@mustBeOverridden
void m() {}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 35, 16),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 35, 16),
]);
}
}
@@ -240,7 +240,7 @@
static int f = 0;
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 45, 14),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 45, 14),
]);
}
@@ -252,7 +252,7 @@
static int get f => 0;
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 45, 14),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 45, 14),
]);
}
@@ -264,7 +264,7 @@
static void m() {}
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 45, 14),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 45, 14),
]);
}
@@ -276,7 +276,7 @@
static void set f(int value) {}
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 45, 14),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 45, 14),
]);
}
@@ -289,7 +289,7 @@
C();
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 47, 13),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 47, 13),
]);
}
@@ -303,7 +303,7 @@
void m() {}
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 57, 14),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 57, 14),
]);
}
@@ -316,7 +316,7 @@
void m() {}
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 60, 14),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 60, 14),
]);
}
@@ -338,7 +338,7 @@
@mustCallSuper
void m() {}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 35, 13),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 35, 13),
]);
}
}
@@ -375,7 +375,7 @@
@A()
mixin M {}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 98, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 98, 1),
]);
}
@@ -392,7 +392,7 @@
@A()
int x = 0;
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 98, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 98, 1),
]);
}
@@ -411,7 +411,7 @@
@a
int x = 0;
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 114, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 114, 1),
]);
}
@@ -428,7 +428,7 @@
@A()
class C {}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 97, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 97, 1),
]);
}
@@ -460,7 +460,7 @@
@A()
class C {}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 98, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 98, 1),
]);
}
@@ -527,7 +527,7 @@
int M(int x) => 0;
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 109, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 109, 1),
]);
}
@@ -544,7 +544,7 @@
@A()
int get x => 0;
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 97, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 97, 1),
]);
}
@@ -561,7 +561,7 @@
@A()
set x(_x) {}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 97, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 97, 1),
]);
}
@@ -597,7 +597,7 @@
int m(int x) => x;
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 107, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 107, 1),
]);
}
@@ -616,7 +616,7 @@
set x(int _x) {}
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 107, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 107, 1),
]);
}
@@ -648,7 +648,7 @@
@A()
class C {}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 96, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 96, 1),
]);
}
@@ -695,7 +695,7 @@
int get x => 0;
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 107, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 107, 1),
]);
}
@@ -748,7 +748,7 @@
set x(int _x) {}
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 107, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 107, 1),
]);
}
@@ -765,7 +765,7 @@
@A()
int f(int x) => x;
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 95, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 95, 1),
]);
}
@@ -782,7 +782,7 @@
@A()
class C {}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 98, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 98, 1),
]);
}
@@ -814,7 +814,7 @@
@A()
int x = 0;
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 117, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 117, 1),
]);
}
@@ -849,7 +849,7 @@
@A()
void f(int x) {}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 98, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 98, 1),
]);
}
@@ -882,7 +882,7 @@
int get x => 0;
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 107, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 107, 1),
]);
}
@@ -901,7 +901,7 @@
int m(int x) => x;
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 107, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 107, 1),
]);
}
@@ -952,7 +952,7 @@
int f = 0;
}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 117, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 117, 1),
]);
}
@@ -1015,7 +1015,7 @@
extension on C {}
class C {}
''', [
- error(HintCode.INVALID_ANNOTATION_TARGET, 93, 1),
+ error(WarningCode.INVALID_ANNOTATION_TARGET, 93, 1),
]);
}
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_export_of_internal_element_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_export_of_internal_element_test.dart
index fd0deac..894bd2e 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_export_of_internal_element_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_export_of_internal_element_test.dart
@@ -51,7 +51,7 @@
''');
assertErrorsInResult([
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
]);
}
@@ -79,7 +79,7 @@
''');
assertErrorsInResult([
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
]);
}
@@ -107,7 +107,7 @@
''');
assertErrorsInResult([
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
]);
}
@@ -146,7 +146,7 @@
await assertErrorsInCode(r'''
export 'package:dart.my/src/foo.dart';
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 38),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 38),
]);
}
@@ -159,7 +159,7 @@
await assertErrorsInCode(r'''
export 'package:dart.my/src/foo.dart';
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 38),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 38),
]);
}
@@ -172,7 +172,7 @@
await assertErrorsInCode(r'''
export 'package:dart.my/src/foo.dart';
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 38),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 38),
]);
}
}
@@ -198,7 +198,7 @@
''');
assertErrorsInResult([
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 35),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 35),
]);
}
@@ -230,7 +230,7 @@
''');
assertErrorsInResult([
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 35),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 35),
]);
}
@@ -256,7 +256,7 @@
await assertErrorsInCode(r'''
export 'package:test/src/foo.dart';
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 35),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 35),
]);
}
@@ -270,7 +270,7 @@
await assertErrorsInCode(r'''
export 'package:test/src/foo.dart';
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 35),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 35),
]);
}
}
@@ -299,7 +299,7 @@
''');
assertErrorsInResult([
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
]);
}
@@ -338,7 +338,7 @@
await assertErrorsInCode(r'''
export 'package:test/src/foo.dart';
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 35),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 35),
]);
}
}
@@ -371,7 +371,7 @@
await assertErrorsInCode(r'''
export 'src/foo.dart' hide Two;
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 31),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 31),
]);
}
@@ -385,7 +385,7 @@
await assertErrorsInCode(r'''
export 'src/foo.dart' show func;
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY, 0, 32),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY, 0, 32),
]);
}
@@ -399,7 +399,7 @@
await assertErrorsInCode(r'''
export 'src/foo.dart' show func;
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY, 0, 32),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY, 0, 32),
]);
}
@@ -413,7 +413,7 @@
await assertErrorsInCode(r'''
export 'src/foo.dart' show func;
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY, 0, 32),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY, 0, 32),
]);
}
@@ -427,7 +427,7 @@
await assertErrorsInCode(r'''
export 'src/foo.dart' show func;
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY, 0, 32),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY, 0, 32),
]);
}
@@ -441,7 +441,7 @@
await assertErrorsInCode(r'''
export 'src/foo.dart' show func;
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY, 0, 32),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY, 0, 32),
]);
}
@@ -466,7 +466,7 @@
await assertErrorsInCode(r'''
export 'src/foo.dart';
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
]);
}
@@ -483,7 +483,7 @@
await assertErrorsInCode(r'''
export 'src/foo.dart';
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
]);
}
@@ -498,7 +498,7 @@
await assertErrorsInCode(r'''
export 'src/foo.dart';
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 22),
]);
}
@@ -544,7 +544,7 @@
await assertErrorsInCode(r'''
export 'src/foo.dart' show One;
''', [
- error(HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 31),
+ error(WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT, 0, 31),
]);
}
}
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_factory_annotation_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_factory_annotation_test.dart
index ee79483..cdddf1f 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_factory_annotation_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_factory_annotation_test.dart
@@ -28,7 +28,7 @@
class X {
}
''', [
- error(HintCode.INVALID_FACTORY_ANNOTATION, 33, 8),
+ error(WarningCode.INVALID_FACTORY_ANNOTATION, 33, 8),
]);
}
@@ -40,7 +40,7 @@
int x = 0;
}
''', [
- error(HintCode.INVALID_FACTORY_ANNOTATION, 45, 8),
+ error(WarningCode.INVALID_FACTORY_ANNOTATION, 45, 8),
]);
}
@@ -50,7 +50,7 @@
@factory
main() { }
''', [
- error(HintCode.INVALID_FACTORY_ANNOTATION, 33, 8),
+ error(WarningCode.INVALID_FACTORY_ANNOTATION, 33, 8),
]);
}
}
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_factory_method_impl_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_factory_method_impl_test.dart
index 347e1da..f781ccd 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_factory_method_impl_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_factory_method_impl_test.dart
@@ -43,7 +43,7 @@
}
class State { }
''', [
- error(HintCode.INVALID_FACTORY_METHOD_IMPL, 96, 11),
+ error(WarningCode.INVALID_FACTORY_METHOD_IMPL, 96, 11),
]);
}
@@ -136,7 +136,7 @@
void createState() {}
}
''', [
- error(HintCode.INVALID_FACTORY_METHOD_DECL, 69, 11),
+ error(WarningCode.INVALID_FACTORY_METHOD_DECL, 69, 11),
]);
}
}