Skip to content

Commit 0284cb4

Browse files
stereotype441Commit Queue
authored andcommitted
[messages] Remove inconsistency in linter's messages.yaml.
Changes the class heading in `pkg/linter/messages.yaml` from `LintCode` to `LinterLintCode`. This fixes an inconsistency by ensuring that in both analyzer-style `messages.yaml` files (`pkg/linter/messages.yaml` and `pkg/analyzer/messages.yaml`), all class headings match the name of the corresponding generated error class. Fixing this inconsistency allows the signature of `MessageWithAnalyzerCode.toAnalyzerCode` to be simplified--it no longer needs a `diagnosticClassInfo` parameter, since it can obtain one from `analyzerCode.diagnosticClass`. Note that there are no changes to generated code, so the behavior of the analyzer and linter is unaffected. Change-Id: I6a6a69644221d8d93b32a454bd5ff8519fbd6971 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/458960 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent ec64f62 commit 0284cb4

File tree

6 files changed

+31
-37
lines changed

6 files changed

+31
-37
lines changed

pkg/analyzer/test/verify_diagnostics_test.dart

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,49 +101,49 @@ class DocumentationValidator {
101101
'HintCode.DEPRECATED_MEMBER_USE',
102102

103103
// Need a way to specify the existance of files whose content is irrelevant.
104-
'LintCode.always_use_package_imports',
104+
'LinterLintCode.always_use_package_imports',
105105
// Missing support for example files outside of `lib`.
106-
'LintCode.avoid_relative_lib_imports',
106+
'LinterLintCode.avoid_relative_lib_imports',
107107
// The example isn't being recognized as a flutter app. We might need to
108108
// build a pubspec.yaml when analyzing flutter code.
109-
'LintCode.avoid_web_libraries_in_flutter',
109+
'LinterLintCode.avoid_web_libraries_in_flutter',
110110
// Produces a CompileTimeErrorCode.BODY_MIGHT_COMPLETE_NORMALLY.
111-
'LintCode.control_flow_in_finally',
111+
'LinterLintCode.control_flow_in_finally',
112112
// Missing support for creating an indirect dependency on a package.
113-
'LintCode.depend_on_referenced_packages',
113+
'LinterLintCode.depend_on_referenced_packages',
114114
// Missing support for specifying the name of the test file.
115-
'LintCode.file_names',
115+
'LinterLintCode.file_names',
116116
// Produces an unused import diagnostic.
117-
'LintCode.implementation_imports',
117+
'LinterLintCode.implementation_imports',
118118
// Doesn't produce a lint for the second example, even though the analyzer
119119
// does when the example is pasted into a file.
120-
'LintCode.prefer_inlined_adds_single',
120+
'LinterLintCode.prefer_inlined_adds_single',
121121
// No mock 'test' package, no good library annotations in 'meta'.
122-
'LintCode.library_annotations',
122+
'LinterLintCode.library_annotations',
123123
// Produces an unused import diagnostic.
124-
'LintCode.library_prefixes',
124+
'LinterLintCode.library_prefixes',
125125
// Produces an unused element diagnostic.
126-
'LintCode.library_private_types_in_public_api',
126+
'LinterLintCode.library_private_types_in_public_api',
127127
// Missing support for YAML files.
128-
'LintCode.package_names',
128+
'LinterLintCode.package_names',
129129
// The lint does nothing.
130-
'LintCode.package_prefixed_library_names',
130+
'LinterLintCode.package_prefixed_library_names',
131131
// Need a way to specify the existance of files whose content is irrelevant.
132-
'LintCode.prefer_relative_imports',
132+
'LinterLintCode.prefer_relative_imports',
133133
// The test file is in a basic workspace, so it can't have public API. I
134134
// think we'd need to add a `pubspec.yaml` file to the example.
135-
'LintCode.public_member_api_docs',
135+
'LinterLintCode.public_member_api_docs',
136136
// Missing support for YAML files.
137-
'LintCode.secure_pubspec_urls',
137+
'LinterLintCode.secure_pubspec_urls',
138138
// The test framework doesn't yet support lints in non-dart files.
139-
'LintCode.sort_pub_dependencies',
139+
'LinterLintCode.sort_pub_dependencies',
140140
// Doesn't produce a lint for the first example, even though the analyzer
141141
// does when the example is pasted into a file.
142-
'LintCode.unnecessary_lambdas',
142+
'LinterLintCode.unnecessary_lambdas',
143143
// Produces an unused_field warning.
144-
'LintCode.use_setters_to_change_properties',
144+
'LinterLintCode.use_setters_to_change_properties',
145145
// Extra warning.
146-
'LintCode.recursive_getters',
146+
'LinterLintCode.recursive_getters',
147147

148148
// Has `language=2.9`
149149
'CompileTimeErrorCode.EXTENSION_DECLARES_INSTANCE_FIELD',
@@ -370,7 +370,7 @@ class DocumentationValidator {
370370
}
371371
for (int i = 0; i < exampleSnippets.length; i++) {
372372
_SnippetData snippet = exampleSnippets[i];
373-
if (message.analyzerCode.diagnosticClass == lintCodeInfo) {
373+
if (message.analyzerCode.diagnosticClass == linterLintCodeInfo) {
374374
snippet.lintCode = codeName;
375375
}
376376
await _validateSnippet('example', i, snippet);
@@ -385,7 +385,7 @@ class DocumentationValidator {
385385
if (firstExample != null) {
386386
snippet.auxiliaryFiles.addAll(firstExample.auxiliaryFiles);
387387
}
388-
if (message.analyzerCode.diagnosticClass == lintCodeInfo) {
388+
if (message.analyzerCode.diagnosticClass == linterLintCodeInfo) {
389389
snippet.lintCode = codeName;
390390
}
391391
await _validateSnippet('fixes', i, snippet);

pkg/analyzer/tool/messages/generate.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ part of ${json.encode(file.parentLibrary)};
119119
if (message.analyzerCode.diagnosticClass != diagnosticClass) continue;
120120

121121
LocatedError.wrap(span: message.keySpan, () {
122-
message.toAnalyzerCode(
123-
diagnosticClass,
124-
memberAccumulator: memberAccumulator,
125-
);
122+
message.toAnalyzerCode(memberAccumulator: memberAccumulator);
126123
});
127124
}
128125

pkg/analyzer_utilities/lib/analyzer_messages.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const codesFile = GeneratedDiagnosticFile(
2222
///
2323
/// Note: to look up an error class by name, use [DiagnosticClassInfo.byName].
2424
const List<DiagnosticClassInfo> diagnosticClasses = [
25-
lintCodeInfo,
2625
linterLintCodeInfo,
2726
GeneratedDiagnosticClassInfo(
2827
file: optionCodesFile,
@@ -115,8 +114,6 @@ const hintCodesFile = GeneratedDiagnosticFile(
115114
parentLibrary: 'package:analyzer/src/dart/error/hint_codes.dart',
116115
);
117116

118-
const lintCodeInfo = DiagnosticClassInfo(name: 'LintCode');
119-
120117
const lintCodesFile = GeneratedDiagnosticFile(
121118
path: generatedLintCodesPath,
122119
parentLibrary: 'package:linter/src/lint_codes.dart',
@@ -333,8 +330,7 @@ class AliasMessage extends AnalyzerMessage {
333330
String get aliasForClass => aliasFor.split('.').first;
334331

335332
@override
336-
void toAnalyzerCode(
337-
DiagnosticClassInfo diagnosticClassInfo, {
333+
void toAnalyzerCode({
338334
String? sharedNameReference,
339335
required MemberAccumulator memberAccumulator,
340336
}) {
@@ -398,6 +394,9 @@ class AnalyzerMessage extends Message with MessageWithAnalyzerCode {
398394
/// Interface class for diagnostic messages that have an analyzer code, and thus
399395
/// can be reported by the analyzer.
400396
mixin MessageWithAnalyzerCode on Message {
397+
late final GeneratedDiagnosticClassInfo diagnosticClassInfo =
398+
analyzerCode.diagnosticClass as GeneratedDiagnosticClassInfo;
399+
401400
/// The code used by the analyzer to refer to this diagnostic message.
402401
AnalyzerCode get analyzerCode;
403402

@@ -422,8 +421,7 @@ mixin MessageWithAnalyzerCode on Message {
422421
/// in the diagnostic class [className].
423422
///
424423
/// [diagnosticCode] is the name of the diagnostic to be generated.
425-
void toAnalyzerCode(
426-
GeneratedDiagnosticClassInfo diagnosticClassInfo, {
424+
void toAnalyzerCode({
427425
String? sharedNameReference,
428426
required MemberAccumulator memberAccumulator,
429427
}) {

pkg/linter/messages.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# * unusedCode - rules that protect against unused code.
2828
# * web - rules that help to write code deployed to the web.
2929

30-
LintCode:
30+
LinterLintCode:
3131
always_declare_return_types_of_functions:
3232
parameters:
3333
Object p0: undocumented

pkg/linter/tool/generate_lints.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class LinterLintCode extends LintCodeWithExpectedTypes {
5252
var lintName = message.sharedName ?? analyzerCode.snakeCaseName;
5353
if (messagesRuleInfo[lintName]!.removed) continue;
5454
message.toAnalyzerCode(
55-
linterLintCodeInfo,
5655
sharedNameReference: 'LintNames.$lintName',
5756
memberAccumulator: memberAccumulator,
5857
);

pkg/linter/tool/messages_info.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ final Map<String, RuleInfo> messagesRuleInfo = () {
4444
if (messagesYaml is! YamlMap) {
4545
throw StateError("The '$_messagesFileName' file is not a YAML map.");
4646
}
47-
var lintCodes = messagesYaml['LintCode'] as YamlMap?;
47+
var lintCodes = messagesYaml['LinterLintCode'] as YamlMap?;
4848
if (lintCodes == null) {
4949
throw StateError(
50-
"The '$_messagesFileName' file does not have a 'LintCode' section.",
50+
"The '$_messagesFileName' file does not have a 'LinterLintCode' section.",
5151
);
5252
}
5353

0 commit comments

Comments
 (0)