diff --git a/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart b/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart index fce374ce3243..83468c9966fb 100644 --- a/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart +++ b/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart @@ -395,6 +395,7 @@ class FfiCode extends ErrorCode { correctionMessage: "Try adding a type parameter extending `NativeType` to the `@Native` " "annotation.", + hasPublishedDocs: true, ); /// No parameters. @@ -402,6 +403,7 @@ class FfiCode extends ErrorCode { 'NEGATIVE_VARIABLE_DIMENSION', "The variable dimension of a variable-length array must be non-negative.", correctionMessage: "Try using a value that is zero or greater.", + hasPublishedDocs: true, ); /// Parameters: diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart index 762617ae7c8d..1d66933cfd73 100644 --- a/pkg/analyzer/lib/src/error/codes.g.dart +++ b/pkg/analyzer/lib/src/error/codes.g.dart @@ -743,7 +743,7 @@ class CompileTimeErrorCode extends ErrorCode { "'{0}' can't be used to name both a type parameter and the extension in " "which the type parameter is defined.", correctionMessage: - "Try renaming either the type variaparameterble or the extension.", + "Try renaming either the type parameter or the extension.", hasPublishedDocs: true, uniqueName: 'CONFLICTING_TYPE_VARIABLE_AND_EXTENSION', ); @@ -7643,6 +7643,7 @@ class WarningCode extends ErrorCode { 'UNUSED_ELEMENT_PARAMETER', "A value for optional parameter '{0}' isn't ever given.", correctionMessage: "Try removing the unused parameter.", + hasPublishedDocs: true, ); /// Parameters: diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml index 66e6a80069a9..6a549710726c 100644 --- a/pkg/analyzer/messages.yaml +++ b/pkg/analyzer/messages.yaml @@ -2391,7 +2391,7 @@ CompileTimeErrorCode: CONFLICTING_TYPE_VARIABLE_AND_EXTENSION: sharedName: CONFLICTING_TYPE_VARIABLE_AND_CONTAINER problemMessage: "'{0}' can't be used to name both a type parameter and the extension in which the type parameter is defined." - correctionMessage: Try renaming either the type variaparameterble or the extension. + correctionMessage: Try renaming either the type parameter or the extension. hasPublishedDocs: true comment: |- Parameters: @@ -19215,7 +19215,7 @@ FfiCode: NATIVE_FUNCTION_MISSING_TYPE: problemMessage: The native type of this function couldn't be inferred so it must be specified in the annotation. correctionMessage: Try adding a type parameter extending `NativeType` to the `@Native` annotation. - hasPublishedDocs: false + hasPublishedDocs: true comment: No parameters documentation: |- #### Description @@ -20452,7 +20452,7 @@ FfiCode: NEGATIVE_VARIABLE_DIMENSION: problemMessage: The variable dimension of a variable-length array must be non-negative. correctionMessage: Try using a value that is zero or greater. - hasPublishedDocs: false + hasPublishedDocs: true comment: No parameters. documentation: |- #### Description @@ -27529,7 +27529,7 @@ WarningCode: UNUSED_ELEMENT_PARAMETER: problemMessage: "A value for optional parameter '{0}' isn't ever given." correctionMessage: Try removing the unused parameter. - hasPublishedDocs: false + hasPublishedDocs: true comment: |- Parameters: 0: the name of the parameter that is declared but not used diff --git a/pkg/analyzer/tool/diagnostics/diagnostics.md b/pkg/analyzer/tool/diagnostics/diagnostics.md index 67a5ebce4b55..f868a2d46468 100644 --- a/pkg/analyzer/tool/diagnostics/diagnostics.md +++ b/pkg/analyzer/tool/diagnostics/diagnostics.md @@ -29218,7 +29218,7 @@ _Unnecessary use of multiple underscores._ #### Description The analyzer produces this diagnostic when an unused variable is named -with mutiple underscores (for example `__`). A single `_` wildcard variable +with multiple underscores (for example `__`). A single `_` wildcard variable can be used instead. #### Example diff --git a/pkg/linter/CHANGELOG.md b/pkg/linter/CHANGELOG.md index 7a3f8e59bc82..c6db35bda2c4 100644 --- a/pkg/linter/CHANGELOG.md +++ b/pkg/linter/CHANGELOG.md @@ -1,12 +1,13 @@ # 3.7.0-wip - new lint: `unnecessary_underscores` -- removed lint: `package_api_docs` -- removed lint: `unsafe_html` -- _(soon to be)_ deprecated lint: `avoid_null_checks_in_equality_operators` +- new lint: `strict_top_level_inference` - new _(experimental)_ lint: `omit_obvious_property_types` - new _(experimental)_ lint: `specify_nonobvious_property_types` - new _(experimental)_ lint: `unsafe_variance` +- removed lint: `package_api_docs` +- removed lint: `unsafe_html` +- _(soon to be)_ deprecated lint: `avoid_null_checks_in_equality_operators` # 3.6.0 diff --git a/pkg/linter/lib/src/lint_codes.g.dart b/pkg/linter/lib/src/lint_codes.g.dart index 65272ddc508c..9be22956108d 100644 --- a/pkg/linter/lib/src/lint_codes.g.dart +++ b/pkg/linter/lib/src/lint_codes.g.dart @@ -1761,6 +1761,7 @@ class LinterLintCode extends LintCode { LintNames.unnecessary_underscores, "Unnecessary use of multiple underscores.", correctionMessage: "Try using '_'.", + hasPublishedDocs: true, ); static const LintCode unreachable_from_main = LinterLintCode( @@ -1795,6 +1796,7 @@ class LinterLintCode extends LintCode { correctionMessage: "Try using a more general type that doesn't contain any type " "parameters in such a position.", + hasPublishedDocs: true, ); static const LintCode use_build_context_synchronously_async_use = diff --git a/pkg/linter/messages.yaml b/pkg/linter/messages.yaml index c112fbaa995e..c25219863fe3 100644 --- a/pkg/linter/messages.yaml +++ b/pkg/linter/messages.yaml @@ -10837,7 +10837,7 @@ LintCode: type argument, but not C(14) if C accepts one or more type arguments. - e is a cascade whose target has an obvious type. For instance, 1..isEven..isEven has an obvious type because 1 has an obvious type. - - e is a type cast. For instance, myComplexpression as int. + - e is a type cast. For instance, `myComplexExpression as int`. **BAD:** ```dart @@ -13011,12 +13011,12 @@ LintCode: state: experimental: "3.7" categories: [brevity, style] - hasPublishedDocs: false + hasPublishedDocs: true documentation: |- #### Description The analyzer produces this diagnostic when an unused variable is named - with mutiple underscores (for example `__`). A single `_` wildcard variable + with multiple underscores (for example `__`). A single `_` wildcard variable can be used instead. #### Example @@ -13295,7 +13295,7 @@ LintCode: state: experimental: "3.7" categories: [errorProne] - hasPublishedDocs: false + hasPublishedDocs: true documentation: |- #### Description diff --git a/pkg/linter/tool/machine/rules.json b/pkg/linter/tool/machine/rules.json index f6c99ca30d57..b84502f028f7 100644 --- a/pkg/linter/tool/machine/rules.json +++ b/pkg/linter/tool/machine/rules.json @@ -2420,7 +2420,20 @@ "incompatible": [], "sets": [], "fixStatus": "hasFix", - "details": "Do type annotate initialized top-level or static variables when the type is\nnon-obvious.\n\nType annotations on top-level or static variables can serve as a request for\ntype inference, documenting the expected outcome of the type inference step,\nand declaratively allowing the compiler and analyzer to solve the possibly\ncomplex task of finding type arguments and annotations in the initializing\nexpression that yield the desired result.\n\nType annotations on top-level or static variables can also inform readers about\nthe type of the initializing expression, which will allow them to proceed\nreading the locations in code where this variable is used with known good\ninformation about the type of the given variable (which may not be immediately\nevident by looking at the initializing expression).\n\nAn expression is considered to have a non-obvious type when it does not\nhave an obvious type.\n\nAn expression e has an obvious type in the following cases:\n\n- e is a non-collection literal. For instance, 1, true, 'Hello, $name!'.\n- e is a collection literal with actual type arguments. For instance,\n {}.\n- e is a list literal or a set literal where at least one element has an\n obvious type, and all elements have the same type. For instance, [1, 2] and\n { [true, false], [] }, but not [1, 1.5].\n- e is a map literal where all key-value pair have a key with an obvious type\n and a value with an obvious type, and all keys have the same type, and all\n values have the same type. For instance, { #a: [] }, but not\n {1: 1, 2: true}.\n- e is an instance creation expression whose class part is not raw. For\n instance C(14) if C is a non-generic class, or C(14) if C accepts one\n type argument, but not C(14) if C accepts one or more type arguments.\n- e is a cascade whose target has an obvious type. For instance,\n 1..isEven..isEven has an obvious type because 1 has an obvious type.\n- e is a type cast. For instance, myComplexpression as int.\n\n**BAD:**\n```dart\nfinal myTopLevelVariable =\n genericFunctionWrittenByOtherFolks(with, args);\n\nclass A {\n static var myStaticVariable =\n myTopLevelVariable.update('foo', null);\n}\n```\n\n**GOOD:**\n```dart\nfinal Map myTopLevelVariable =\n genericFunctionWrittenByOtherFolks(with, args);\n\nclass A {\n static Map myStaticVariable =\n myTopLevelVariable.update('foo', null);\n}\n```\n\n**This rule is experimental.** It is being evaluated, and it may be changed\nor removed. Feedback on its behavior is welcome! The main issue is here:\nhttps://github.com/dart-lang/linter/issues/5101.", + "details": "Do type annotate initialized top-level or static variables when the type is\nnon-obvious.\n\nType annotations on top-level or static variables can serve as a request for\ntype inference, documenting the expected outcome of the type inference step,\nand declaratively allowing the compiler and analyzer to solve the possibly\ncomplex task of finding type arguments and annotations in the initializing\nexpression that yield the desired result.\n\nType annotations on top-level or static variables can also inform readers about\nthe type of the initializing expression, which will allow them to proceed\nreading the locations in code where this variable is used with known good\ninformation about the type of the given variable (which may not be immediately\nevident by looking at the initializing expression).\n\nAn expression is considered to have a non-obvious type when it does not\nhave an obvious type.\n\nAn expression e has an obvious type in the following cases:\n\n- e is a non-collection literal. For instance, 1, true, 'Hello, $name!'.\n- e is a collection literal with actual type arguments. For instance,\n {}.\n- e is a list literal or a set literal where at least one element has an\n obvious type, and all elements have the same type. For instance, [1, 2] and\n { [true, false], [] }, but not [1, 1.5].\n- e is a map literal where all key-value pair have a key with an obvious type\n and a value with an obvious type, and all keys have the same type, and all\n values have the same type. For instance, { #a: [] }, but not\n {1: 1, 2: true}.\n- e is an instance creation expression whose class part is not raw. For\n instance C(14) if C is a non-generic class, or C(14) if C accepts one\n type argument, but not C(14) if C accepts one or more type arguments.\n- e is a cascade whose target has an obvious type. For instance,\n 1..isEven..isEven has an obvious type because 1 has an obvious type.\n- e is a type cast. For instance, `myComplexExpression as int`.\n\n**BAD:**\n```dart\nfinal myTopLevelVariable =\n genericFunctionWrittenByOtherFolks(with, args);\n\nclass A {\n static var myStaticVariable =\n myTopLevelVariable.update('foo', null);\n}\n```\n\n**GOOD:**\n```dart\nfinal Map myTopLevelVariable =\n genericFunctionWrittenByOtherFolks(with, args);\n\nclass A {\n static Map myStaticVariable =\n myTopLevelVariable.update('foo', null);\n}\n```\n\n**This rule is experimental.** It is being evaluated, and it may be changed\nor removed. Feedback on its behavior is welcome! The main issue is here:\nhttps://github.com/dart-lang/linter/issues/5101.", + "sinceDartSdk": "3.7" + }, + { + "name": "strict_top_level_inference", + "description": "Specify type annotations.", + "categories": [ + "style" + ], + "state": "stable", + "incompatible": [], + "sets": [], + "fixStatus": "hasFix", + "details": "Do type annotate top-level and class-like member declarations, where types\nare not inferred from super-interfaces or initializers.\n\nThe lint warns about every omitted return type, parameter type, and\nvariable type of a top-level declaration or class-like-namespace-level\ndeclaration (static or instance member or constructor declaration), which\nis not given a type by inference, and which therefore defaults to dynamic.\n\nThe only omitted types that can be given a type by top-level inference,\nare those of variable declarations with initializer expressions, and\nreturn and parameter types of instance members that override a consistent\ncombined super-interface signature.\n\nSetters do not need a return type, as it is always assumed to be `void`.\n\n**BAD:**\n```dart\nvar _zeroPointCache;\nclass Point {\n get zero => ...;\n final x, y;\n Point(x, y) {}\n closest(b, c) => distance(b) <= distance(c) ? b : c;\n distance(other) => ...;\n}\n_sq(v) => v * v;\n```\n\n**GOOD:**\n```dart\nPoint? _zeroPointCache;\nclass Point {\n Point get zero => ...;\n final int x, y;\n Point(int x, int y) {}\n closest(Point b, Point c) =>\n distance(b) <= distance(c) ? b : c;\n distance(Point other) => ...;\n}\nint _sq(int v) => v * v;\n```", "sinceDartSdk": "3.7" }, { @@ -2889,6 +2902,20 @@ "details": "Unnecessary `toList()` in spreads.\n\n**BAD:**\n```dart\nchildren: [\n ...['foo', 'bar', 'baz'].map((String s) => Text(s)).toList(),\n]\n```\n\n**GOOD:**\n```dart\nchildren: [\n ...['foo', 'bar', 'baz'].map((String s) => Text(s)),\n]\n```", "sinceDartSdk": "2.18" }, + { + "name": "unnecessary_underscores", + "description": "Unnecessary underscores can be removed.", + "categories": [ + "brevity", + "style" + ], + "state": "stable", + "incompatible": [], + "sets": [], + "fixStatus": "hasFix", + "details": "**AVOID** using multiple underscores when a single wildcard will do.\n\n**BAD:**\n```dart\nvoid function(int __) { }\n```\n\n**GOOD:**\n```dart\nvoid function(int _) { }\n```", + "sinceDartSdk": "3.7" + }, { "name": "unreachable_from_main", "description": "Unreachable top-level members in executable libraries.",