Skip to content

Commit 97c49e7

Browse files
srawlinsCommit Queue
authored andcommitted
Deprecate errorCodeValues for diagnosticCodeValues
Work towards #60635 Change-Id: Ieea525a3f7260ea50e766feff0a0647fc0c33b4d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434526 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 27b9397 commit 97c49e7

File tree

14 files changed

+69
-55
lines changed

14 files changed

+69
-55
lines changed

PRESUBMIT.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def _CheckAnalyzerFiles(input_api, output_api):
380380

381381
# Verify the "error fix status" file.
382382
code_files = [
383-
"pkg/analyzer/lib/src/error/error_code_values.g.dart",
383+
"pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart",
384384
"pkg/linter/lib/src/rules.dart",
385385
]
386386

pkg/analysis_server/lib/src/services/completion/yaml/analysis_options_generator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class _ErrorProducer extends KeyValueProducer {
7474
@override
7575
Iterable<CompletionSuggestion> suggestions(YamlCompletionRequest request) {
7676
return [
77-
for (var error in errorCodeValues)
78-
identifier('${error.name.toLowerCase()}: '),
77+
for (var diagnostic in diagnosticCodeValues)
78+
identifier('${diagnostic.name.toLowerCase()}: '),
7979
for (var rule in Registry.ruleRegistry.rules)
8080
identifier('${rule.name}: '),
8181
];

pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class BulkFixProcessor {
157157
static final Map<DiagnosticCode, bool> _bulkFixableCodes = {};
158158

159159
static final Set<String> _diagnosticCodes =
160-
errorCodeValues.map((code) => code.name.toLowerCase()).toSet();
160+
diagnosticCodeValues.map((code) => code.name.toLowerCase()).toSet();
161161

162162
static final Set<String> _lintCodes =
163163
Registry.ruleRegistry.rules.map((rule) => rule.name).toSet();

pkg/analysis_server/tool/presubmit/verify_error_fix_status.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ String? verifyErrorFixStatus() {
5757
var lintRuleNames = {for (var lintCode in lintRuleCodes) lintCode.uniqueName};
5858

5959
var errorData = ErrorData();
60-
for (var code in errorCodeValues) {
60+
for (var code in diagnosticCodeValues) {
6161
var name = code.uniqueName;
6262
if (name.startsWith('TodoCode.')) {
6363
// To-do codes are ignored.
@@ -99,10 +99,10 @@ String? verifyErrorFixStatus() {
9999
}
100100
}
101101

102-
var errorCodeNames = {for (var code in errorCodeValues) code.uniqueName};
102+
var codeNames = {for (var code in diagnosticCodeValues) code.uniqueName};
103103
for (var key in statusInfo.keys) {
104104
if (key is String) {
105-
if (!errorCodeNames.contains(key) && !lintRuleNames.contains(key)) {
105+
if (!codeNames.contains(key) && !lintRuleNames.contains(key)) {
106106
errorData.entriesWithNoCode.add(key);
107107
}
108108
}

pkg/analyzer/api.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4685,7 +4685,8 @@ package:analyzer/diagnostic/diagnostic.dart:
46854685
values (static getter: List<Severity>)
46864686
warning (static getter: Severity)
46874687
package:analyzer/error/error.dart:
4688-
errorCodeValues (static getter: List<DiagnosticCode>)
4688+
diagnosticCodeValues (static getter: List<DiagnosticCode>)
4689+
errorCodeValues (static getter: List<DiagnosticCode>, deprecated)
46894690
errorCodeByUniqueName (function: DiagnosticCode? Function(String))
46904691
DiagnosticCode (class extends Object):
46914692
new (constructor: DiagnosticCode Function({String? correctionMessage, bool hasPublishedDocs, bool isUnresolvedIdentifier, required String name, required String problemMessage, required String uniqueName}))

pkg/analyzer/lib/error/error.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'dart:collection';
99

1010
import 'package:_fe_analyzer_shared/src/base/errors.dart';
1111
import 'package:analyzer/diagnostic/diagnostic.dart';
12-
import 'package:analyzer/src/error/error_code_values.g.dart';
12+
import 'package:analyzer/src/diagnostic/diagnostic_code_values.g.dart';
1313

1414
export 'package:_fe_analyzer_shared/src/base/errors.dart'
1515
show
@@ -26,7 +26,7 @@ export 'package:_fe_analyzer_shared/src/base/errors.dart'
2626
// ignore: deprecated_member_use
2727
ErrorType;
2828
export 'package:analyzer/src/dart/error/lint_codes.dart' show LintCode;
29-
export 'package:analyzer/src/error/error_code_values.g.dart';
29+
export 'package:analyzer/src/diagnostic/diagnostic_code_values.g.dart';
3030

3131
/// The lazy initialized map from [DiagnosticCode.uniqueName] to the
3232
/// [DiagnosticCode] instance.
@@ -39,11 +39,11 @@ DiagnosticCode? errorCodeByUniqueName(String uniqueName) {
3939
return _uniqueNameToCodeMap[uniqueName];
4040
}
4141

42-
/// Return the map from [DiagnosticCode.uniqueName] to the [DiagnosticCode]
43-
/// instance for all [errorCodeValues].
42+
/// The map from [DiagnosticCode.uniqueName] to the [DiagnosticCode] instance
43+
/// for all [diagnosticCodeValues].
4444
HashMap<String, DiagnosticCode> _computeUniqueNameToCodeMap() {
4545
var result = HashMap<String, DiagnosticCode>();
46-
for (DiagnosticCode diagnosticCode in errorCodeValues) {
46+
for (DiagnosticCode diagnosticCode in diagnosticCodeValues) {
4747
var uniqueName = diagnosticCode.uniqueName;
4848
assert(() {
4949
if (result.containsKey(uniqueName)) {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,25 +302,25 @@ final class AnalysisOptionsBuilder {
302302
var stringValues = cannotIgnore.whereType<String>().toSet();
303303
for (var severity in AnalysisOptionsFile.severities) {
304304
if (stringValues.contains(severity)) {
305-
// [severity] is a marker denoting all error codes with severity
305+
// [severity] is a marker denoting all diagnostic codes with severity
306306
// equal to [severity].
307307
stringValues.remove(severity);
308-
// Replace name like 'error' with error codes with this named
308+
// Replace name like 'error' with diagnostic codes with this named
309309
// severity.
310-
for (var e in errorCodeValues) {
310+
for (var d in diagnosticCodeValues) {
311311
// If the severity of [error] is also changed in this options file
312312
// to be [severity], we add [error] to the un-ignorable list.
313313
var processors = errorProcessors.where(
314-
(processor) => processor.code == e.name,
314+
(processor) => processor.code == d.name,
315315
);
316316
if (processors.isNotEmpty &&
317317
processors.first.severity?.displayName == severity) {
318-
unignorableDiagnosticCodeNames.add(e.name);
318+
unignorableDiagnosticCodeNames.add(d.name);
319319
continue;
320320
}
321321
// Otherwise, add [error] if its default severity is [severity].
322-
if (e.severity.displayName == severity) {
323-
unignorableDiagnosticCodeNames.add(e.name);
322+
if (d.severity.displayName == severity) {
323+
unignorableDiagnosticCodeNames.add(d.name);
324324
}
325325
}
326326
}

pkg/analyzer/lib/src/error/error_code_values.g.dart renamed to pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import 'package:analyzer/src/manifest/manifest_warning_code.dart';
2424
import 'package:analyzer/src/pubspec/pubspec_warning_code.dart';
2525

2626
@AnalyzerPublicApi(message: 'exported by lib/error/error.dart')
27-
const List<DiagnosticCode> errorCodeValues = [
27+
const List<DiagnosticCode> diagnosticCodeValues = [
2828
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR,
2929
AnalysisOptionsErrorCode.PARSE_ERROR,
3030
AnalysisOptionsWarningCode.ANALYSIS_OPTION_DEPRECATED,
@@ -1125,3 +1125,7 @@ const List<DiagnosticCode> errorCodeValues = [
11251125
WarningCode.UNUSED_SHOWN_NAME,
11261126
WarningCode.URI_DOES_NOT_EXIST_IN_DOC_IMPORT,
11271127
];
1128+
1129+
@AnalyzerPublicApi(message: 'exported by lib/error/error.dart')
1130+
@Deprecated("Use 'diagnosticCodeValues' instead")
1131+
List<DiagnosticCode> get errorCodeValues => diagnosticCodeValues;

pkg/analyzer/lib/src/error/ignore_validator.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import 'package:analyzer/src/lint/registry.dart';
1212

1313
/// Used to validate the ignore comments in a single file.
1414
class IgnoreValidator {
15-
/// A list of known error codes used to ensure we don't over-report
15+
/// A list of known diagnostic codes used to ensure we don't over-report
1616
/// `unnecessary_ignore`s on error codes that may be contributed by a plugin.
17-
static final Set<String> _validErrorCodeNames =
18-
errorCodeValues.map((e) => e.name.toLowerCase()).toSet();
17+
static final Set<String> _validDiagnosticCodeNames =
18+
diagnosticCodeValues.map((d) => d.name.toLowerCase()).toSet();
1919

20-
/// Error codes used to report `unnecessary_ignore`s.
20+
/// Diagnostic codes used to report `unnecessary_ignore`s.
21+
///
2122
/// These codes are set when the `UnnecessaryIgnore` lint rule is instantiated and
2223
/// registered by the linter.
2324
static late DiagnosticCode unnecessaryIgnoreLocationLintCode;
@@ -202,7 +203,7 @@ class IgnoreValidator {
202203
// If a code is not a lint or a recognized error,
203204
// don't report. (It could come from a plugin.)
204205
// TODO(pq): consider another diagnostic that reports undefined codes
205-
if (!_validErrorCodeNames.contains(name.toLowerCase())) continue;
206+
if (!_validDiagnosticCodeNames.contains(name.toLowerCase())) continue;
206207
} else {
207208
var state = rule.state;
208209
var since = state.since.toString();

pkg/analyzer/lib/src/task/options.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -427,16 +427,16 @@ class _AnalyzerTopLevelOptionsValidator extends _TopLevelOptionValidator {
427427
/// This includes the format of the `cannot-ignore` section, the format of
428428
/// values in the section, and whether each value is a valid string.
429429
class _CannotIgnoreOptionValidator extends OptionsValidator {
430-
/// Lazily populated set of error codes.
431-
static final Set<String> _errorCodes =
432-
errorCodeValues.map((DiagnosticCode code) => code.name).toSet();
430+
/// Lazily populated set of diagnostic code names.
431+
static final Set<String> _diagnosticCodes =
432+
diagnosticCodeValues.map((DiagnosticCode code) => code.name).toSet();
433433

434-
/// The error code names that existed, but were removed.
434+
/// The diagnostic code names that existed, but were removed.
435435
/// We don't want to report these, this breaks clients.
436436
// TODO(scheglov): https://github.com/flutter/flutter/issues/141576
437-
static const Set<String> _removedErrorCodes = {'MISSING_RETURN'};
437+
static const Set<String> _removedDiagnosticCodes = {'MISSING_RETURN'};
438438

439-
/// Lazily populated set of lint codes.
439+
/// Lazily populated set of lint code names.
440440
late final Set<String> _lintCodes =
441441
Registry.ruleRegistry.rules
442442
.map((rule) => rule.name.toUpperCase())
@@ -457,9 +457,9 @@ class _CannotIgnoreOptionValidator extends OptionsValidator {
457457
continue;
458458
}
459459
var upperCaseName = unignorableName.toUpperCase();
460-
if (!_errorCodes.contains(upperCaseName) &&
460+
if (!_diagnosticCodes.contains(upperCaseName) &&
461461
!_lintCodes.contains(upperCaseName) &&
462-
!_removedErrorCodes.contains(upperCaseName)) {
462+
!_removedDiagnosticCodes.contains(upperCaseName)) {
463463
reporter.atSourceSpan(
464464
unignorableNameNode.span,
465465
AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE,
@@ -677,16 +677,16 @@ class _ErrorFilterOptionValidator extends OptionsValidator {
677677
static final String legalValueString =
678678
legalValues.quotedAndCommaSeparatedWithAnd;
679679

680-
/// Lazily populated set of diagnostic codes.
680+
/// Lazily populated set of diagnostic code names.
681681
static final Set<String> _diagnosticCodes =
682-
errorCodeValues.map((DiagnosticCode code) => code.name).toSet();
682+
diagnosticCodeValues.map((DiagnosticCode code) => code.name).toSet();
683683

684-
/// The error code names that existed, but were removed.
684+
/// The diagnostic code names that existed, but were removed.
685685
/// We don't want to report these, this breaks clients.
686686
// TODO(scheglov): https://github.com/flutter/flutter/issues/141576
687-
static const Set<String> _removedErrorCodes = {'MISSING_RETURN'};
687+
static const Set<String> _removedDiagnosticCodes = {'MISSING_RETURN'};
688688

689-
/// Lazily populated set of lint codes.
689+
/// Lazily populated set of lint code names.
690690
late final Set<String> _lintCodes =
691691
Registry.ruleRegistry.rules
692692
.map((rule) => rule.name.toUpperCase())
@@ -704,7 +704,7 @@ class _ErrorFilterOptionValidator extends OptionsValidator {
704704
value = toUpperCase(k.value);
705705
if (!_diagnosticCodes.contains(value) &&
706706
!_lintCodes.contains(value) &&
707-
!_removedErrorCodes.contains(value)) {
707+
!_removedDiagnosticCodes.contains(value)) {
708708
reporter.atSourceSpan(
709709
k.span,
710710
AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE,

0 commit comments

Comments
 (0)