Deprecate errorCodeValues for diagnosticCodeValues
Work towards https://github.com/dart-lang/sdk/issues/60635 Change-Id: Ieea525a3f7260ea50e766feff0a0647fc0c33b4d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434526 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Paul Berry <paulberry@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
committed by
Commit Queue
parent
27b9397fbf
commit
97c49e7514
+1
-1
@@ -380,7 +380,7 @@ def _CheckAnalyzerFiles(input_api, output_api):
|
||||
|
||||
# Verify the "error fix status" file.
|
||||
code_files = [
|
||||
"pkg/analyzer/lib/src/error/error_code_values.g.dart",
|
||||
"pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart",
|
||||
"pkg/linter/lib/src/rules.dart",
|
||||
]
|
||||
|
||||
|
||||
+2
-2
@@ -74,8 +74,8 @@ class _ErrorProducer extends KeyValueProducer {
|
||||
@override
|
||||
Iterable<CompletionSuggestion> suggestions(YamlCompletionRequest request) {
|
||||
return [
|
||||
for (var error in errorCodeValues)
|
||||
identifier('${error.name.toLowerCase()}: '),
|
||||
for (var diagnostic in diagnosticCodeValues)
|
||||
identifier('${diagnostic.name.toLowerCase()}: '),
|
||||
for (var rule in Registry.ruleRegistry.rules)
|
||||
identifier('${rule.name}: '),
|
||||
];
|
||||
|
||||
@@ -157,7 +157,7 @@ class BulkFixProcessor {
|
||||
static final Map<DiagnosticCode, bool> _bulkFixableCodes = {};
|
||||
|
||||
static final Set<String> _diagnosticCodes =
|
||||
errorCodeValues.map((code) => code.name.toLowerCase()).toSet();
|
||||
diagnosticCodeValues.map((code) => code.name.toLowerCase()).toSet();
|
||||
|
||||
static final Set<String> _lintCodes =
|
||||
Registry.ruleRegistry.rules.map((rule) => rule.name).toSet();
|
||||
|
||||
@@ -57,7 +57,7 @@ String? verifyErrorFixStatus() {
|
||||
var lintRuleNames = {for (var lintCode in lintRuleCodes) lintCode.uniqueName};
|
||||
|
||||
var errorData = ErrorData();
|
||||
for (var code in errorCodeValues) {
|
||||
for (var code in diagnosticCodeValues) {
|
||||
var name = code.uniqueName;
|
||||
if (name.startsWith('TodoCode.')) {
|
||||
// To-do codes are ignored.
|
||||
@@ -99,10 +99,10 @@ String? verifyErrorFixStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
var errorCodeNames = {for (var code in errorCodeValues) code.uniqueName};
|
||||
var codeNames = {for (var code in diagnosticCodeValues) code.uniqueName};
|
||||
for (var key in statusInfo.keys) {
|
||||
if (key is String) {
|
||||
if (!errorCodeNames.contains(key) && !lintRuleNames.contains(key)) {
|
||||
if (!codeNames.contains(key) && !lintRuleNames.contains(key)) {
|
||||
errorData.entriesWithNoCode.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4685,7 +4685,8 @@ package:analyzer/diagnostic/diagnostic.dart:
|
||||
values (static getter: List<Severity>)
|
||||
warning (static getter: Severity)
|
||||
package:analyzer/error/error.dart:
|
||||
errorCodeValues (static getter: List<DiagnosticCode>)
|
||||
diagnosticCodeValues (static getter: List<DiagnosticCode>)
|
||||
errorCodeValues (static getter: List<DiagnosticCode>, deprecated)
|
||||
errorCodeByUniqueName (function: DiagnosticCode? Function(String))
|
||||
DiagnosticCode (class extends Object):
|
||||
new (constructor: DiagnosticCode Function({String? correctionMessage, bool hasPublishedDocs, bool isUnresolvedIdentifier, required String name, required String problemMessage, required String uniqueName}))
|
||||
|
||||
@@ -9,7 +9,7 @@ import 'dart:collection';
|
||||
|
||||
import 'package:_fe_analyzer_shared/src/base/errors.dart';
|
||||
import 'package:analyzer/diagnostic/diagnostic.dart';
|
||||
import 'package:analyzer/src/error/error_code_values.g.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic_code_values.g.dart';
|
||||
|
||||
export 'package:_fe_analyzer_shared/src/base/errors.dart'
|
||||
show
|
||||
@@ -26,7 +26,7 @@ export 'package:_fe_analyzer_shared/src/base/errors.dart'
|
||||
// ignore: deprecated_member_use
|
||||
ErrorType;
|
||||
export 'package:analyzer/src/dart/error/lint_codes.dart' show LintCode;
|
||||
export 'package:analyzer/src/error/error_code_values.g.dart';
|
||||
export 'package:analyzer/src/diagnostic/diagnostic_code_values.g.dart';
|
||||
|
||||
/// The lazy initialized map from [DiagnosticCode.uniqueName] to the
|
||||
/// [DiagnosticCode] instance.
|
||||
@@ -39,11 +39,11 @@ DiagnosticCode? errorCodeByUniqueName(String uniqueName) {
|
||||
return _uniqueNameToCodeMap[uniqueName];
|
||||
}
|
||||
|
||||
/// Return the map from [DiagnosticCode.uniqueName] to the [DiagnosticCode]
|
||||
/// instance for all [errorCodeValues].
|
||||
/// The map from [DiagnosticCode.uniqueName] to the [DiagnosticCode] instance
|
||||
/// for all [diagnosticCodeValues].
|
||||
HashMap<String, DiagnosticCode> _computeUniqueNameToCodeMap() {
|
||||
var result = HashMap<String, DiagnosticCode>();
|
||||
for (DiagnosticCode diagnosticCode in errorCodeValues) {
|
||||
for (DiagnosticCode diagnosticCode in diagnosticCodeValues) {
|
||||
var uniqueName = diagnosticCode.uniqueName;
|
||||
assert(() {
|
||||
if (result.containsKey(uniqueName)) {
|
||||
|
||||
@@ -302,25 +302,25 @@ final class AnalysisOptionsBuilder {
|
||||
var stringValues = cannotIgnore.whereType<String>().toSet();
|
||||
for (var severity in AnalysisOptionsFile.severities) {
|
||||
if (stringValues.contains(severity)) {
|
||||
// [severity] is a marker denoting all error codes with severity
|
||||
// [severity] is a marker denoting all diagnostic codes with severity
|
||||
// equal to [severity].
|
||||
stringValues.remove(severity);
|
||||
// Replace name like 'error' with error codes with this named
|
||||
// Replace name like 'error' with diagnostic codes with this named
|
||||
// severity.
|
||||
for (var e in errorCodeValues) {
|
||||
for (var d in diagnosticCodeValues) {
|
||||
// If the severity of [error] is also changed in this options file
|
||||
// to be [severity], we add [error] to the un-ignorable list.
|
||||
var processors = errorProcessors.where(
|
||||
(processor) => processor.code == e.name,
|
||||
(processor) => processor.code == d.name,
|
||||
);
|
||||
if (processors.isNotEmpty &&
|
||||
processors.first.severity?.displayName == severity) {
|
||||
unignorableDiagnosticCodeNames.add(e.name);
|
||||
unignorableDiagnosticCodeNames.add(d.name);
|
||||
continue;
|
||||
}
|
||||
// Otherwise, add [error] if its default severity is [severity].
|
||||
if (e.severity.displayName == severity) {
|
||||
unignorableDiagnosticCodeNames.add(e.name);
|
||||
if (d.severity.displayName == severity) {
|
||||
unignorableDiagnosticCodeNames.add(d.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -24,7 +24,7 @@ import 'package:analyzer/src/manifest/manifest_warning_code.dart';
|
||||
import 'package:analyzer/src/pubspec/pubspec_warning_code.dart';
|
||||
|
||||
@AnalyzerPublicApi(message: 'exported by lib/error/error.dart')
|
||||
const List<DiagnosticCode> errorCodeValues = [
|
||||
const List<DiagnosticCode> diagnosticCodeValues = [
|
||||
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR,
|
||||
AnalysisOptionsErrorCode.PARSE_ERROR,
|
||||
AnalysisOptionsWarningCode.ANALYSIS_OPTION_DEPRECATED,
|
||||
@@ -1125,3 +1125,7 @@ const List<DiagnosticCode> errorCodeValues = [
|
||||
WarningCode.UNUSED_SHOWN_NAME,
|
||||
WarningCode.URI_DOES_NOT_EXIST_IN_DOC_IMPORT,
|
||||
];
|
||||
|
||||
@AnalyzerPublicApi(message: 'exported by lib/error/error.dart')
|
||||
@Deprecated("Use 'diagnosticCodeValues' instead")
|
||||
List<DiagnosticCode> get errorCodeValues => diagnosticCodeValues;
|
||||
@@ -12,12 +12,13 @@ import 'package:analyzer/src/lint/registry.dart';
|
||||
|
||||
/// Used to validate the ignore comments in a single file.
|
||||
class IgnoreValidator {
|
||||
/// A list of known error codes used to ensure we don't over-report
|
||||
/// A list of known diagnostic codes used to ensure we don't over-report
|
||||
/// `unnecessary_ignore`s on error codes that may be contributed by a plugin.
|
||||
static final Set<String> _validErrorCodeNames =
|
||||
errorCodeValues.map((e) => e.name.toLowerCase()).toSet();
|
||||
static final Set<String> _validDiagnosticCodeNames =
|
||||
diagnosticCodeValues.map((d) => d.name.toLowerCase()).toSet();
|
||||
|
||||
/// Error codes used to report `unnecessary_ignore`s.
|
||||
/// Diagnostic codes used to report `unnecessary_ignore`s.
|
||||
///
|
||||
/// These codes are set when the `UnnecessaryIgnore` lint rule is instantiated and
|
||||
/// registered by the linter.
|
||||
static late DiagnosticCode unnecessaryIgnoreLocationLintCode;
|
||||
@@ -202,7 +203,7 @@ class IgnoreValidator {
|
||||
// If a code is not a lint or a recognized error,
|
||||
// don't report. (It could come from a plugin.)
|
||||
// TODO(pq): consider another diagnostic that reports undefined codes
|
||||
if (!_validErrorCodeNames.contains(name.toLowerCase())) continue;
|
||||
if (!_validDiagnosticCodeNames.contains(name.toLowerCase())) continue;
|
||||
} else {
|
||||
var state = rule.state;
|
||||
var since = state.since.toString();
|
||||
|
||||
@@ -427,16 +427,16 @@ class _AnalyzerTopLevelOptionsValidator extends _TopLevelOptionValidator {
|
||||
/// This includes the format of the `cannot-ignore` section, the format of
|
||||
/// values in the section, and whether each value is a valid string.
|
||||
class _CannotIgnoreOptionValidator extends OptionsValidator {
|
||||
/// Lazily populated set of error codes.
|
||||
static final Set<String> _errorCodes =
|
||||
errorCodeValues.map((DiagnosticCode code) => code.name).toSet();
|
||||
/// Lazily populated set of diagnostic code names.
|
||||
static final Set<String> _diagnosticCodes =
|
||||
diagnosticCodeValues.map((DiagnosticCode code) => code.name).toSet();
|
||||
|
||||
/// The error code names that existed, but were removed.
|
||||
/// The diagnostic code names that existed, but were removed.
|
||||
/// We don't want to report these, this breaks clients.
|
||||
// TODO(scheglov): https://github.com/flutter/flutter/issues/141576
|
||||
static const Set<String> _removedErrorCodes = {'MISSING_RETURN'};
|
||||
static const Set<String> _removedDiagnosticCodes = {'MISSING_RETURN'};
|
||||
|
||||
/// Lazily populated set of lint codes.
|
||||
/// Lazily populated set of lint code names.
|
||||
late final Set<String> _lintCodes =
|
||||
Registry.ruleRegistry.rules
|
||||
.map((rule) => rule.name.toUpperCase())
|
||||
@@ -457,9 +457,9 @@ class _CannotIgnoreOptionValidator extends OptionsValidator {
|
||||
continue;
|
||||
}
|
||||
var upperCaseName = unignorableName.toUpperCase();
|
||||
if (!_errorCodes.contains(upperCaseName) &&
|
||||
if (!_diagnosticCodes.contains(upperCaseName) &&
|
||||
!_lintCodes.contains(upperCaseName) &&
|
||||
!_removedErrorCodes.contains(upperCaseName)) {
|
||||
!_removedDiagnosticCodes.contains(upperCaseName)) {
|
||||
reporter.atSourceSpan(
|
||||
unignorableNameNode.span,
|
||||
AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE,
|
||||
@@ -677,16 +677,16 @@ class _ErrorFilterOptionValidator extends OptionsValidator {
|
||||
static final String legalValueString =
|
||||
legalValues.quotedAndCommaSeparatedWithAnd;
|
||||
|
||||
/// Lazily populated set of diagnostic codes.
|
||||
/// Lazily populated set of diagnostic code names.
|
||||
static final Set<String> _diagnosticCodes =
|
||||
errorCodeValues.map((DiagnosticCode code) => code.name).toSet();
|
||||
diagnosticCodeValues.map((DiagnosticCode code) => code.name).toSet();
|
||||
|
||||
/// The error code names that existed, but were removed.
|
||||
/// The diagnostic code names that existed, but were removed.
|
||||
/// We don't want to report these, this breaks clients.
|
||||
// TODO(scheglov): https://github.com/flutter/flutter/issues/141576
|
||||
static const Set<String> _removedErrorCodes = {'MISSING_RETURN'};
|
||||
static const Set<String> _removedDiagnosticCodes = {'MISSING_RETURN'};
|
||||
|
||||
/// Lazily populated set of lint codes.
|
||||
/// Lazily populated set of lint code names.
|
||||
late final Set<String> _lintCodes =
|
||||
Registry.ruleRegistry.rules
|
||||
.map((rule) => rule.name.toUpperCase())
|
||||
@@ -704,7 +704,7 @@ class _ErrorFilterOptionValidator extends OptionsValidator {
|
||||
value = toUpperCase(k.value);
|
||||
if (!_diagnosticCodes.contains(value) &&
|
||||
!_lintCodes.contains(value) &&
|
||||
!_removedErrorCodes.contains(value)) {
|
||||
!_removedDiagnosticCodes.contains(value)) {
|
||||
reporter.atSourceSpan(
|
||||
k.span,
|
||||
AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE,
|
||||
|
||||
@@ -34,7 +34,7 @@ class ErrorCodeValuesTest {
|
||||
// split the codes by class is to find all of the classes that need to be
|
||||
// checked against `errorCodeValues`.
|
||||
var errorTypeMap = <Type, List<DiagnosticCode>>{};
|
||||
for (DiagnosticCode code in errorCodeValues) {
|
||||
for (DiagnosticCode code in diagnosticCodeValues) {
|
||||
Type type = code.runtimeType;
|
||||
errorTypeMap.putIfAbsent(type, () => <DiagnosticCode>[]).add(code);
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ class VerifyDiagnosticsTest {
|
||||
// _all_ codes with the same name are also marked that way.
|
||||
var nameToCodeMap = <String, List<DiagnosticCode>>{};
|
||||
var nameToPublishedMap = <String, bool>{};
|
||||
for (var code in errorCodeValues) {
|
||||
for (var code in diagnosticCodeValues) {
|
||||
var name = code.name;
|
||||
nameToCodeMap.putIfAbsent(name, () => []).add(code);
|
||||
nameToPublishedMap[name] =
|
||||
|
||||
@@ -143,19 +143,19 @@ _CommentInfo _extractCommentInfo(FieldDeclaration fieldDeclaration) {
|
||||
/// Computes a map from class name to a list of all the diagnostic codes defined
|
||||
/// by that class.
|
||||
///
|
||||
/// Uses the analyzer's global variable `errorCodeValues` to find all the error
|
||||
/// codes.
|
||||
/// Uses the analyzer's global variable `diagnosticCodeValues` to find all the
|
||||
/// diagnostic codes.
|
||||
Map<String, List<DiagnosticCode>> _findDiagnosticCodesByClass() {
|
||||
var codesByClass = <String, List<DiagnosticCode>>{};
|
||||
for (var errorCode in errorCodeValues) {
|
||||
if (errorCode is ScannerErrorCode) {
|
||||
continue; // Will deal with later
|
||||
for (var diagnostic in diagnosticCodeValues) {
|
||||
if (diagnostic is ScannerErrorCode) {
|
||||
continue; // Will deal with later.
|
||||
}
|
||||
if (errorCode is TodoCode) {
|
||||
if (diagnostic is TodoCode) {
|
||||
continue; // It's not worth converting these to YAML.
|
||||
}
|
||||
var className = errorCode.runtimeType.toString();
|
||||
(codesByClass[className] ??= []).add(errorCode);
|
||||
var className = diagnostic.runtimeType.toString();
|
||||
(codesByClass[className] ??= []).add(diagnostic);
|
||||
}
|
||||
return codesByClass;
|
||||
}
|
||||
|
||||
@@ -56,10 +56,10 @@ List<GeneratedContent> _analyzerGeneratedFiles() {
|
||||
codeGenerator.generate();
|
||||
return codeGenerator.out.toString();
|
||||
}),
|
||||
GeneratedFile('lib/src/error/error_code_values.g.dart', (
|
||||
GeneratedFile('lib/src/diagnostic/diagnostic_code_values.g.dart', (
|
||||
String pkgPath,
|
||||
) async {
|
||||
var codeGenerator = _ErrorCodeValuesGenerator(generatedCodes);
|
||||
var codeGenerator = _DiagnosticCodeValuesGenerator(generatedCodes);
|
||||
codeGenerator.generate();
|
||||
return codeGenerator.out.toString();
|
||||
}),
|
||||
@@ -188,7 +188,7 @@ library;
|
||||
}
|
||||
}
|
||||
|
||||
class _ErrorCodeValuesGenerator {
|
||||
class _DiagnosticCodeValuesGenerator {
|
||||
final List<String> generatedCodes;
|
||||
|
||||
final StringBuffer out = StringBuffer('''
|
||||
@@ -210,7 +210,7 @@ class _ErrorCodeValuesGenerator {
|
||||
// ignore_for_file: deprecated_member_use_from_same_package
|
||||
''');
|
||||
|
||||
_ErrorCodeValuesGenerator(this.generatedCodes);
|
||||
_DiagnosticCodeValuesGenerator(this.generatedCodes);
|
||||
|
||||
void generate() {
|
||||
// The scanner error codes are not yet being generated, so we need to add
|
||||
@@ -248,11 +248,19 @@ import 'package:analyzer/src/pubspec/pubspec_warning_code.dart';
|
||||
out.writeln(
|
||||
"@AnalyzerPublicApi(message: 'exported by lib/error/error.dart')",
|
||||
);
|
||||
out.writeln('const List<DiagnosticCode> errorCodeValues = [');
|
||||
out.writeln('const List<DiagnosticCode> diagnosticCodeValues = [');
|
||||
for (var name in generatedCodes) {
|
||||
out.writeln(' $name,');
|
||||
}
|
||||
out.writeln('];');
|
||||
out.writeln();
|
||||
out.writeln(
|
||||
"@AnalyzerPublicApi(message: 'exported by lib/error/error.dart')",
|
||||
);
|
||||
out.writeln('@Deprecated("Use \'diagnosticCodeValues\' instead")');
|
||||
out.writeln(
|
||||
'List<DiagnosticCode> get errorCodeValues => diagnosticCodeValues;',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user