diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 30eaaca5bcf..1df59d9ba67 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -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", ] diff --git a/pkg/analysis_server/lib/src/services/completion/yaml/analysis_options_generator.dart b/pkg/analysis_server/lib/src/services/completion/yaml/analysis_options_generator.dart index aca7103e532..1dba885e2a0 100644 --- a/pkg/analysis_server/lib/src/services/completion/yaml/analysis_options_generator.dart +++ b/pkg/analysis_server/lib/src/services/completion/yaml/analysis_options_generator.dart @@ -74,8 +74,8 @@ class _ErrorProducer extends KeyValueProducer { @override Iterable 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}: '), ]; diff --git a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart index e729db696a5..24e1906d94b 100644 --- a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart +++ b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart @@ -157,7 +157,7 @@ class BulkFixProcessor { static final Map _bulkFixableCodes = {}; static final Set _diagnosticCodes = - errorCodeValues.map((code) => code.name.toLowerCase()).toSet(); + diagnosticCodeValues.map((code) => code.name.toLowerCase()).toSet(); static final Set _lintCodes = Registry.ruleRegistry.rules.map((rule) => rule.name).toSet(); diff --git a/pkg/analysis_server/tool/presubmit/verify_error_fix_status.dart b/pkg/analysis_server/tool/presubmit/verify_error_fix_status.dart index 2b67cc50f99..6b893e3815d 100644 --- a/pkg/analysis_server/tool/presubmit/verify_error_fix_status.dart +++ b/pkg/analysis_server/tool/presubmit/verify_error_fix_status.dart @@ -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); } } diff --git a/pkg/analyzer/api.txt b/pkg/analyzer/api.txt index 2b69f4566a5..f62afe4d881 100644 --- a/pkg/analyzer/api.txt +++ b/pkg/analyzer/api.txt @@ -4685,7 +4685,8 @@ package:analyzer/diagnostic/diagnostic.dart: values (static getter: List) warning (static getter: Severity) package:analyzer/error/error.dart: - errorCodeValues (static getter: List) + diagnosticCodeValues (static getter: List) + errorCodeValues (static getter: List, 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})) diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart index 57a99f9fa1d..9088b76e131 100644 --- a/pkg/analyzer/lib/error/error.dart +++ b/pkg/analyzer/lib/error/error.dart @@ -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 _computeUniqueNameToCodeMap() { var result = HashMap(); - for (DiagnosticCode diagnosticCode in errorCodeValues) { + for (DiagnosticCode diagnosticCode in diagnosticCodeValues) { var uniqueName = diagnosticCode.uniqueName; assert(() { if (result.containsKey(uniqueName)) { diff --git a/pkg/analyzer/lib/src/dart/analysis/analysis_options.dart b/pkg/analyzer/lib/src/dart/analysis/analysis_options.dart index 11660523d83..251892331d9 100644 --- a/pkg/analyzer/lib/src/dart/analysis/analysis_options.dart +++ b/pkg/analyzer/lib/src/dart/analysis/analysis_options.dart @@ -302,25 +302,25 @@ final class AnalysisOptionsBuilder { var stringValues = cannotIgnore.whereType().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); } } } diff --git a/pkg/analyzer/lib/src/error/error_code_values.g.dart b/pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart similarity index 99% rename from pkg/analyzer/lib/src/error/error_code_values.g.dart rename to pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart index f8a2d532219..d294c0a042d 100644 --- a/pkg/analyzer/lib/src/error/error_code_values.g.dart +++ b/pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart @@ -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 errorCodeValues = [ +const List diagnosticCodeValues = [ AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR, AnalysisOptionsErrorCode.PARSE_ERROR, AnalysisOptionsWarningCode.ANALYSIS_OPTION_DEPRECATED, @@ -1125,3 +1125,7 @@ const List 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 get errorCodeValues => diagnosticCodeValues; diff --git a/pkg/analyzer/lib/src/error/ignore_validator.dart b/pkg/analyzer/lib/src/error/ignore_validator.dart index 2432c59a5cd..a67578a3812 100644 --- a/pkg/analyzer/lib/src/error/ignore_validator.dart +++ b/pkg/analyzer/lib/src/error/ignore_validator.dart @@ -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 _validErrorCodeNames = - errorCodeValues.map((e) => e.name.toLowerCase()).toSet(); + static final Set _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(); diff --git a/pkg/analyzer/lib/src/task/options.dart b/pkg/analyzer/lib/src/task/options.dart index 5647bd987c3..109fc463346 100644 --- a/pkg/analyzer/lib/src/task/options.dart +++ b/pkg/analyzer/lib/src/task/options.dart @@ -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 _errorCodes = - errorCodeValues.map((DiagnosticCode code) => code.name).toSet(); + /// Lazily populated set of diagnostic code names. + static final Set _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 _removedErrorCodes = {'MISSING_RETURN'}; + static const Set _removedDiagnosticCodes = {'MISSING_RETURN'}; - /// Lazily populated set of lint codes. + /// Lazily populated set of lint code names. late final Set _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 _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 _removedErrorCodes = {'MISSING_RETURN'}; + static const Set _removedDiagnosticCodes = {'MISSING_RETURN'}; - /// Lazily populated set of lint codes. + /// Lazily populated set of lint code names. late final Set _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, diff --git a/pkg/analyzer/test/src/task/options_test.dart b/pkg/analyzer/test/src/task/options_test.dart index f332fb104fe..36e21a1fb34 100644 --- a/pkg/analyzer/test/src/task/options_test.dart +++ b/pkg/analyzer/test/src/task/options_test.dart @@ -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 = >{}; - for (DiagnosticCode code in errorCodeValues) { + for (DiagnosticCode code in diagnosticCodeValues) { Type type = code.runtimeType; errorTypeMap.putIfAbsent(type, () => []).add(code); } diff --git a/pkg/analyzer/test/verify_diagnostics_test.dart b/pkg/analyzer/test/verify_diagnostics_test.dart index ac4c8f2dec8..7fc68c55b1e 100644 --- a/pkg/analyzer/test/verify_diagnostics_test.dart +++ b/pkg/analyzer/test/verify_diagnostics_test.dart @@ -484,7 +484,7 @@ class VerifyDiagnosticsTest { // _all_ codes with the same name are also marked that way. var nameToCodeMap = >{}; var nameToPublishedMap = {}; - for (var code in errorCodeValues) { + for (var code in diagnosticCodeValues) { var name = code.name; nameToCodeMap.putIfAbsent(name, () => []).add(code); nameToPublishedMap[name] = diff --git a/pkg/analyzer/tool/messages/extract_errors_to_yaml.dart b/pkg/analyzer/tool/messages/extract_errors_to_yaml.dart index d8105b40381..ce9ffcc621d 100644 --- a/pkg/analyzer/tool/messages/extract_errors_to_yaml.dart +++ b/pkg/analyzer/tool/messages/extract_errors_to_yaml.dart @@ -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> _findDiagnosticCodesByClass() { var codesByClass = >{}; - 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; } diff --git a/pkg/analyzer/tool/messages/generate.dart b/pkg/analyzer/tool/messages/generate.dart index 54a1db1528a..b035ec8cde3 100644 --- a/pkg/analyzer/tool/messages/generate.dart +++ b/pkg/analyzer/tool/messages/generate.dart @@ -56,10 +56,10 @@ List _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 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 errorCodeValues = ['); + out.writeln('const List 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 get errorCodeValues => diagnosticCodeValues;', + ); } }