Skip to content

Commit 1b9063c

Browse files
bwilkersondart-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
Enable recommended lints when verifying diagnostic documentation
This enables the remainder of the recommended lints when verifying diagnostic documentation. As before, in most cases this amounted to ignoring additional diagnostics and documenting why I thought that was a reasonable choice. At some point someone should create issues for all of the places where a diagnostic is being reported where it shouldn't be and add the URL of the issue to these files. Change-Id: Iadcad9f13334e3f1702a32273e190a04017796aa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/532000 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Auto-Submit: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
1 parent c6b76d1 commit 1b9063c

3 files changed

Lines changed: 83 additions & 27 deletions

File tree

pkg/analyzer/messages.yaml

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,9 @@ CompileTimeErrorCode:
16831683
parameters: none
16841684
problemMessage: "Functions can't be assigned a value."
16851685
hasPublishedDocs: true
1686+
# In the documentation, the `prefer_function_declarations_over_variables`
1687+
# diagnostic is ignored because fixing it would require adding code that
1688+
# isn't relevant to the point of the fix.
16861689
documentation: |-
16871690
#### Description
16881691

@@ -1708,6 +1711,7 @@ CompileTimeErrorCode:
17081711
local variable, then change the left-hand side:
17091712

17101713
```dart
1714+
%ignore=prefer_function_declarations_over_variables
17111715
void f() {}
17121716

17131717
void g() {
@@ -4585,6 +4589,8 @@ CompileTimeErrorCode:
45854589
correctionMessage: Try correcting the name to match an existing class.
45864590
isUnresolvedIdentifier: true
45874591
hasPublishedDocs: true
4592+
# In the documentation, the `unnecessary_new` diagnostic is ignored because
4593+
# the diagnostic being documented requires using `new`.
45884594
documentation: |-
45894595
#### Description
45904596

@@ -4597,6 +4603,7 @@ CompileTimeErrorCode:
45974603
rather than a class:
45984604

45994605
```dart
4606+
%ignore=unnecessary_new
46004607
int f() => 0;
46014608

46024609
void g() {
@@ -4610,6 +4617,7 @@ CompileTimeErrorCode:
46104617
of a valid class:
46114618

46124619
```dart
4620+
%ignore=unnecessary_new
46134621
int f() => 0;
46144622

46154623
void g() {
@@ -6633,6 +6641,10 @@ CompileTimeErrorCode:
66336641
problemMessage: "Extension overrides have no value so they can't be used as the receiver of a cascade expression."
66346642
correctionMessage: "Try using '.' instead of '..'."
66356643
hasPublishedDocs: true
6644+
# In the documentation, the `avoid_single_cascade_in_expression_statements`
6645+
# diagnostic is being ignored because it shouldn't be produced here. They
6646+
# are both signalling the same problem, but the diagnostic being documented
6647+
# provides the better message.
66366648
documentation: |-
66376649
#### Description
66386650

@@ -6647,6 +6659,7 @@ CompileTimeErrorCode:
66476659
expression:
66486660

66496661
```dart
6662+
%ignore=avoid_single_cascade_in_expression_statements
66506663
extension E on int {
66516664
void m() {}
66526665
}
@@ -10167,6 +10180,10 @@ CompileTimeErrorCode:
1016710180
problemMessage: "Inline function types can't be used for parameters in a generic function type."
1016810181
correctionMessage: "Try using a generic function type (returnType 'Function(' parameters ')')."
1016910182
hasPublishedDocs: true
10183+
# In the documentation, the `use_function_type_syntax_for_parameters`
10184+
# diagnostic is being ignored because it shouldn't be produced here. Because
10185+
# it's an error to use a function typed parameter in a generic function
10186+
# type, there's no value in reporting both diagnostics.
1017010187
documentation: |-
1017110188
#### Description
1017210189

@@ -10181,6 +10198,7 @@ CompileTimeErrorCode:
1018110198
type syntax:
1018210199

1018310200
```dart
10201+
%ignore=use_function_type_syntax_for_parameters
1018410202
typedef F = int Function(int f[!(!]String s));
1018510203
```
1018610204

@@ -10198,6 +10216,9 @@ CompileTimeErrorCode:
1019810216
problemMessage: "The modifier '#modifier' can't be applied to the body of a constructor."
1019910217
correctionMessage: Try removing the modifier.
1020010218
hasPublishedDocs: true
10219+
# In the documentation, the `empty_constructor_bodies` diagnostic is being
10220+
# ignored because it shouldn't be produced here. The constructor body can't
10221+
# be replaced by a semicolon because of the `async` keyword.
1020110222
documentation: |-
1020210223
#### Description
1020310224

@@ -10211,6 +10232,7 @@ CompileTimeErrorCode:
1021110232
constructor for `C` is marked as being `async`:
1021210233

1021310234
```dart
10235+
%ignore=empty_constructor_bodies
1021410236
class C {
1021510237
C() [!async!] {}
1021610238
}
@@ -12094,38 +12116,39 @@ CompileTimeErrorCode:
1209412116
documentation: |-
1209512117
#### Description
1209612118

12097-
The analyzer produces this diagnostic when a mixin class declares a non-trivial
12098-
generative constructor. Trivial constructors are allowed, but non-trivial ones
12099-
(those with parameters, bodies, or initializers) aren't.
12119+
The analyzer produces this diagnostic when a mixin class declares a
12120+
non-trivial generative constructor. Trivial constructors are allowed, but
12121+
non-trivial ones (those with parameters, bodies, or initializers) aren't.
1210012122

1210112123
#### Example
1210212124

1210312125
The following code produces this diagnostic because the `mixin class` `A`
12104-
defines a generative constructor with a body:
12126+
defines a generative constructor with an initializer:
1210512127

1210612128
```dart
1210712129
mixin class A {
12108-
[!A!]() {}
12130+
[!A!]() : assert(true);
1210912131
}
1211012132
```
1211112133

1211212134
#### Common fixes
1211312135

12114-
If you can remove the body or parameters of the constructor to make it trivial,
12115-
then do so:
12136+
If you can remove the initialize, body, or parameters of the constructor
12137+
to make it trivial, then do so:
1211612138

1211712139
```dart
1211812140
mixin class A {
1211912141
A(); // Trivial constructor
1212012142
}
1212112143
```
1212212144

12123-
If the constructor can't be made trivial, then convert the `mixin class` to a
12124-
regular `class` and extend or implement it, or separate the mixin capability:
12145+
If the constructor can't be made trivial, then convert the `mixin class`
12146+
to a regular `class` and extend or implement it, or separate the mixin
12147+
capability:
1212512148

1212612149
```dart
1212712150
class A {
12128-
A();
12151+
A() : assert(true);
1212912152
}
1213012153

1213112154
// A separate mixin for mixing in behavior
@@ -13850,6 +13873,10 @@ CompileTimeErrorCode:
1385013873
problemMessage: "The return type of the setter must be 'void' or absent."
1385113874
correctionMessage: Try removing the return type, or define a method rather than a setter.
1385213875
hasPublishedDocs: true
13876+
# In the documentation, the `avoid_return_types_on_setters` diagnostic is
13877+
# ignored because it shouldn't be reported here. If the return type is
13878+
# anything other than `void`, then both will be reported. The lint should
13879+
# only report for a return type of `void`.
1385313880
documentation: |-
1385413881
#### Description
1385513882

@@ -13862,6 +13889,7 @@ CompileTimeErrorCode:
1386213889
return type of `int`:
1386313890

1386413891
```dart
13892+
%ignore=avoid_return_types_on_setters
1386513893
class C {
1386613894
[!int!] set p(int i) => 0;
1386713895
}
@@ -15281,6 +15309,9 @@ CompileTimeErrorCode:
1528115309
problemMessage: Positional super parameters can't be used when the super constructor invocation has a positional argument.
1528215310
correctionMessage: Try making all the positional parameters passed to the super constructor be either all super parameters or all normal parameters.
1528315311
hasPublishedDocs: true
15312+
# In the documentation, the `use_super_parameters` diagnostic is ignored
15313+
# because the only way to resolve the diagnostic would also resolve the
15314+
# diagnostic being documented.
1528415315
documentation: |-
1528515316
#### Description
1528615317

@@ -15304,6 +15335,7 @@ CompileTimeErrorCode:
1530415335
other in the super constructor invocation:
1530515336

1530615337
```dart
15338+
%ignore=use_super_parameters
1530715339
class A {
1530815340
A(int x, int y);
1530915341
}
@@ -27997,6 +28029,9 @@ WarningCode:
2799728029
String name: the name of the member
2799828030
problemMessage: "The member '#name' can only be used within its package."
2799928031
hasPublishedDocs: true
28032+
# In the documentation, the `implementation_imports` diagnostic is being
28033+
# ignored because it's a necessary pre-condition to referencing an internal
28034+
# member.
2800028035
documentation: |-
2800128036
#### Description
2800228037

@@ -28021,6 +28056,7 @@ WarningCode:
2802128056
class `C`, which isn't intended to be used outside the package `p`:
2802228057

2802328058
```dart
28059+
%ignore=implementation_imports
2802428060
import 'package:p/src/p.dart';
2802528061

2802628062
void f([!C!] c) {}

pkg/analyzer/test/verify_diagnostics_test.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -774,18 +774,18 @@ class _SnippetTest extends PubPackageResolutionTest {
774774

775775
// The lints from the 'recommended' lint set.
776776
LintNames.annotate_overrides,
777-
// LintNames.avoid_function_literals_in_foreach_calls,
777+
LintNames.avoid_function_literals_in_foreach_calls,
778778
LintNames.avoid_init_to_null,
779779
LintNames.avoid_renaming_method_parameters,
780-
// LintNames.avoid_return_types_on_setters,
780+
LintNames.avoid_return_types_on_setters,
781781
LintNames.avoid_returning_null_for_void,
782-
// LintNames.avoid_single_cascade_in_expression_statements,
782+
LintNames.avoid_single_cascade_in_expression_statements,
783783
LintNames.constant_identifier_names,
784784
LintNames.control_flow_in_finally,
785-
// LintNames.empty_constructor_bodies,
786-
// LintNames.empty_statements,
785+
LintNames.empty_constructor_bodies,
786+
LintNames.empty_statements,
787787
LintNames.exhaustive_cases,
788-
// LintNames.implementation_imports,
788+
LintNames.implementation_imports,
789789
LintNames.invalid_runtime_check_with_js_interop_types,
790790
LintNames.library_prefixes,
791791
LintNames.library_private_types_in_public_api,
@@ -794,15 +794,15 @@ class _SnippetTest extends PubPackageResolutionTest {
794794
LintNames.null_closures,
795795
LintNames.overridden_fields,
796796
LintNames.package_names,
797-
// LintNames.prefer_adjacent_string_concatenation,
797+
LintNames.prefer_adjacent_string_concatenation,
798798
LintNames.prefer_collection_literals,
799799
LintNames.prefer_conditional_assignment,
800800
LintNames.prefer_contains,
801801
LintNames.prefer_final_fields,
802802
LintNames.prefer_for_elements_to_map_fromiterable,
803-
// LintNames.prefer_function_declarations_over_variables,
803+
LintNames.prefer_function_declarations_over_variables,
804804
LintNames.prefer_if_null_operators,
805-
// LintNames.prefer_initializing_formals,
805+
LintNames.prefer_initializing_formals,
806806
LintNames.prefer_inlined_adds,
807807
LintNames.prefer_interpolation_to_compose_strings,
808808
LintNames.prefer_is_not_operator,
@@ -816,8 +816,8 @@ class _SnippetTest extends PubPackageResolutionTest {
816816
LintNames.unnecessary_constructor_name,
817817
LintNames.unnecessary_getters_setters,
818818
LintNames.unnecessary_late,
819-
// LintNames.unnecessary_library_name,
820-
// LintNames.unnecessary_new,
819+
LintNames.unnecessary_library_name,
820+
LintNames.unnecessary_new,
821821
LintNames.unnecessary_null_aware_assignments,
822822
LintNames.unnecessary_null_in_if_null_operators,
823823
LintNames.unnecessary_nullable_for_final_variable_declarations,
@@ -826,10 +826,10 @@ class _SnippetTest extends PubPackageResolutionTest {
826826
LintNames.unnecessary_this,
827827
LintNames.unnecessary_to_list_in_spreads,
828828
LintNames.unnecessary_underscores,
829-
// LintNames.use_function_type_syntax_for_parameters,
829+
LintNames.use_function_type_syntax_for_parameters,
830830
LintNames.use_null_aware_elements,
831831
LintNames.use_rethrow_when_possible,
832-
// LintNames.use_super_parameters,
832+
LintNames.use_super_parameters,
833833

834834
// The lints from the 'flutter' lint set.
835835
// LintNames.avoid_print,

pkg/linter/messages.yaml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,9 +1444,9 @@ LinterLintCode:
14441444
stable: "2.0"
14451445
categories: [brevity, errorProne]
14461446
hasPublishedDocs: true
1447-
# In the documentation, the `curly_braces_in_flow_control_structures`
1448-
# diagnostic is being ignored because the lint shouldn't be reported when
1449-
# there's already an error being reported.
1447+
# In the documentation, the `curly_braces_in_flow_control_structures` and
1448+
# `empty_statements` diagnostics are being ignored because they can't be
1449+
# fixed without also fixing the diagnostic being documented.
14501450
documentation: |-
14511451
#### Description
14521452

@@ -1462,7 +1462,7 @@ LinterLintCode:
14621462
following the `else` is an empty statement:
14631463

14641464
```dart
1465-
%ignore=curly_braces_in_flow_control_structures
1465+
%ignore=curly_braces_in_flow_control_structures,empty_statements
14661466
void f(int x, int y) {
14671467
if (x > y) {
14681468
print('1');
@@ -7021,6 +7021,9 @@ LinterLintCode:
70217021
stable: "2.0"
70227022
categories: [style]
70237023
hasPublishedDocs: true
7024+
# In the documentation, the `unnecessary_library_name` diagnostic is ignored
7025+
# because the diagnostic being documented requires the existance of a
7026+
# library name.
70247027
documentation: |-
70257028
#### Description
70267029

@@ -7033,6 +7036,7 @@ LinterLintCode:
70337036
`libraryName` isn't a lower_case_with_underscores identifier:
70347037

70357038
```dart
7039+
%ignore=unnecessary_library_name
70367040
library [!libraryName!];
70377041
```
70387042

@@ -7048,6 +7052,7 @@ LinterLintCode:
70487052
lower_case_with_underscores naming convention:
70497053

70507054
```dart
7055+
%ignore=unnecessary_library_name
70517056
library library_name;
70527057
```
70537058
deprecatedDetails: |-
@@ -7664,6 +7669,10 @@ LinterLintCode:
76647669
stable: "2.0"
76657670
categories: [style]
76667671
hasPublishedDocs: true
7672+
# In the documentation, the `prefer_adjacent_string_concatenation`
7673+
# diagnostic is ignored because even though the use of `+` isn't a
7674+
# recommended solution, it is a valid way to avoid this lint. We should
7675+
# consider allowing the use of `+` in list literals.
76677676
documentation: |-
76687677
#### Description
76697678

@@ -7704,6 +7713,7 @@ LinterLintCode:
77047713
Or use the `+` operator to concatenate the strings:
77057714

77067715
```dart
7716+
%ignore=prefer_adjacent_string_concatenation
77077717
List<String> list = ['a' + 'b', 'c'];
77087718
```
77097719
deprecatedDetails: |-
@@ -15048,6 +15058,11 @@ LinterLintCode:
1504815058
stable: "2.0"
1504915059
categories: [style]
1505015060
hasPublishedDocs: true
15061+
# In the documentation, the `avoid_function_literals_in_foreach_calls`
15062+
# diagnostic is ignored because it's a bi-product of the choice of example.
15063+
# The documentation is more clear if we use a familiar method that taked a
15064+
# function as a parameter, and `forEach` is a reasonable choice. We could
15065+
# remove the ignore by choosing a different method.
1505115066
documentation: |-
1505215067
#### Description
1505315068

@@ -15061,6 +15076,7 @@ LinterLintCode:
1506115076
parameter of the closure:
1506215077

1506315078
```dart
15079+
%ignore=avoid_function_literals_in_foreach_calls
1506415080
void f(List<String> strings) {
1506515081
strings.forEach([!(string) {
1506615082
print(string);
@@ -17197,6 +17213,9 @@ LinterLintCode:
1719717213
stable: "3.13"
1719817214
categories: [style]
1719917215
hasPublishedDocs: true
17216+
# In the documentation, the `prefer_initializing_formals` diagnostic is
17217+
# ignored because not using an initializing formal shows a more dramatic
17218+
# improvement in the code.
1720017219
documentation: |-
1720117220
#### Description
1720217221

@@ -17210,6 +17229,7 @@ LinterLintCode:
1721017229
assigns the parameter `i` to the field `i`:
1721117230

1721217231
```dart
17232+
%ignore=prefer_initializing_formals
1721317233
class C(int [!i!]) {
1721417234
final int i;
1721517235

0 commit comments

Comments
 (0)