DAS: Re-map other LintNames-based maps
These maps can now just be oriented around the LintCodes.
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Ie4e88c61a4d55dbd6d184541cc80aa4893d2ef69
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377267
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
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 bb7543d..d5be449 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
@@ -51,6 +51,7 @@
import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/change_builder/conflicting_edit_exception.dart';
+import 'package:linter/src/rules/directives_ordering.dart';
import 'package:yaml/yaml.dart';
/// A fix producer that produces changes that will fix multiple diagnostics in
@@ -65,7 +66,7 @@
class BulkFixProcessor {
/// A list of lint codes that can be run on parsed code. These lints will all
/// be run when the `--syntactic-fixes` flag is specified.
- static const List<String> syntacticLintCodes = [
+ static const List<String> _syntacticLintCodes = [
LintNames.prefer_generic_function_type_aliases,
LintNames.slash_for_doc_comments,
LintNames.unnecessary_const,
@@ -568,7 +569,7 @@
var unit = currentUnit.unit;
var nodeRegistry = NodeLintRegistry(false);
var context = LinterContextWithParsedResults(allUnits, currentUnit);
- var lintRules = syntacticLintCodes
+ var lintRules = _syntacticLintCodes
.map((name) => Registry.ruleRegistry.getRule(name))
.nonNulls;
for (var lintRule in lintRules) {
@@ -673,8 +674,7 @@
for (var error in _filterErrors(analysisOptions, unit.errors)) {
var errorCode = error.errorCode;
if (errorCode is LintCode) {
- var lintName = errorCode.name;
- if (lintName == LintNames.directives_ordering) {
+ if (DirectivesOrdering.allCodes.contains(errorCode)) {
directivesOrderingError = error;
break;
}
@@ -746,7 +746,7 @@
if (isCancelled) {
return;
}
- var multiGenerators = FixProcessor.lintMultiProducerMap[codeName];
+ var multiGenerators = FixProcessor.lintMultiProducerMap[errorCode];
if (multiGenerators != null) {
for (var multiGenerator in multiGenerators) {
var multiProducer = multiGenerator(context: context);
@@ -798,7 +798,7 @@
var codeName = errorCode.name;
try {
if (errorCode is LintCode) {
- var generators = FixProcessor.parseLintProducerMap[codeName] ?? [];
+ var generators = FixProcessor.parseLintProducerMap[errorCode] ?? [];
await _bulkApply(generators, codeName, context, parsedOnly: true);
if (isCancelled) {
return;
@@ -854,14 +854,14 @@
}
Future<void> _generateFix(CorrectionProducerContext context,
- CorrectionProducer producer, String code) async {
+ CorrectionProducer producer, String codeName) async {
int computeChangeHash() => (builder as ChangeBuilderImpl).changeHash;
var oldHash = computeChangeHash();
await _applyProducer(producer);
var newHash = computeChangeHash();
if (newHash != oldHash) {
- changeMap.add(context.path, code.toLowerCase());
+ changeMap.add(context.path, codeName.toLowerCase());
}
}
@@ -887,8 +887,7 @@
if (errorCode == WarningCode.DUPLICATE_IMPORT ||
errorCode == HintCode.UNNECESSARY_IMPORT ||
errorCode == WarningCode.UNUSED_IMPORT ||
- (errorCode is LintCode &&
- errorCode.name == LintNames.directives_ordering)) {
+ (DirectivesOrdering.allCodes.contains(errorCode))) {
return true;
}
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart
index 4229ad9..72895bc 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart
@@ -16,6 +16,7 @@
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
+import 'package:linter/src/rules/diagnostic_describe_all_properties.dart';
class AddDiagnosticPropertyReference extends ResolvedCorrectionProducer {
AddDiagnosticPropertyReference({required super.context});
@@ -337,8 +338,8 @@
}
}
- /// Returns a list of all the [AnalysisError]'s of type
- /// [LintNames.diagnostic_describe_all_properties] fpr the given [declaration].
+ /// Returns a list of all the [AnalysisError]s of type
+ /// [DiagnosticDescribeAllProperties.code] fpr the given [declaration].
List<AnalysisError> _getAllDiagnosticsInClass(ClassDeclaration declaration) {
var propertyErrors = <AnalysisError>[];
var startOffset = declaration.offset;
@@ -346,7 +347,7 @@
for (var error in unitResult.errors) {
var errorCode = error.errorCode;
if (errorCode.type == ErrorType.LINT &&
- errorCode.name == LintNames.diagnostic_describe_all_properties &&
+ errorCode == DiagnosticDescribeAllProperties.code &&
error.offset > startOffset &&
error.offset < endOffset) {
propertyErrors.add(error);
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_comparison.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_comparison.dart
index 27011a0..519e5a8 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/remove_comparison.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_comparison.dart
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/services/correction/fix.dart';
-import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
@@ -13,6 +12,7 @@
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';
+import 'package:linter/src/rules/avoid_null_checks_in_equality_operators.dart';
class RemoveComparison extends ResolvedCorrectionProducer {
@override
@@ -35,7 +35,7 @@
CorrectionApplicability get applicability =>
CorrectionApplicability.automatically;
- /// Return `true` if the condition will always return `false`.
+ /// Whether the condition will always return `false`.
bool get _conditionIsFalse {
var errorCode = (diagnostic as AnalysisError).errorCode;
return errorCode == WarningCode.UNNECESSARY_NAN_COMPARISON_FALSE ||
@@ -43,13 +43,13 @@
errorCode == WarningCode.UNNECESSARY_TYPE_CHECK_FALSE;
}
- /// Return `true` if the condition will always return `true`.
+ /// Whether the condition will always return `true`.
bool get _conditionIsTrue {
var errorCode = (diagnostic as AnalysisError).errorCode;
return errorCode == WarningCode.UNNECESSARY_NAN_COMPARISON_TRUE ||
errorCode == WarningCode.UNNECESSARY_NULL_COMPARISON_TRUE ||
errorCode == WarningCode.UNNECESSARY_TYPE_CHECK_TRUE ||
- errorCode.name == LintNames.avoid_null_checks_in_equality_operators;
+ errorCode == AvoidNullChecksInEqualityOperators.code;
}
@override
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_decorated_box.dart b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_decorated_box.dart
index 4d173a7..801c09a 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_decorated_box.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_decorated_box.dart
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/services/correction/fix.dart';
-import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
@@ -12,6 +11,7 @@
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';
+import 'package:linter/src/rules/use_decorated_box.dart';
class ReplaceWithDecoratedBox extends ResolvedCorrectionProducer {
ReplaceWithDecoratedBox({required super.context});
@@ -116,7 +116,7 @@
return unitResult.errors.any((error) {
var errorCode = error.errorCode;
return errorCode.type == ErrorType.LINT &&
- errorCode.name == LintNames.use_decorated_box &&
+ errorCode == UseDecoratedBox.code &&
error.offset == constructorName.offset &&
error.length == constructorName.length;
});
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index 4eab107..82bc26d 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -240,7 +240,6 @@
import 'package:analysis_server/src/services/correction/dart/wrap_in_text.dart';
import 'package:analysis_server/src/services/correction/dart/wrap_in_unawaited.dart';
import 'package:analysis_server/src/services/correction/fix_processor.dart';
-import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
import 'package:analysis_server_plugin/edit/fix/fix.dart';
@@ -283,9 +282,11 @@
import 'package:linter/src/rules/cascade_invocations.dart';
import 'package:linter/src/rules/cast_nullable_to_non_nullable.dart';
import 'package:linter/src/rules/combinators_ordering.dart';
+import 'package:linter/src/rules/comment_references.dart';
import 'package:linter/src/rules/constant_identifier_names.dart';
import 'package:linter/src/rules/curly_braces_in_flow_control_structures.dart';
import 'package:linter/src/rules/dangling_library_doc_comments.dart';
+import 'package:linter/src/rules/deprecated_member_use_from_same_package.dart';
import 'package:linter/src/rules/diagnostic_describe_all_properties.dart';
import 'package:linter/src/rules/directives_ordering.dart';
import 'package:linter/src/rules/discarded_futures.dart';
@@ -390,15 +391,15 @@
import 'package:linter/src/rules/use_super_parameters.dart';
final _builtInLintMultiProducers = {
- LintNames.deprecated_member_use_from_same_package: [
- DataDriven.new,
- ],
- LintNames.deprecated_member_use_from_same_package_with_message: [
- DataDriven.new,
- ],
- LintNames.comment_references: [
+ CommentReferences.code: [
ImportLibrary.forType,
],
+ DeprecatedMemberUseFromSamePackage.code: [
+ DataDriven.new,
+ ],
+ DeprecatedMemberUseFromSamePackage.codeWithMessage: [
+ DataDriven.new,
+ ],
};
final _builtInLintProducers = <LintCode, List<ProducerGenerator>>{
@@ -1978,23 +1979,23 @@
],
};
-final _builtInParseLintProducers = <String, List<ProducerGenerator>>{
- LintNames.prefer_generic_function_type_aliases: [
+final _builtInParseLintProducers = <LintCode, List<ProducerGenerator>>{
+ PreferGenericFunctionTypeAliases.code: [
ConvertToGenericFunctionSyntax.new,
],
- LintNames.slash_for_doc_comments: [
+ SlashForDocComments.code: [
ConvertDocumentationIntoLine.new,
],
- LintNames.unnecessary_const: [
+ UnnecessaryConst.code: [
RemoveUnnecessaryConst.new,
],
- LintNames.unnecessary_new: [
+ UnnecessaryNew.code: [
RemoveUnnecessaryNew.new,
],
- LintNames.unnecessary_string_escapes: [
+ UnnecessaryStringEscapes.code: [
RemoveUnnecessaryStringEscape.new,
],
- LintNames.use_function_type_syntax_for_parameters: [
+ UseFunctionTypeSyntaxForParameters.code: [
ConvertToGenericFunctionSyntax.new,
],
};
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_processor.dart b/pkg/analysis_server/lib/src/services/correction/fix_processor.dart
index 92f6d3e..b851cc9 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_processor.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_processor.dart
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/services/correction/bulk_fix_processor.dart';
-import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
import 'package:analysis_server_plugin/edit/fix/fix.dart';
@@ -28,8 +27,8 @@
/// Cached results of [canBulkFix].
static final Map<ErrorCode, bool> _bulkFixableErrorCodes = {};
- static final Map<String, List<MultiProducerGenerator>> lintMultiProducerMap =
- {};
+ static final Map<LintCode, List<MultiProducerGenerator>>
+ lintMultiProducerMap = {};
/// A map from the names of lint rules to a list of the generators that are
/// used to create correction producers.
@@ -60,7 +59,7 @@
/// A map from error codes to a list of fix generators that work with only
/// parsed results.
- static final Map<String, List<ProducerGenerator>> parseLintProducerMap = {};
+ static final Map<LintCode, List<ProducerGenerator>> parseLintProducerMap = {};
/// A set of generators that are used to create correction producers that
/// produce corrections that ignore diagnostics locally.
@@ -130,9 +129,8 @@
List<ProducerGenerator>? generators;
List<MultiProducerGenerator>? multiGenerators;
if (errorCode is LintCode) {
- var uniqueLintName = errorCode.uniqueLintName;
generators = lintProducerMap[errorCode];
- multiGenerators = lintMultiProducerMap[uniqueLintName];
+ multiGenerators = lintMultiProducerMap[errorCode];
} else {
generators = nonLintProducerMap[errorCode];
multiGenerators = nonLintMultiProducerMap[errorCode];
@@ -177,7 +175,7 @@
return true;
}
- return FixProcessor.lintMultiProducerMap.containsKey(errorCode.name);
+ return FixProcessor.lintMultiProducerMap.containsKey(errorCode);
}
var producers = FixProcessor.nonLintProducerMap[errorCode];
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 d7ebe4b..9663eb5 100644
--- a/pkg/analysis_server/tool/presubmit/verify_error_fix_status.dart
+++ b/pkg/analysis_server/tool/presubmit/verify_error_fix_status.dart
@@ -190,9 +190,8 @@
bool get hasFix {
var self = this;
if (self is LintCode) {
- var lintName = self.name;
return FixProcessor.lintProducerMap.containsKey(self) ||
- FixProcessor.lintMultiProducerMap.containsKey(lintName);
+ FixProcessor.lintMultiProducerMap.containsKey(self);
}
return FixProcessor.nonLintProducerMap.containsKey(self) ||
FixProcessor.nonLintMultiProducerMap.containsKey(self) ||
diff --git a/pkg/analyzer/test/src/dart/micro/simple_file_resolver_test.dart b/pkg/analyzer/test/src/dart/micro/simple_file_resolver_test.dart
index 58c7d3f..728588b 100644
--- a/pkg/analyzer/test/src/dart/micro/simple_file_resolver_test.dart
+++ b/pkg/analyzer/test/src/dart/micro/simple_file_resolver_test.dart
@@ -11,7 +11,7 @@
import 'package:analyzer/src/dart/micro/resolve_file.dart';
import 'package:analyzer/src/dart/micro/utils.dart';
import 'package:analyzer/src/error/codes.dart';
-import 'package:analyzer/src/lint/registry.dart';
+import 'package:linter/src/rules/omit_local_variable_types.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -928,15 +928,13 @@
- omit_local_variable_types
''');
- var rule = Registry.ruleRegistry.getRule('omit_local_variable_types')!;
-
await assertErrorsInCode(r'''
main() {
int a = 0;
a;
}
''', [
- error(rule.lintCode, 11, 3),
+ error(OmitLocalVariableTypes.code, 11, 3),
]);
}
diff --git a/pkg/linter/lib/src/rules/directives_ordering.dart b/pkg/linter/lib/src/rules/directives_ordering.dart
index c544430..061b6c9 100644
--- a/pkg/linter/lib/src/rules/directives_ordering.dart
+++ b/pkg/linter/lib/src/rules/directives_ordering.dart
@@ -173,6 +173,13 @@
'directives_ordering', "Place 'package:' {0}s before relative {0}s.",
correctionMessage: 'Try sorting the directives.');
+ static const allCodes = [
+ DirectivesOrdering.dartDirectiveGoFirst,
+ DirectivesOrdering.directiveSectionOrderedAlphabetically,
+ DirectivesOrdering.exportDirectiveAfterImportDirectives,
+ DirectivesOrdering.packageDirectiveBeforeRelative,
+ ];
+
DirectivesOrdering()
: super(
name: 'directives_ordering',