Skip to content

Commit 0214937

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
[analyzer] Move 6 more Hints to be Warnings, INVALID_*
Bug: #50796 Change-Id: Ic46261738fbbd5d0e78a60b520283ea38a28b22b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280063 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 6cbc89d commit 0214937

File tree

11 files changed

+376
-374
lines changed

11 files changed

+376
-374
lines changed

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,29 +1410,6 @@ HintCode.INFERENCE_FAILURE_ON_UNINITIALIZED_VARIABLE:
14101410
status: noFix
14111411
HintCode.INFERENCE_FAILURE_ON_UNTYPED_PARAMETER:
14121412
status: noFix
1413-
HintCode.INVALID_ANNOTATION_TARGET:
1414-
status: hasFix
1415-
HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT:
1416-
status: needsFix
1417-
notes: |-
1418-
Low priority, because this is likely not encountered often.
1419-
1420-
The fix is to update the export directive so that the name is no longer
1421-
exported.
1422-
HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY:
1423-
status: needsFix
1424-
notes: |-
1425-
Low priority, because this is likely not encountered often and the only fix
1426-
is not likely to be the most common fix.
1427-
1428-
The fix is to update the export directive so that the member using the name
1429-
is no longer exported.
1430-
HintCode.INVALID_FACTORY_ANNOTATION:
1431-
status: hasFix
1432-
HintCode.INVALID_FACTORY_METHOD_DECL:
1433-
status: noFix
1434-
HintCode.INVALID_FACTORY_METHOD_IMPL:
1435-
status: noFix
14361413
HintCode.INVALID_IMMUTABLE_ANNOTATION:
14371414
status: hasFix
14381415
HintCode.INVALID_INTERNAL_ANNOTATION:
@@ -2766,6 +2743,29 @@ WarningCode.EQUAL_KEYS_IN_MAP:
27662743
status: noFix
27672744
notes: |-
27682745
Fix depends on user's intent, which can't be known.
2746+
WarningCode.INVALID_ANNOTATION_TARGET:
2747+
status: hasFix
2748+
WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT:
2749+
status: needsFix
2750+
notes: |-
2751+
Low priority, because this is likely not encountered often.
2752+
2753+
The fix is to update the export directive so that the name is no longer
2754+
exported.
2755+
WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY:
2756+
status: needsFix
2757+
notes: |-
2758+
Low priority, because this is likely not encountered often and the only fix
2759+
is not likely to be the most common fix.
2760+
2761+
The fix is to update the export directive so that the member using the name
2762+
is no longer exported.
2763+
WarningCode.INVALID_FACTORY_ANNOTATION:
2764+
status: hasFix
2765+
WarningCode.INVALID_FACTORY_METHOD_DECL:
2766+
status: noFix
2767+
WarningCode.INVALID_FACTORY_METHOD_IMPL:
2768+
status: noFix
27692769
WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE:
27702770
status: hasFix
27712771
WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT:

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,12 +1351,6 @@ class FixProcessor extends BaseProcessor {
13511351
],
13521352
// TODO(brianwilkerson) Add a fix to convert the path to a package: import.
13531353
// HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE: [],
1354-
HintCode.INVALID_ANNOTATION_TARGET: [
1355-
RemoveAnnotation.new,
1356-
],
1357-
HintCode.INVALID_FACTORY_ANNOTATION: [
1358-
RemoveAnnotation.new,
1359-
],
13601354
HintCode.INVALID_IMMUTABLE_ANNOTATION: [
13611355
RemoveAnnotation.new,
13621356
],
@@ -1557,6 +1551,12 @@ class FixProcessor extends BaseProcessor {
15571551
WarningCode.DUPLICATE_SHOWN_NAME: [
15581552
RemoveNameFromCombinator.new,
15591553
],
1554+
WarningCode.INVALID_ANNOTATION_TARGET: [
1555+
RemoveAnnotation.new,
1556+
],
1557+
WarningCode.INVALID_FACTORY_ANNOTATION: [
1558+
RemoveAnnotation.new,
1559+
],
15601560
WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT: [
15611561
UpdateSdkConstraints.version_2_2_2,
15621562
],

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

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -306,59 +306,6 @@ class HintCode extends AnalyzerErrorCode {
306306
correctionMessage: "Try specifying the type of the parameter.",
307307
);
308308

309-
/// Parameters:
310-
/// 0: the name of the annotation
311-
/// 1: the list of valid targets
312-
static const HintCode INVALID_ANNOTATION_TARGET = HintCode(
313-
'INVALID_ANNOTATION_TARGET',
314-
"The annotation '{0}' can only be used on {1}.",
315-
hasPublishedDocs: true,
316-
);
317-
318-
/// Parameters:
319-
/// 0: the name of the element
320-
static const HintCode INVALID_EXPORT_OF_INTERNAL_ELEMENT = HintCode(
321-
'INVALID_EXPORT_OF_INTERNAL_ELEMENT',
322-
"The member '{0}' can't be exported as a part of a package's public API.",
323-
correctionMessage: "Try using a hide clause to hide '{0}'.",
324-
hasPublishedDocs: true,
325-
);
326-
327-
/// Parameters:
328-
/// 0: the name of the element
329-
/// 1: ?
330-
static const HintCode INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY =
331-
HintCode(
332-
'INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY',
333-
"The member '{0}' can't be exported as a part of a package's public API, "
334-
"but is indirectly exported as part of the signature of '{1}'.",
335-
correctionMessage: "Try using a hide clause to hide '{0}'.",
336-
hasPublishedDocs: true,
337-
);
338-
339-
/// This hint is generated anywhere a @factory annotation is associated with
340-
/// anything other than a method.
341-
static const HintCode INVALID_FACTORY_ANNOTATION = HintCode(
342-
'INVALID_FACTORY_ANNOTATION',
343-
"Only methods can be annotated as factories.",
344-
);
345-
346-
/// Parameters:
347-
/// 0: The name of the method
348-
static const HintCode INVALID_FACTORY_METHOD_DECL = HintCode(
349-
'INVALID_FACTORY_METHOD_DECL',
350-
"Factory method '{0}' must have a return type.",
351-
hasPublishedDocs: true,
352-
);
353-
354-
/// Parameters:
355-
/// 0: the name of the method
356-
static const HintCode INVALID_FACTORY_METHOD_IMPL = HintCode(
357-
'INVALID_FACTORY_METHOD_IMPL',
358-
"Factory method '{0}' doesn't return a newly allocated object.",
359-
hasPublishedDocs: true,
360-
);
361-
362309
/// This hint is generated anywhere an @immutable annotation is associated with
363310
/// anything other than a class.
364311
static const HintCode INVALID_IMMUTABLE_ANNOTATION = HintCode(

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
144144
if (parent is MethodDeclaration) {
145145
_checkForInvalidFactory(parent);
146146
} else {
147-
_errorReporter
148-
.reportErrorForNode(HintCode.INVALID_FACTORY_ANNOTATION, node, []);
147+
_errorReporter.reportErrorForNode(
148+
WarningCode.INVALID_FACTORY_ANNOTATION, node, []);
149149
}
150150
} else if (element.isImmutable) {
151151
if (parent is! ClassDeclaration &&
@@ -196,7 +196,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
196196
parent.parent is ExtensionDeclaration ||
197197
parent.parent is EnumDeclaration) {
198198
_errorReporter.reportErrorForNode(
199-
HintCode.INVALID_ANNOTATION_TARGET,
199+
WarningCode.INVALID_ANNOTATION_TARGET,
200200
node,
201201
[node.name.name, 'instance members of classes and mixins'],
202202
);
@@ -207,7 +207,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
207207
parent.parent is ExtensionDeclaration ||
208208
parent.parent is EnumDeclaration) {
209209
_errorReporter.reportErrorForNode(
210-
HintCode.INVALID_ANNOTATION_TARGET,
210+
WarningCode.INVALID_ANNOTATION_TARGET,
211211
node,
212212
[node.name.name, 'instance members of classes and mixins'],
213213
);
@@ -337,8 +337,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
337337
var validKinds = kindNames.commaSeparatedWithOr;
338338
// Annotations always refer to named elements, so we can safely assume
339339
// that `name` is non-`null`.
340-
_errorReporter.reportErrorForNode(
341-
HintCode.INVALID_ANNOTATION_TARGET, node.name, [name!, validKinds]);
340+
_errorReporter.reportErrorForNode(WarningCode.INVALID_ANNOTATION_TARGET,
341+
node.name, [name!, validKinds]);
342342
return;
343343
}
344344
}
@@ -1107,7 +1107,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
11071107
if (libraryElement == null) return;
11081108
if (libraryElement.hasInternal) {
11091109
_errorReporter.reportErrorForNode(
1110-
HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
1110+
WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
11111111
node,
11121112
[libraryElement.displayName]);
11131113
}
@@ -1116,7 +1116,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
11161116
exportNamespace.definedNames.forEach((String name, Element element) {
11171117
if (element.hasInternal) {
11181118
_errorReporter.reportErrorForNode(
1119-
HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
1119+
WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
11201120
node,
11211121
[element.displayName]);
11221122
} else if (element is FunctionElement) {
@@ -1129,7 +1129,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
11291129
var aliasElement = type?.alias?.element;
11301130
if (aliasElement != null && aliasElement.hasInternal) {
11311131
_errorReporter.reportErrorForNode(
1132-
HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY,
1132+
WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY,
11331133
node,
11341134
[aliasElement.name, element.displayName]);
11351135
}
@@ -1144,7 +1144,9 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
11441144
var returnType = decl.returnType?.type;
11451145
if (returnType is VoidType) {
11461146
_errorReporter.reportErrorForToken(
1147-
HintCode.INVALID_FACTORY_METHOD_DECL, decl.name, [decl.name.lexeme]);
1147+
WarningCode.INVALID_FACTORY_METHOD_DECL,
1148+
decl.name,
1149+
[decl.name.lexeme]);
11481150
return;
11491151
}
11501152

@@ -1173,7 +1175,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
11731175
}
11741176

11751177
_errorReporter.reportErrorForToken(
1176-
HintCode.INVALID_FACTORY_METHOD_IMPL, decl.name, [decl.name.lexeme]);
1178+
WarningCode.INVALID_FACTORY_METHOD_IMPL, decl.name, [decl.name.lexeme]);
11771179
}
11781180

11791181
void _checkForInvalidSealedSuperclass(NamedCompilationUnitMember node) {

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5754,6 +5754,59 @@ class WarningCode extends AnalyzerErrorCode {
57545754
hasPublishedDocs: true,
57555755
);
57565756

5757+
/// Parameters:
5758+
/// 0: the name of the annotation
5759+
/// 1: the list of valid targets
5760+
static const WarningCode INVALID_ANNOTATION_TARGET = WarningCode(
5761+
'INVALID_ANNOTATION_TARGET',
5762+
"The annotation '{0}' can only be used on {1}.",
5763+
hasPublishedDocs: true,
5764+
);
5765+
5766+
/// Parameters:
5767+
/// 0: the name of the element
5768+
static const WarningCode INVALID_EXPORT_OF_INTERNAL_ELEMENT = WarningCode(
5769+
'INVALID_EXPORT_OF_INTERNAL_ELEMENT',
5770+
"The member '{0}' can't be exported as a part of a package's public API.",
5771+
correctionMessage: "Try using a hide clause to hide '{0}'.",
5772+
hasPublishedDocs: true,
5773+
);
5774+
5775+
/// Parameters:
5776+
/// 0: the name of the element
5777+
/// 1: ?
5778+
static const WarningCode INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY =
5779+
WarningCode(
5780+
'INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY',
5781+
"The member '{0}' can't be exported as a part of a package's public API, "
5782+
"but is indirectly exported as part of the signature of '{1}'.",
5783+
correctionMessage: "Try using a hide clause to hide '{0}'.",
5784+
hasPublishedDocs: true,
5785+
);
5786+
5787+
/// This hint is generated anywhere a @factory annotation is associated with
5788+
/// anything other than a method.
5789+
static const WarningCode INVALID_FACTORY_ANNOTATION = WarningCode(
5790+
'INVALID_FACTORY_ANNOTATION',
5791+
"Only methods can be annotated as factories.",
5792+
);
5793+
5794+
/// Parameters:
5795+
/// 0: The name of the method
5796+
static const WarningCode INVALID_FACTORY_METHOD_DECL = WarningCode(
5797+
'INVALID_FACTORY_METHOD_DECL',
5798+
"Factory method '{0}' must have a return type.",
5799+
hasPublishedDocs: true,
5800+
);
5801+
5802+
/// Parameters:
5803+
/// 0: the name of the method
5804+
static const WarningCode INVALID_FACTORY_METHOD_IMPL = WarningCode(
5805+
'INVALID_FACTORY_METHOD_IMPL',
5806+
"Factory method '{0}' doesn't return a newly allocated object.",
5807+
hasPublishedDocs: true,
5808+
);
5809+
57575810
/// This is the new replacement for [HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR].
57585811
static const HintCode NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR =
57595812
HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,6 @@ const List<ErrorCode> errorCodeValues = [
595595
HintCode.INFERENCE_FAILURE_ON_INSTANCE_CREATION,
596596
HintCode.INFERENCE_FAILURE_ON_UNINITIALIZED_VARIABLE,
597597
HintCode.INFERENCE_FAILURE_ON_UNTYPED_PARAMETER,
598-
HintCode.INVALID_ANNOTATION_TARGET,
599-
HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
600-
HintCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY,
601-
HintCode.INVALID_FACTORY_ANNOTATION,
602-
HintCode.INVALID_FACTORY_METHOD_DECL,
603-
HintCode.INVALID_FACTORY_METHOD_IMPL,
604598
HintCode.INVALID_IMMUTABLE_ANNOTATION,
605599
HintCode.INVALID_INTERNAL_ANNOTATION,
606600
HintCode.INVALID_LANGUAGE_VERSION_OVERRIDE_AT_SIGN,
@@ -974,6 +968,12 @@ const List<ErrorCode> errorCodeValues = [
974968
WarningCode.DUPLICATE_SHOWN_NAME,
975969
WarningCode.EQUAL_ELEMENTS_IN_SET,
976970
WarningCode.EQUAL_KEYS_IN_MAP,
971+
WarningCode.INVALID_ANNOTATION_TARGET,
972+
WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
973+
WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY,
974+
WarningCode.INVALID_FACTORY_ANNOTATION,
975+
WarningCode.INVALID_FACTORY_METHOD_DECL,
976+
WarningCode.INVALID_FACTORY_METHOD_IMPL,
977977
WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE,
978978
WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT,
979979
WarningCode.SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT,

0 commit comments

Comments
 (0)