Skip to content

Commit

Permalink
Revert "[analyzer] Move 6 more HintCodes to be WarningCodes, STRICT_*…
Browse files Browse the repository at this point in the history
…, SUBTYPE_*, UNDEFINED_*, UNNECESSARY_*"

This reverts commit 86278e3.

Reason for revert: This is breaking flutter customer tests. See flutter/flutter#120992

Original change's description:
> [analyzer] Move 6 more HintCodes to be WarningCodes, STRICT_*, SUBTYPE_*, UNDEFINED_*, UNNECESSARY_*
>
> Bug: #50796
> Change-Id: Ic65b01d19984874c442722de472b21701f85ee5d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283400
> Commit-Queue: Samuel Rawlins <[email protected]>
> Reviewed-by: Konstantin Shcheglov <[email protected]>

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: #50796
Change-Id: Ia2eaba6ebbbad13fe31b783b39c02b1adce322b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283923
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Jackson Gardner <[email protected]>
Reviewed-by: Jackson Gardner <[email protected]>
  • Loading branch information
eyebrowsoffire authored and Commit Queue committed Feb 17, 2023
1 parent 9ec898a commit d90a06b
Show file tree
Hide file tree
Showing 14 changed files with 344 additions and 345 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/source/source_range.dart';
import 'package:analyzer/src/dart/error/hint_codes.dart';
import 'package:analyzer/src/error/codes.g.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';
Expand Down Expand Up @@ -41,15 +40,15 @@ class RemoveComparison extends CorrectionProducer {
/// Return `true` if the condition will always return `false`.
bool get _conditionIsFalse {
var errorCode = (diagnostic as AnalysisError).errorCode;
return errorCode == WarningCode.UNNECESSARY_NAN_COMPARISON_FALSE ||
return errorCode == HintCode.UNNECESSARY_NAN_COMPARISON_FALSE ||
errorCode == HintCode.UNNECESSARY_NULL_COMPARISON_FALSE ||
errorCode == HintCode.UNNECESSARY_TYPE_CHECK_FALSE;
}

/// Return `true` if the condition will always return `true`.
bool get _conditionIsTrue {
var errorCode = (diagnostic as AnalysisError).errorCode;
return errorCode == WarningCode.UNNECESSARY_NAN_COMPARISON_TRUE ||
return errorCode == HintCode.UNNECESSARY_NAN_COMPARISON_TRUE ||
errorCode == HintCode.UNNECESSARY_NULL_COMPARISON_TRUE ||
errorCode == HintCode.UNNECESSARY_TYPE_CHECK_TRUE ||
errorCode.name == LintNames.avoid_null_checks_in_equality_operators;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,24 @@ HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD:
status: hasFix
HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER:
status: hasFix
HintCode.STRICT_RAW_TYPE:
status: needsFix
notes: |-
One fix would be to add an explicit `<dynamic>`, but we can also provide
more helpful fixes that pretend inference works the way the user may
have thought it did. For example in: `List a = <int>[];`, we can add
`<int>` after `List`.
HintCode.SUBTYPE_OF_SEALED_CLASS:
status: needsFix
notes: |-
`sealed` annotation is likely to be replaced by the `sealed` keyword
in the next stable release.
Remove the sealed class in the `extends` or `implements` clause.
Use RemoveNameFromDeclarationClause.
HintCode.UNDEFINED_REFERENCED_PARAMETER:
status: needsFix
notes: |-
Can try to find the correct parameter name.
HintCode.UNIGNORABLE_IGNORE:
status: needsFix
notes: |-
Expand All @@ -1466,6 +1484,18 @@ HintCode.UNNECESSARY_IGNORE:
Remove the ignore comment (or one code in the comment).
HintCode.UNNECESSARY_IMPORT:
status: hasFix
HintCode.UNNECESSARY_NAN_COMPARISON_FALSE:
status: hasFix
notes: |-
Add another fix to remove the comparison.
HintCode.UNNECESSARY_NAN_COMPARISON_TRUE:
status: hasFix
notes: |-
Add another fix to remove the comparison.
HintCode.UNNECESSARY_NO_SUCH_METHOD:
status: needsFix
notes: |-
Remove the noSuchMethod implementation.
HintCode.UNNECESSARY_NULL_COMPARISON_FALSE:
status: hasFix
HintCode.UNNECESSARY_NULL_COMPARISON_TRUE:
Expand Down Expand Up @@ -2805,20 +2835,6 @@ WarningCode.SDK_VERSION_UI_AS_CODE:
WarningCode.SDK_VERSION_UI_AS_CODE_IN_CONST_CONTEXT:
status: noFix
notes: Deprecated
WarningCode.STRICT_RAW_TYPE:
status: needsFix
notes: |-
One fix would be to add an explicit `<dynamic>`, but we can also provide
more helpful fixes that pretend inference works the way the user may
have thought it did. For example in: `List a = <int>[];`, we can add
`<int>` after `List`.
WarningCode.SUBTYPE_OF_SEALED_CLASS:
status: needsFix
notes: |-
`sealed` annotation is likely to be replaced by the `sealed` keyword
in the next stable release.
Remove the sealed class in the `extends` or `implements` clause.
Use RemoveNameFromDeclarationClause.
WarningCode.TEXT_DIRECTION_CODE_POINT_IN_COMMENT:
status: hasFix
WarningCode.TEXT_DIRECTION_CODE_POINT_IN_LITERAL:
Expand All @@ -2829,26 +2845,10 @@ WarningCode.TYPE_CHECK_IS_NULL:
status: hasFix
WarningCode.UNDEFINED_HIDDEN_NAME:
status: hasFix
WarningCode.UNDEFINED_REFERENCED_PARAMETER:
status: needsFix
notes: |-
Can try to find the correct parameter name.
WarningCode.UNDEFINED_SHOWN_NAME:
status: hasFix
WarningCode.UNNECESSARY_CAST_PATTERN:
status: needsEvaluation
WarningCode.UNNECESSARY_NAN_COMPARISON_FALSE:
status: hasFix
notes: |-
Add another fix to remove the comparison.
WarningCode.UNNECESSARY_NAN_COMPARISON_TRUE:
status: hasFix
notes: |-
Add another fix to remove the comparison.
WarningCode.UNNECESSARY_NO_SUCH_METHOD:
status: needsFix
notes: |-
Remove the noSuchMethod implementation.
WarningCode.UNNECESSARY_WILDCARD_PATTERN:
status: needsEvaluation
WarningCode.UNUSED_CATCH_CLAUSE:
Expand Down
19 changes: 11 additions & 8 deletions pkg/analysis_server/lib/src/services/correction/fix_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,17 @@ class FixProcessor extends BaseProcessor {
HintCode.UNNECESSARY_IMPORT: [
RemoveUnusedImport.new,
],
// HintCode.UNNECESSARY_NO_SUCH_METHOD: [
// TODO(brianwilkerson) Add a fix to remove the method.
// ],
HintCode.UNNECESSARY_NAN_COMPARISON_FALSE: [
RemoveComparison.new,
ReplaceWithIsNan.new,
],
HintCode.UNNECESSARY_NAN_COMPARISON_TRUE: [
RemoveComparison.new,
ReplaceWithIsNan.new,
],
HintCode.UNNECESSARY_NULL_COMPARISON_FALSE: [
RemoveComparison.new,
],
Expand Down Expand Up @@ -1612,14 +1623,6 @@ class FixProcessor extends BaseProcessor {
WarningCode.UNDEFINED_SHOWN_NAME: [
RemoveNameFromCombinator.new,
],
WarningCode.UNNECESSARY_NAN_COMPARISON_FALSE: [
RemoveComparison.new,
ReplaceWithIsNan.new,
],
WarningCode.UNNECESSARY_NAN_COMPARISON_TRUE: [
RemoveComparison.new,
ReplaceWithIsNan.new,
],
WarningCode.UNUSED_CATCH_CLAUSE: [
RemoveUnusedCatchClause.new,
],
Expand Down
58 changes: 58 additions & 0 deletions pkg/analyzer/lib/src/dart/error/hint_codes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,40 @@ class HintCode extends AnalyzerErrorCode {
uniqueName: 'OVERRIDE_ON_NON_OVERRIDING_SETTER',
);

/// When "strict-raw-types" is enabled, "raw types" must have type arguments.
///
/// A "raw type" is a type name that does not use inference to fill in missing
/// type arguments; instead, each type argument is instantiated to its bound.
///
/// Parameters:
/// 0: the name of the generic type
static const HintCode STRICT_RAW_TYPE = HintCode(
'STRICT_RAW_TYPE',
"The generic type '{0}' should have explicit type arguments but doesn't.",
correctionMessage: "Use explicit type arguments for '{0}'.",
);

/// Parameters:
/// 0: the name of the sealed class
static const HintCode SUBTYPE_OF_SEALED_CLASS = HintCode(
'SUBTYPE_OF_SEALED_CLASS',
"The class '{0}' shouldn't be extended, mixed in, or implemented because "
"it's sealed.",
correctionMessage:
"Try composing instead of inheriting, or refer to the documentation of "
"'{0}' for more information.",
hasPublishedDocs: true,
);

/// Parameters:
/// 0: the name of the undefined parameter
/// 1: the name of the targeted member
static const HintCode UNDEFINED_REFERENCED_PARAMETER = HintCode(
'UNDEFINED_REFERENCED_PARAMETER',
"The parameter '{0}' isn't defined by '{1}'.",
hasPublishedDocs: true,
);

/// Parameters:
/// 0: the name of the non-diagnostic being ignored
static const HintCode UNIGNORABLE_IGNORE = HintCode(
Expand Down Expand Up @@ -357,6 +391,30 @@ class HintCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);

/// No parameters.
static const HintCode UNNECESSARY_NAN_COMPARISON_FALSE = HintCode(
'UNNECESSARY_NAN_COMPARISON',
"A double can't equal 'double.nan', so the condition is always 'false'.",
correctionMessage: "Try using 'double.isNan', or removing the condition.",
uniqueName: 'UNNECESSARY_NAN_COMPARISON_FALSE',
);

/// No parameters.
static const HintCode UNNECESSARY_NAN_COMPARISON_TRUE = HintCode(
'UNNECESSARY_NAN_COMPARISON',
"A double can't equal 'double.nan', so the condition is always 'true'.",
correctionMessage: "Try using 'double.isNan', or removing the condition.",
uniqueName: 'UNNECESSARY_NAN_COMPARISON_TRUE',
);

/// No parameters.
static const HintCode UNNECESSARY_NO_SUCH_METHOD = HintCode(
'UNNECESSARY_NO_SUCH_METHOD',
"Unnecessary 'noSuchMethod' declaration.",
correctionMessage: "Try removing the declaration of 'noSuchMethod'.",
hasPublishedDocs: true,
);

/// No parameters.
static const HintCode UNNECESSARY_NULL_COMPARISON_FALSE = HintCode(
'UNNECESSARY_NULL_COMPARISON',
Expand Down
21 changes: 9 additions & 12 deletions pkg/analyzer/lib/src/error/best_practices_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/ast/extensions.dart';
Expand Down Expand Up @@ -313,7 +312,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
? undefinedParam.value
: undefinedParam.staticParameterElement?.name;
_errorReporter.reportErrorForNode(
WarningCode.UNDEFINED_REFERENCED_PARAMETER,
HintCode.UNDEFINED_REFERENCED_PARAMETER,
undefinedParam,
[paramName ?? undefinedParam, name]);
}
Expand Down Expand Up @@ -1205,10 +1204,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
node, [superclass.name.toString()]);
} else {
// This is a regular violation of the sealed class contract.
_errorReporter.reportErrorForNode(
WarningCode.SUBTYPE_OF_SEALED_CLASS,
node,
[superclass.name.toString()]);
_errorReporter.reportErrorForNode(HintCode.SUBTYPE_OF_SEALED_CLASS,
node, [superclass.name.toString()]);
}
}
}
Expand All @@ -1217,7 +1214,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {

void _checkForInvariantNanComparison(BinaryExpression node) {
void reportStartEnd(
ErrorCode errorCode,
HintCode errorCode,
SyntacticEntity startEntity,
SyntacticEntity endEntity,
) {
Expand All @@ -1234,7 +1231,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
expression.prefix.name == 'double' &&
expression.identifier.name == 'nan';

void checkLeftRight(ErrorCode errorCode) {
void checkLeftRight(HintCode errorCode) {
if (isDoubleNan(node.leftOperand)) {
reportStartEnd(errorCode, node.leftOperand, node.operator);
} else if (isDoubleNan(node.rightOperand)) {
Expand All @@ -1243,9 +1240,9 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
}

if (node.operator.type == TokenType.BANG_EQ) {
checkLeftRight(WarningCode.UNNECESSARY_NAN_COMPARISON_TRUE);
checkLeftRight(HintCode.UNNECESSARY_NAN_COMPARISON_TRUE);
} else if (node.operator.type == TokenType.EQ_EQ) {
checkLeftRight(WarningCode.UNNECESSARY_NAN_COMPARISON_FALSE);
checkLeftRight(HintCode.UNNECESSARY_NAN_COMPARISON_FALSE);
}
}

Expand Down Expand Up @@ -1542,7 +1539,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
if (body is ExpressionFunctionBody) {
if (isNonObjectNoSuchMethodInvocation(body.expression)) {
_errorReporter.reportErrorForToken(
WarningCode.UNNECESSARY_NO_SUCH_METHOD, node.name);
HintCode.UNNECESSARY_NO_SUCH_METHOD, node.name);
return true;
}
} else if (body is BlockFunctionBody) {
Expand All @@ -1552,7 +1549,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
if (returnStatement is ReturnStatement &&
isNonObjectNoSuchMethodInvocation(returnStatement.expression)) {
_errorReporter.reportErrorForToken(
WarningCode.UNNECESSARY_NO_SUCH_METHOD, node.name);
HintCode.UNNECESSARY_NO_SUCH_METHOD, node.name);
return true;
}
}
Expand Down
58 changes: 0 additions & 58 deletions pkg/analyzer/lib/src/error/codes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6613,31 +6613,6 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);

/// When "strict-raw-types" is enabled, "raw types" must have type arguments.
///
/// A "raw type" is a type name that does not use inference to fill in missing
/// type arguments; instead, each type argument is instantiated to its bound.
///
/// Parameters:
/// 0: the name of the generic type
static const WarningCode STRICT_RAW_TYPE = WarningCode(
'STRICT_RAW_TYPE',
"The generic type '{0}' should have explicit type arguments but doesn't.",
correctionMessage: "Use explicit type arguments for '{0}'.",
);

/// Parameters:
/// 0: the name of the sealed class
static const WarningCode SUBTYPE_OF_SEALED_CLASS = WarningCode(
'SUBTYPE_OF_SEALED_CLASS',
"The class '{0}' shouldn't be extended, mixed in, or implemented because "
"it's sealed.",
correctionMessage:
"Try composing instead of inheriting, or refer to the documentation of "
"'{0}' for more information.",
hasPublishedDocs: true,
);

/// Parameters:
/// 0: the unicode sequence of the code point.
static const WarningCode TEXT_DIRECTION_CODE_POINT_IN_COMMENT = WarningCode(
Expand Down Expand Up @@ -6690,15 +6665,6 @@ class WarningCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);

/// Parameters:
/// 0: the name of the undefined parameter
/// 1: the name of the targeted member
static const WarningCode UNDEFINED_REFERENCED_PARAMETER = WarningCode(
'UNDEFINED_REFERENCED_PARAMETER',
"The parameter '{0}' isn't defined by '{1}'.",
hasPublishedDocs: true,
);

/// Parameters:
/// 0: the name of the library being imported
/// 1: the name in the show clause that isn't defined in the library
Expand All @@ -6722,30 +6688,6 @@ class WarningCode extends AnalyzerErrorCode {
/// This is the new replacement for [HintCode.UNNECESSARY_FINAL].
static const HintCode UNNECESSARY_FINAL = HintCode.UNNECESSARY_FINAL;

/// No parameters.
static const WarningCode UNNECESSARY_NAN_COMPARISON_FALSE = WarningCode(
'UNNECESSARY_NAN_COMPARISON',
"A double can't equal 'double.nan', so the condition is always 'false'.",
correctionMessage: "Try using 'double.isNan', or removing the condition.",
uniqueName: 'UNNECESSARY_NAN_COMPARISON_FALSE',
);

/// No parameters.
static const WarningCode UNNECESSARY_NAN_COMPARISON_TRUE = WarningCode(
'UNNECESSARY_NAN_COMPARISON',
"A double can't equal 'double.nan', so the condition is always 'true'.",
correctionMessage: "Try using 'double.isNan', or removing the condition.",
uniqueName: 'UNNECESSARY_NAN_COMPARISON_TRUE',
);

/// No parameters.
static const WarningCode UNNECESSARY_NO_SUCH_METHOD = WarningCode(
'UNNECESSARY_NO_SUCH_METHOD',
"Unnecessary 'noSuchMethod' declaration.",
correctionMessage: "Try removing the declaration of 'noSuchMethod'.",
hasPublishedDocs: true,
);

/// This is the new replacement for [HintCode.UNNECESSARY_TYPE_CHECK_FALSE].
static const HintCode UNNECESSARY_TYPE_CHECK_FALSE =
HintCode.UNNECESSARY_TYPE_CHECK_FALSE;
Expand Down
Loading

0 comments on commit d90a06b

Please sign in to comment.