Skip to content

Commit 55a2089

Browse files
bwilkersonCommit Queue
authored andcommitted
Add a test for hasPublishedDocs
This causes the code that parses the `messages.yaml` files in either the analyzer or linter packages so that it throw an exception if any code fails to have an explicit `hasPublishedDocs` key. We decided to require the field because it makes it easier to identify codes for which documentation has not yet been published. Prior to this the search looked for codes missing this key _or_ codes where this key had a value of `false`, but now only the last needs to be searched for which can be done using a simple textual search. Change-Id: I1aa59eb02a628fae8cb79c5390b59c787218fe15 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431761 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 2b59598 commit 55a2089

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

pkg/analyzer/tool/messages/error_code_info.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ Map<String, Map<String, AnalyzerErrorCodeInfo>> decodeAnalyzerMessagesYaml(
172172
st,
173173
);
174174
}
175+
if (errorCodeInfo.hasPublishedDocs == null) {
176+
problem('Missing hasPublishedDocs for $className.$errorName');
177+
}
175178

176179
if (errorCodeInfo case AliasErrorCodeInfo(:var aliasFor)) {
177180
var aliasForPath = aliasFor.split('.');
@@ -215,7 +218,11 @@ Map<String, FrontEndErrorCodeInfo> decodeCfeMessagesYaml(Object? yaml) {
215218
if (errorValue is! Map<Object?, Object?>) {
216219
problem('value associated with error $errorName is not a map');
217220
}
218-
result[errorName] = FrontEndErrorCodeInfo.fromYaml(errorValue);
221+
try {
222+
result[errorName] = FrontEndErrorCodeInfo.fromYaml(errorValue);
223+
} catch (e, st) {
224+
Error.throwWithStackTrace('while processing $errorName, $e', st);
225+
}
219226
}
220227
return result;
221228
}
@@ -468,9 +475,11 @@ abstract class ErrorCodeInfo {
468475
/// If present, user-facing documentation for the error.
469476
final String? documentation;
470477

471-
/// `true` if diagnostics with this code have documentation for them that has
478+
/// Whether diagnostics with this code have documentation for them that has
472479
/// been published.
473-
final bool hasPublishedDocs;
480+
///
481+
/// `null` if the YAML doesn't contain this information.
482+
final bool? hasPublishedDocs;
474483

475484
/// Indicates whether this error is caused by an unresolved identifier.
476485
final bool isUnresolvedIdentifier;
@@ -494,7 +503,7 @@ abstract class ErrorCodeInfo {
494503
ErrorCodeInfo({
495504
this.comment,
496505
this.documentation,
497-
this.hasPublishedDocs = false,
506+
this.hasPublishedDocs,
498507
this.isUnresolvedIdentifier = false,
499508
this.sharedName,
500509
required this.problemMessage,
@@ -511,7 +520,7 @@ abstract class ErrorCodeInfo {
511520
correctionMessage: yaml['correctionMessage'] as String?,
512521
deprecatedMessage: yaml['deprecatedMessage'] as String?,
513522
documentation: yaml['documentation'] as String?,
514-
hasPublishedDocs: yaml['hasPublishedDocs'] as bool? ?? false,
523+
hasPublishedDocs: yaml['hasPublishedDocs'] as bool?,
515524
isUnresolvedIdentifier:
516525
yaml['isUnresolvedIdentifier'] as bool? ?? false,
517526
problemMessage: yaml['problemMessage'] as String? ?? '',
@@ -574,7 +583,7 @@ abstract class ErrorCodeInfo {
574583
var codeLines = _splitText(code, maxWidth: maxWidth);
575584
out.writeln('${codeLines.map(json.encode).join('\n')},');
576585
}
577-
if (hasPublishedDocs) {
586+
if (hasPublishedDocs ?? false) {
578587
out.writeln('hasPublishedDocs:true,');
579588
}
580589
if (isUnresolvedIdentifier) {
@@ -606,7 +615,7 @@ abstract class ErrorCodeInfo {
606615
'problemMessage': problemMessage,
607616
if (correctionMessage != null) 'correctionMessage': correctionMessage,
608617
if (isUnresolvedIdentifier) 'isUnresolvedIdentifier': true,
609-
if (hasPublishedDocs) 'hasPublishedDocs': true,
618+
if (hasPublishedDocs ?? false) 'hasPublishedDocs': true,
610619
if (comment != null) 'comment': comment,
611620
if (documentation != null) 'documentation': documentation,
612621
};

pkg/linter/messages.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ LintCode:
223223
state:
224224
stable: "2.0"
225225
removed: "3.3"
226+
hasPublishedDocs: false
226227
deprecatedDetails: |-
227228
NOTE: This rule is removed in Dart 3.3.0; it is no longer functional.
228229
@@ -542,6 +543,7 @@ LintCode:
542543
state:
543544
stable: "2.0"
544545
removed: "3.0"
546+
hasPublishedDocs: false
545547
deprecatedDetails: |-
546548
NOTE: This rule was removed from the SDK in Dart 3; it is no longer functional.
547549
Its advice is compiler-specific and mostly obsolete with null safety.
@@ -1909,6 +1911,7 @@ LintCode:
19091911
state:
19101912
stable: "2.0"
19111913
removed: "3.3"
1914+
hasPublishedDocs: false
19121915
deprecatedDetails: |-
19131916
NOTE: This rule is removed in Dart 3.3.0; it is no longer functional.
19141917
@@ -1938,6 +1941,7 @@ LintCode:
19381941
state:
19391942
stable: "2.1"
19401943
removed: "3.3"
1944+
hasPublishedDocs: false
19411945
deprecatedDetails: |-
19421946
NOTE: This rule is removed in Dart 3.3.0; it is no longer functional.
19431947
@@ -2545,6 +2549,7 @@ LintCode:
25452549
state:
25462550
experimental: "3.3"
25472551
removed: "3.3"
2552+
hasPublishedDocs: false
25482553
deprecatedDetails: |-
25492554
This rule has been removed.
25502555
avoid_unused_constructor_parameters:
@@ -4438,6 +4443,7 @@ LintCode:
44384443
state:
44394444
stable: "2.19"
44404445
removed: "3.0"
4446+
hasPublishedDocs: false
44414447
deprecatedDetails: |-
44424448
NOTE: This rule is removed in Dart 3.0.0; it is no longer functional.
44434449
@@ -5343,6 +5349,7 @@ LintCode:
53435349
state:
53445350
stable: "2.0"
53455351
removed: "3.0"
5352+
hasPublishedDocs: false
53465353
deprecatedDetails: |-
53475354
NOTE: This rule is removed in Dart 3.0.0; it is no longer functional.
53485355
@@ -5428,6 +5435,7 @@ LintCode:
54285435
state:
54295436
stable: "2.0"
54305437
removed: "3.3"
5438+
hasPublishedDocs: false
54315439
deprecatedDetails: |-
54325440
NOTE: This rule is removed in Dart 3.3.0; it is no longer functional.
54335441
@@ -5868,6 +5876,7 @@ LintCode:
58685876
state:
58695877
stable: "2.0"
58705878
removed: "3.3"
5879+
hasPublishedDocs: false
58715880
deprecatedDetails: |-
58725881
NOTE: This rule is removed in Dart 3.3.0; it is no longer functional.
58735882
@@ -7951,6 +7960,7 @@ LintCode:
79517960
state:
79527961
stable: "2.0"
79537962
removed: "3.0"
7963+
hasPublishedDocs: false
79547964
deprecatedDetails: |-
79557965
NOTE: This rule is removed in Dart 3.0.0; it is no longer functional.
79567966
@@ -8652,6 +8662,7 @@ LintCode:
86528662
state:
86538663
stable: "2.0"
86548664
removed: "3.0"
8665+
hasPublishedDocs: false
86558666
deprecatedDetails: |-
86568667
NOTE: This rule is removed in Dart 3.0; it is no longer functional.
86578668
@@ -11312,6 +11323,7 @@ LintCode:
1131211323
state:
1131311324
stable: "2.0"
1131411325
removed: "3.0"
11326+
hasPublishedDocs: false
1131511327
deprecatedDetails: |-
1131611328
NOTE: This rule is removed in Dart 3.0.0; it is no longer functional.
1131711329

0 commit comments

Comments
 (0)