Skip to content

Commit bcd7c3a

Browse files
stereotype441Commit Queue
authored andcommitted
[messages] Prepare to standardize DiagnosticCode names to all lower case.
In a follow-up CL, I will change the code generator for diagnostic messages so that all code-generated instances of `DiagnosticCode` have `name` and `uniqueName` fields in all lower case letters. This will help pave the way toward resolving conflicts between the diagnostic code naming conventions between the analyzer and CFE. To prepare for this change, the following pieces of code need to first be modified to be case insensitive: - The `_ignoreNullSafetyWarnings` check in `RemoveDeadCodeSoundFlowAnalysisTest`. - The `_diagnosticCodes` fields in `_CannotIgnoreOptionValidator` and `_ErrorFilterOptionValidator`. - The `computeErrorData` methods in `ConstantsDataComputer` and `_InheritanceDataComputer`. - The `_writeDiagnostic` methods in `DriverEventsPrinter` and `ResolvedUnitResultPrinter`. - The `_validateMessages` and `_validateSnippet` methods in `DocumentationValidator`. - The `run` method in `TextualOutline`. In most cases, the code was changed to be case insensitive by having it call `.toLowerCase()` or `.toUpperCase()` on the diagnostic code name before operating on it. In one case I was able to re-use the `AnalyzerCode.lowerSnakeCaseName` getter. Change-Id: I6a6a6964f3cc4c71f2e82478855d64d5ef91d26b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465804 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 34a63b5 commit bcd7c3a

File tree

7 files changed

+23
-13
lines changed

7 files changed

+23
-13
lines changed

pkg/analysis_server/test/src/services/correction/fix/remove_dead_code_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,8 @@ void f(int i, int j) => i;
11591159
/// Error filter ignoring warnings that frequently occur in conjunction with
11601160
/// code that is dead due to sound flow analysis.
11611161
bool _ignoreNullSafetyWarnings(Diagnostic diagnostic) => !const {
1162-
'DEAD_NULL_AWARE_EXPRESSION',
1163-
'INVALID_NULL_AWARE_OPERATOR',
1164-
'UNNECESSARY_NULL_COMPARISON',
1165-
}.contains(diagnostic.diagnosticCode.name);
1162+
'dead_null_aware_expression',
1163+
'invalid_null_aware_operator',
1164+
'unnecessary_null_comparison',
1165+
}.contains(diagnostic.diagnosticCode.name.toLowerCase());
11661166
}

pkg/analyzer/lib/src/analysis_options/options_file_validator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class _AnalyzerTopLevelOptionsValidator extends _TopLevelOptionValidator {
346346
class _CannotIgnoreOptionValidator extends OptionsValidator {
347347
/// Lazily populated set of diagnostic code names.
348348
static final Set<String> _diagnosticCodes = diagnosticCodeValues
349-
.map((DiagnosticCode code) => code.name)
349+
.map((DiagnosticCode code) => code.name.toUpperCase())
350350
.toSet();
351351

352352
/// The diagnostic code names that existed, but were removed.
@@ -591,7 +591,7 @@ class _ErrorFilterOptionValidator extends OptionsValidator {
591591

592592
/// Lazily populated set of diagnostic code names.
593593
static final Set<String> _diagnosticCodes = diagnosticCodeValues
594-
.map((DiagnosticCode code) => code.name)
594+
.map((DiagnosticCode code) => code.name.toUpperCase())
595595
.toSet();
596596

597597
/// The diagnostic code names that existed, but were removed.

pkg/analyzer/test/id_tests/constant_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ class ConstantsDataComputer extends DataComputer<String> {
6060
var diagnosticCodes = diagnostics
6161
.map((e) => e.diagnosticCode)
6262
.where((c) => c != diag.constInitializedWithNonConstantValue);
63-
return diagnosticCodes.isNotEmpty ? diagnosticCodes.join(',') : null;
63+
return diagnosticCodes.isNotEmpty
64+
? diagnosticCodes.map((c) => c.uniqueName.toUpperCase()).join(',')
65+
: null;
6466
}
6567

6668
@override

pkg/analyzer/test/id_tests/inheritance_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ class _InheritanceDataComputer extends DataComputer<String> {
6565
Id id,
6666
List<Diagnostic> diagnostics,
6767
) {
68-
return diagnostics.map((e) => e.diagnosticCode).join(',');
68+
return diagnostics
69+
.map((e) => e.diagnosticCode.uniqueName.toUpperCase())
70+
.join(',');
6971
}
7072

7173
@override

pkg/analyzer/test/src/dart/analysis/result_printer.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ class DriverEventsPrinter {
409409
}
410410

411411
void _writeDiagnostic(Diagnostic d) {
412-
sink.writelnWithIndent('${d.offset} +${d.length} ${d.diagnosticCode.name}');
412+
sink.writelnWithIndent(
413+
'${d.offset} +${d.length} ${d.diagnosticCode.name.toUpperCase()}',
414+
);
413415
}
414416

415417
void _writeErrorsEvent(GetErrorsEvent event) {
@@ -1965,7 +1967,9 @@ class ResolvedUnitResultPrinter {
19651967
}
19661968

19671969
void _writeDiagnostic(Diagnostic d) {
1968-
sink.writelnWithIndent('${d.offset} +${d.length} ${d.diagnosticCode.name}');
1970+
sink.writelnWithIndent(
1971+
'${d.offset} +${d.length} ${d.diagnosticCode.name.toUpperCase()}',
1972+
);
19691973
}
19701974

19711975
void _writeResolvedUnitResult(ResolvedUnitResultImpl result) {

pkg/analyzer/test/verify_diagnostics_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ class DocumentationValidator {
374374
message.documentation,
375375
);
376376
if (docs != null) {
377-
codeName = (message.sharedName ?? message.analyzerCode).snakeCaseName;
377+
codeName =
378+
(message.sharedName ?? message.analyzerCode).lowerSnakeCaseName;
378379
variableName = message.analyzerCode.lowerSnakeCaseName;
379380
if (unverifiedDocs.contains(variableName)) {
380381
continue;
@@ -443,7 +444,7 @@ class DocumentationValidator {
443444
_reportProblem('Expected one error but found none ($section $index).');
444445
} else if (errorCount == 1) {
445446
Diagnostic diagnostic = diagnostics[0];
446-
if (diagnostic.diagnosticCode.name != codeName) {
447+
if (diagnostic.diagnosticCode.name.toLowerCase() != codeName) {
447448
_reportProblem(
448449
'Expected an error with code $codeName, '
449450
'found ${diagnostic.diagnosticCode} ($section $index).',

pkg/front_end/test/textual_outline_suite.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ class TextualOutline extends Step<TestDescription, TestDescription, Context> {
170170
formatterExceptionSt = st;
171171
if (e is FormatterException) {
172172
for (var error in e.errors) {
173-
if (error.diagnosticCode.name == "EXPERIMENT_NOT_ENABLED") {
173+
if (error.diagnosticCode.name.toUpperCase() ==
174+
"EXPERIMENT_NOT_ENABLED") {
174175
allowFormatterCrash = true;
175176
}
176177
}

0 commit comments

Comments
 (0)