Skip to content

Commit

Permalink
[analyzer] Mark latest lint and diagnostic docs as published
Browse files Browse the repository at this point in the history
Also fixes a few minor typos.

Change-Id: I026bb91682440aa851f05f998c4c67c3d1a7a56e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403540
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Phil Quitslund <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
Auto-Submit: Parker Lougheed <[email protected]>
  • Loading branch information
parlough authored and Commit Queue committed Jan 8, 2025
1 parent 525afed commit fec029f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 14 deletions.
2 changes: 2 additions & 0 deletions pkg/analyzer/lib/src/dart/error/ffi_code.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,15 @@ class FfiCode extends ErrorCode {
correctionMessage:
"Try adding a type parameter extending `NativeType` to the `@Native` "
"annotation.",
hasPublishedDocs: true,
);

/// No parameters.
static const FfiCode NEGATIVE_VARIABLE_DIMENSION = FfiCode(
'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:
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer/lib/src/error/codes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions pkg/analyzer/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/tool/diagnostics/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions pkg/linter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions pkg/linter/lib/src/lint_codes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 =
Expand Down
8 changes: 4 additions & 4 deletions pkg/linter/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -13295,7 +13295,7 @@ LintCode:
state:
experimental: "3.7"
categories: [errorProne]
hasPublishedDocs: false
hasPublishedDocs: true
documentation: |-
#### Description
Expand Down
29 changes: 28 additions & 1 deletion pkg/linter/tool/machine/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <int, bool>{}.\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: <int>[] }, 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<int>(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<String, Widget?> myTopLevelVariable =\n genericFunctionWrittenByOtherFolks(with, args);\n\nclass A {\n static Map<String, Widget?> 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 <int, bool>{}.\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: <int>[] }, 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<int>(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<String, Widget?> myTopLevelVariable =\n genericFunctionWrittenByOtherFolks(with, args);\n\nclass A {\n static Map<String, Widget?> 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"
},
{
Expand Down Expand Up @@ -2889,6 +2902,20 @@
"details": "Unnecessary `toList()` in spreads.\n\n**BAD:**\n```dart\nchildren: <Widget>[\n ...['foo', 'bar', 'baz'].map((String s) => Text(s)).toList(),\n]\n```\n\n**GOOD:**\n```dart\nchildren: <Widget>[\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.",
Expand Down

0 comments on commit fec029f

Please sign in to comment.