From beee8641965ef77e250a2617bbf6366b6e98487e Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Mon, 22 Jul 2024 06:43:58 +0000 Subject: [PATCH] DAS: Move away from LintNames, now that LintRules have LintCodes Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try Change-Id: Id52cbf9fe95f9f2aaff80baaa10b2abbdba85f9e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376560 Commit-Queue: Samuel Rawlins Reviewed-by: Brian Wilkerson Reviewed-by: Phil Quitslund --- .../lib/plugin/edit/assist/assist_dart.dart | 3 +- .../lib/src/analysis_server.dart | 3 +- .../lib/src/cider/assists.dart | 3 +- .../lib/src/services/correction/assist.dart | 3 +- .../services/correction/assist_internal.dart | 10 +- .../correction/bulk_fix_processor.dart | 2 +- .../src/services/correction/fix_internal.dart | 459 ++++++++++++------ .../services/correction/fix_processor.dart | 13 +- .../test/src/cider/assists_test.dart | 3 +- .../correction/assist/assist_processor.dart | 3 +- .../correction/fix/fix_processor.dart | 2 +- .../fix/fix_processor_map_test.dart | 15 +- .../presubmit/verify_error_fix_status.dart | 4 +- .../avoid_renaming_method_parameters.dart | 4 +- 14 files changed, 358 insertions(+), 169 deletions(-) diff --git a/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart b/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart index 532781de9fdf..9dc89ffdac07 100644 --- a/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart +++ b/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart @@ -5,6 +5,7 @@ import 'package:analysis_server/src/services/correction/fix_processor.dart'; import 'package:analysis_server_plugin/src/correction/change_workspace.dart'; import 'package:analyzer/dart/analysis/results.dart'; +import 'package:analyzer/error/error.dart'; import 'package:analyzer/instrumentation/service.dart'; /// An object used to provide context information for Dart assist contributors. @@ -17,7 +18,7 @@ abstract class DartAssistContext { /// A mapping of [ProducerGenerator]s to the set of lint names with which they /// are associated (can fix). - Map> get producerGeneratorsForLintRules; + Map> get producerGeneratorsForLintRules; /// The resolution result in which assist operates. ResolvedUnitResult get resolveResult; diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart index cb97d990cf71..ce9a199d8f73 100644 --- a/pkg/analysis_server/lib/src/analysis_server.dart +++ b/pkg/analysis_server/lib/src/analysis_server.dart @@ -48,6 +48,7 @@ import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/analysis/session.dart'; import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/error/error.dart'; import 'package:analyzer/exception/exception.dart'; import 'package:analyzer/file_system/file_system.dart'; import 'package:analyzer/file_system/overlay_file_system.dart'; @@ -236,7 +237,7 @@ abstract class AnalysisServer { /// A mapping of [ProducerGenerator]s to the set of lint names with which they /// are associated (can fix). - final Map> producerGeneratorsForLintRules; + final Map> producerGeneratorsForLintRules; AnalysisServer( this.options, diff --git a/pkg/analysis_server/lib/src/cider/assists.dart b/pkg/analysis_server/lib/src/cider/assists.dart index 61f193132b89..8c09559962cd 100644 --- a/pkg/analysis_server/lib/src/cider/assists.dart +++ b/pkg/analysis_server/lib/src/cider/assists.dart @@ -8,6 +8,7 @@ import 'package:analysis_server/src/services/correction/assist_internal.dart'; import 'package:analysis_server/src/services/correction/fix_processor.dart'; import 'package:analysis_server_plugin/src/correction/dart_change_workspace.dart'; import 'package:analyzer/dart/analysis/session.dart'; +import 'package:analyzer/error/error.dart'; import 'package:analyzer/instrumentation/service.dart'; import 'package:analyzer/src/dart/analysis/performance_logger.dart'; import 'package:analyzer/src/dart/micro/resolve_file.dart'; @@ -18,7 +19,7 @@ class CiderAssistsComputer { /// A mapping of [ProducerGenerator]s to the set of lint names with which they /// are associated (can fix). - final Map> _producerGeneratorsForLintRules; + final Map> _producerGeneratorsForLintRules; CiderAssistsComputer( this._logger, this._fileResolver, this._producerGeneratorsForLintRules); diff --git a/pkg/analysis_server/lib/src/services/correction/assist.dart b/pkg/analysis_server/lib/src/services/correction/assist.dart index b1b97de1c5e1..6c442cd96ffc 100644 --- a/pkg/analysis_server/lib/src/services/correction/assist.dart +++ b/pkg/analysis_server/lib/src/services/correction/assist.dart @@ -6,6 +6,7 @@ import 'package:analysis_server/plugin/edit/assist/assist_dart.dart'; import 'package:analysis_server/src/services/correction/fix_processor.dart'; import 'package:analysis_server_plugin/src/correction/change_workspace.dart'; import 'package:analyzer/dart/analysis/results.dart'; +import 'package:analyzer/error/error.dart'; import 'package:analyzer/instrumentation/service.dart'; import 'package:analyzer_plugin/utilities/assist/assist.dart'; @@ -21,7 +22,7 @@ class DartAssistContextImpl implements DartAssistContext { final ResolvedUnitResult resolveResult; @override - final Map> producerGeneratorsForLintRules; + final Map> producerGeneratorsForLintRules; @override final int selectionOffset; diff --git a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart index a6d03fb658b8..50179b7cd90d 100644 --- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart @@ -73,6 +73,7 @@ import 'package:analysis_server/src/services/correction/dart/surround_with.dart' import 'package:analysis_server/src/services/correction/dart/use_curly_braces.dart'; import 'package:analysis_server/src/services/correction/fix_processor.dart'; import 'package:analysis_server_plugin/edit/dart/correction_producer.dart'; +import 'package:analyzer/error/error.dart'; import 'package:analyzer/src/dart/ast/utilities.dart'; import 'package:analyzer/src/generated/java_core.dart'; import 'package:analyzer/src/util/file_paths.dart'; @@ -213,7 +214,8 @@ class AssistProcessor { for (var generator in _generators) { if (!_generatorAppliesToAnyLintRule( generator, - _assistContext.producerGeneratorsForLintRules[generator] ?? {}, + _assistContext.producerGeneratorsForLintRules[generator] ?? + {}, )) { var producer = generator(context: context); await compute(producer); @@ -231,7 +233,7 @@ class AssistProcessor { /// [errorCodes]. bool _generatorAppliesToAnyLintRule( ProducerGenerator generator, - Set errorCodes, + Set errorCodes, ) { var selectionEnd = _assistContext.selectionOffset + _assistContext.selectionLength; @@ -247,7 +249,7 @@ class AssistProcessor { if (_assistContext.resolveResult.path == errorSource.fullName) { if (fileOffset >= error.offset && fileOffset <= error.offset + error.length) { - if (errorCodes.contains(error.errorCode.name)) { + if (errorCodes.contains(error.errorCode)) { return true; } } @@ -256,7 +258,7 @@ class AssistProcessor { return false; } - static Map> computeLintRuleMap() => { + static Map> computeLintRuleMap() => { for (var generator in _generators) generator: { for (var MapEntry(key: lintName, value: generators) 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 bf0b5cb57168..bb7543d2030b 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 @@ -741,7 +741,7 @@ class BulkFixProcessor { var codeName = errorCode.name; try { if (errorCode is LintCode) { - var generators = FixProcessor.lintProducerMap[codeName] ?? []; + var generators = FixProcessor.lintProducerMap[errorCode] ?? []; await _bulkApply(generators, codeName, context); if (isCancelled) { return; 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 aaf879138788..2bde2f365e32 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart @@ -252,6 +252,142 @@ import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_core import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart'; import 'package:analyzer_plugin/utilities/change_builder/conflicting_edit_exception.dart'; import 'package:analyzer_plugin/utilities/fixes/fixes.dart'; +import 'package:linter/src/rules/always_declare_return_types.dart'; +import 'package:linter/src/rules/always_put_control_body_on_new_line.dart'; +import 'package:linter/src/rules/always_put_required_named_parameters_first.dart'; +import 'package:linter/src/rules/always_specify_types.dart'; +import 'package:linter/src/rules/always_use_package_imports.dart'; +import 'package:linter/src/rules/annotate_overrides.dart'; +import 'package:linter/src/rules/annotate_redeclares.dart'; +import 'package:linter/src/rules/avoid_annotating_with_dynamic.dart'; +import 'package:linter/src/rules/avoid_empty_else.dart'; +import 'package:linter/src/rules/avoid_escaping_inner_quotes.dart'; +import 'package:linter/src/rules/avoid_function_literals_in_foreach_calls.dart'; +import 'package:linter/src/rules/avoid_init_to_null.dart'; +import 'package:linter/src/rules/avoid_multiple_declarations_per_line.dart'; +import 'package:linter/src/rules/avoid_null_checks_in_equality_operators.dart'; +import 'package:linter/src/rules/avoid_print.dart'; +import 'package:linter/src/rules/avoid_private_typedef_functions.dart'; +import 'package:linter/src/rules/avoid_redundant_argument_values.dart'; +import 'package:linter/src/rules/avoid_relative_lib_imports.dart'; +import 'package:linter/src/rules/avoid_renaming_method_parameters.dart'; +import 'package:linter/src/rules/avoid_return_types_on_setters.dart'; +import 'package:linter/src/rules/avoid_returning_null_for_void.dart'; +import 'package:linter/src/rules/avoid_single_cascade_in_expression_statements.dart'; +import 'package:linter/src/rules/avoid_types_as_parameter_names.dart'; +import 'package:linter/src/rules/avoid_types_on_closure_parameters.dart'; +import 'package:linter/src/rules/avoid_unnecessary_containers.dart'; +import 'package:linter/src/rules/avoid_unused_constructor_parameters.dart'; +import 'package:linter/src/rules/avoid_void_async.dart'; +import 'package:linter/src/rules/await_only_futures.dart'; +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/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/diagnostic_describe_all_properties.dart'; +import 'package:linter/src/rules/directives_ordering.dart'; +import 'package:linter/src/rules/discarded_futures.dart'; +import 'package:linter/src/rules/empty_catches.dart'; +import 'package:linter/src/rules/empty_constructor_bodies.dart'; +import 'package:linter/src/rules/empty_statements.dart'; +import 'package:linter/src/rules/eol_at_end_of_file.dart'; +import 'package:linter/src/rules/exhaustive_cases.dart'; +import 'package:linter/src/rules/flutter_style_todos.dart'; +import 'package:linter/src/rules/hash_and_equals.dart'; +import 'package:linter/src/rules/implicit_call_tearoffs.dart'; +import 'package:linter/src/rules/implicit_reopen.dart'; +import 'package:linter/src/rules/invalid_case_patterns.dart'; +import 'package:linter/src/rules/leading_newlines_in_multiline_strings.dart'; +import 'package:linter/src/rules/library_annotations.dart'; +import 'package:linter/src/rules/no_duplicate_case_values.dart'; +import 'package:linter/src/rules/no_leading_underscores_for_library_prefixes.dart'; +import 'package:linter/src/rules/no_leading_underscores_for_local_identifiers.dart'; +import 'package:linter/src/rules/no_literal_bool_comparisons.dart'; +import 'package:linter/src/rules/non_constant_identifier_names.dart'; +import 'package:linter/src/rules/noop_primitive_operations.dart'; +import 'package:linter/src/rules/null_check_on_nullable_type_parameter.dart'; +import 'package:linter/src/rules/null_closures.dart'; +import 'package:linter/src/rules/omit_local_variable_types.dart'; +import 'package:linter/src/rules/omit_obvious_local_variable_types.dart'; +import 'package:linter/src/rules/prefer_adjacent_string_concatenation.dart'; +import 'package:linter/src/rules/prefer_collection_literals.dart'; +import 'package:linter/src/rules/prefer_conditional_assignment.dart'; +import 'package:linter/src/rules/prefer_const_constructors.dart'; +import 'package:linter/src/rules/prefer_const_constructors_in_immutables.dart'; +import 'package:linter/src/rules/prefer_const_declarations.dart'; +import 'package:linter/src/rules/prefer_const_literals_to_create_immutables.dart'; +import 'package:linter/src/rules/prefer_contains.dart'; +import 'package:linter/src/rules/prefer_double_quotes.dart'; +import 'package:linter/src/rules/prefer_expression_function_bodies.dart'; +import 'package:linter/src/rules/prefer_final_fields.dart'; +import 'package:linter/src/rules/prefer_final_in_for_each.dart'; +import 'package:linter/src/rules/prefer_final_locals.dart'; +import 'package:linter/src/rules/prefer_final_parameters.dart'; +import 'package:linter/src/rules/prefer_for_elements_to_map_fromIterable.dart'; +import 'package:linter/src/rules/prefer_function_declarations_over_variables.dart'; +import 'package:linter/src/rules/prefer_generic_function_type_aliases.dart'; +import 'package:linter/src/rules/prefer_if_elements_to_conditional_expressions.dart'; +import 'package:linter/src/rules/prefer_if_null_operators.dart'; +import 'package:linter/src/rules/prefer_initializing_formals.dart'; +import 'package:linter/src/rules/prefer_inlined_adds.dart'; +import 'package:linter/src/rules/prefer_int_literals.dart'; +import 'package:linter/src/rules/prefer_interpolation_to_compose_strings.dart'; +import 'package:linter/src/rules/prefer_is_empty.dart'; +import 'package:linter/src/rules/prefer_is_not_empty.dart'; +import 'package:linter/src/rules/prefer_is_not_operator.dart'; +import 'package:linter/src/rules/prefer_iterable_whereType.dart'; +import 'package:linter/src/rules/prefer_null_aware_operators.dart'; +import 'package:linter/src/rules/prefer_relative_imports.dart'; +import 'package:linter/src/rules/prefer_single_quotes.dart'; +import 'package:linter/src/rules/prefer_spread_collections.dart'; +import 'package:linter/src/rules/prefer_typing_uninitialized_variables.dart'; +import 'package:linter/src/rules/prefer_void_to_null.dart'; +import 'package:linter/src/rules/require_trailing_commas.dart'; +import 'package:linter/src/rules/sized_box_for_whitespace.dart'; +import 'package:linter/src/rules/slash_for_doc_comments.dart'; +import 'package:linter/src/rules/sort_child_properties_last.dart'; +import 'package:linter/src/rules/sort_constructors_first.dart'; +import 'package:linter/src/rules/sort_unnamed_constructors_first.dart'; +import 'package:linter/src/rules/type_annotate_public_apis.dart'; +import 'package:linter/src/rules/type_init_formals.dart'; +import 'package:linter/src/rules/type_literal_in_constant_pattern.dart'; +import 'package:linter/src/rules/unawaited_futures.dart'; +import 'package:linter/src/rules/unnecessary_await_in_return.dart'; +import 'package:linter/src/rules/unnecessary_brace_in_string_interps.dart'; +import 'package:linter/src/rules/unnecessary_breaks.dart'; +import 'package:linter/src/rules/unnecessary_const.dart'; +import 'package:linter/src/rules/unnecessary_constructor_name.dart'; +import 'package:linter/src/rules/unnecessary_final.dart'; +import 'package:linter/src/rules/unnecessary_getters_setters.dart'; +import 'package:linter/src/rules/unnecessary_lambdas.dart'; +import 'package:linter/src/rules/unnecessary_late.dart'; +import 'package:linter/src/rules/unnecessary_library_directive.dart'; +import 'package:linter/src/rules/unnecessary_library_name.dart'; +import 'package:linter/src/rules/unnecessary_new.dart'; +import 'package:linter/src/rules/unnecessary_null_aware_assignments.dart'; +import 'package:linter/src/rules/unnecessary_null_checks.dart'; +import 'package:linter/src/rules/unnecessary_null_in_if_null_operators.dart'; +import 'package:linter/src/rules/unnecessary_nullable_for_final_variable_declarations.dart'; +import 'package:linter/src/rules/unnecessary_overrides.dart'; +import 'package:linter/src/rules/unnecessary_parenthesis.dart'; +import 'package:linter/src/rules/unnecessary_raw_strings.dart'; +import 'package:linter/src/rules/unnecessary_string_escapes.dart'; +import 'package:linter/src/rules/unnecessary_string_interpolations.dart'; +import 'package:linter/src/rules/unnecessary_this.dart'; +import 'package:linter/src/rules/unnecessary_to_list_in_spreads.dart'; +import 'package:linter/src/rules/unreachable_from_main.dart'; +import 'package:linter/src/rules/use_decorated_box.dart'; +import 'package:linter/src/rules/use_enums.dart'; +import 'package:linter/src/rules/use_full_hex_values_for_flutter_colors.dart'; +import 'package:linter/src/rules/use_function_type_syntax_for_parameters.dart'; +import 'package:linter/src/rules/use_key_in_widget_constructors.dart'; +import 'package:linter/src/rules/use_named_constants.dart'; +import 'package:linter/src/rules/use_raw_strings.dart'; +import 'package:linter/src/rules/use_rethrow_when_possible.dart'; +import 'package:linter/src/rules/use_string_in_part_of_directives.dart'; +import 'package:linter/src/rules/use_super_parameters.dart'; final _builtInLintMultiProducers = { LintNames.deprecated_member_use_from_same_package: [ @@ -265,424 +401,467 @@ final _builtInLintMultiProducers = { ], }; -final _builtInLintProducers = >{ - LintNames.always_declare_return_types: [ +final _builtInLintProducers = >{ + AlwaysDeclareReturnTypes.functionCode: [ AddReturnType.new, ], - LintNames.always_put_control_body_on_new_line: [ + AlwaysDeclareReturnTypes.methodCode: [ + AddReturnType.new, + ], + AlwaysPutControlBodyOnNewLine.code: [ UseCurlyBraces.nonBulk, ], - LintNames.always_put_required_named_parameters_first: [ + AlwaysPutRequiredNamedParametersFirst.code: [ MakeRequiredNamedParametersFirst.new, ], - LintNames.always_specify_types: [ + AlwaysSpecifyTypes.code: [ AddTypeAnnotation.bulkFixable, ], - LintNames.always_use_package_imports: [ + AlwaysUsePackageImports.code: [ ConvertToPackageImport.new, ], - LintNames.annotate_overrides: [ + AnnotateOverrides.code: [ AddOverride.new, ], - LintNames.annotate_redeclares: [ + AnnotateRedeclares.code: [ AddRedeclare.new, ], - LintNames.avoid_annotating_with_dynamic: [ + AvoidAnnotatingWithDynamic.code: [ RemoveTypeAnnotation.other, ], - LintNames.avoid_empty_else: [ + AvoidEmptyElse.code: [ RemoveEmptyElse.new, ], - LintNames.avoid_escaping_inner_quotes: [ + AvoidEscapingInnerQuotes.code: [ ConvertQuotes.new, ], - LintNames.avoid_function_literals_in_foreach_calls: [ + AvoidFunctionLiteralsInForeachCalls.code: [ ConvertForEachToForLoop.new, ], - LintNames.avoid_init_to_null: [ + AvoidInitToNull.code: [ RemoveInitializer.bulkFixable, ], - LintNames.avoid_multiple_declarations_per_line: [ + AvoidMultipleDeclarationsPerLine.code: [ SplitMultipleDeclarations.new, ], - LintNames.avoid_null_checks_in_equality_operators: [ + AvoidNullChecksInEqualityOperators.code: [ RemoveComparison.new, ], - LintNames.avoid_print: [ + AvoidPrint.code: [ MakeConditionalOnDebugMode.new, RemovePrint.new, ], - LintNames.avoid_private_typedef_functions: [ + AvoidPrivateTypedefFunctions.code: [ InlineTypedef.new, ], - LintNames.avoid_redundant_argument_values: [ + AvoidRedundantArgumentValues.code: [ RemoveArgument.new, ], - LintNames.avoid_relative_lib_imports: [ + AvoidRelativeLibImports.code: [ ConvertToPackageImport.new, ], - LintNames.avoid_renaming_method_parameters: [ + AvoidRenamingMethodParameters.code: [ RenameMethodParameter.new, ], - LintNames.avoid_return_types_on_setters: [ + AvoidReturnTypesOnSetters.code: [ RemoveTypeAnnotation.other, ], - LintNames.avoid_returning_null_for_void: [ + AvoidReturningNullForVoid.fromFunction: [ RemoveReturnedValue.new, ], - LintNames.avoid_single_cascade_in_expression_statements: [ + AvoidReturningNullForVoid.fromMethod: [ + RemoveReturnedValue.new, + ], + AvoidSingleCascadeInExpressionStatements.code: [ // TODO(brianwilkerson): This fix should be applied to some non-lint // diagnostics and should also be available as an assist. ReplaceCascadeWithDot.new, ], - LintNames.avoid_types_as_parameter_names: [ + AvoidTypesAsParameterNames.code: [ ConvertToOnType.new, ], - LintNames.avoid_types_on_closure_parameters: [ + AvoidTypesOnClosureParameters.code: [ ReplaceWithIdentifier.new, RemoveTypeAnnotation.other, ], - LintNames.avoid_unused_constructor_parameters: [ + AvoidUnusedConstructorParameters.code: [ RemoveUnusedParameter.new, ], - LintNames.avoid_unnecessary_containers: [ + AvoidUnnecessaryContainers.code: [ FlutterRemoveWidget.new, ], - LintNames.avoid_void_async: [ + AvoidVoidAsync.code: [ ReplaceReturnTypeFuture.new, ], - LintNames.await_only_futures: [ + AwaitOnlyFutures.code: [ RemoveAwait.new, ], - LintNames.cascade_invocations: [ + CascadeInvocations.code: [ ConvertToCascade.new, ], - LintNames.cast_nullable_to_non_nullable: [ + CastNullableToNonNullable.code: [ AddNullCheck.withoutAssignabilityCheck, ], - LintNames.combinators_ordering: [ + CombinatorsOrdering.code: [ SortCombinators.new, ], - LintNames.constant_identifier_names: [ + ConstantIdentifierNames.code: [ RenameToCamelCase.new, ], - LintNames.curly_braces_in_flow_control_structures: [ + CurlyBracesInFlowControlStructures.code: [ UseCurlyBraces.new, ], - LintNames.dangling_library_doc_comments: [ + DanglingLibraryDocComments.code: [ MoveDocCommentToLibraryDirective.new, ], - LintNames.diagnostic_describe_all_properties: [ + DiagnosticDescribeAllProperties.code: [ AddDiagnosticPropertyReference.new, ], - LintNames.directives_ordering: [ + DirectivesOrdering.dartDirectiveGoFirst: [ + OrganizeImports.new, + ], + DirectivesOrdering.directiveSectionOrderedAlphabetically: [ + OrganizeImports.new, + ], + DirectivesOrdering.exportDirectiveAfterImportDirectives: [ + OrganizeImports.new, + ], + DirectivesOrdering.packageDirectiveBeforeRelative: [ OrganizeImports.new, ], - LintNames.discarded_futures: [ + DiscardedFutures.code: [ AddAsync.new, WrapInUnawaited.new, ], - LintNames.empty_catches: [ + EmptyCatches.code: [ RemoveEmptyCatch.new, ], - LintNames.empty_constructor_bodies: [ + EmptyConstructorBodies.code: [ RemoveEmptyConstructorBody.new, ], - LintNames.empty_statements: [ + EmptyStatements.code: [ RemoveEmptyStatement.new, ReplaceWithBrackets.new, ], - LintNames.eol_at_end_of_file: [ + EolAtEndOfFile.code: [ AddEolAtEndOfFile.new, ], - LintNames.exhaustive_cases: [ + ExhaustiveCases.code: [ AddMissingEnumLikeCaseClauses.new, ], - LintNames.flutter_style_todos: [ + FlutterStyleTodos.code: [ ConvertToFlutterStyleTodo.new, ], - LintNames.hash_and_equals: [ + HashAndEquals.code: [ CreateMethod.equalityOrHashCode, ], - LintNames.implicit_call_tearoffs: [ + ImplicitCallTearoffs.code: [ AddExplicitCall.new, ], - LintNames.implicit_reopen: [ + ImplicitReopen.code: [ AddReopen.new, ], - LintNames.invalid_case_patterns: [ + InvalidCasePatterns.code: [ AddConst.new, ], - LintNames.leading_newlines_in_multiline_strings: [ + LeadingNewlinesInMultilineStrings.code: [ AddLeadingNewlineToString.new, ], - LintNames.library_annotations: [ + LibraryAnnotations.code: [ MoveAnnotationToLibraryDirective.new, ], - LintNames.no_duplicate_case_values: [ + NoDuplicateCaseValues.code: [ RemoveDuplicateCase.new, ], - LintNames.no_leading_underscores_for_library_prefixes: [ + NoLeadingUnderscoresForLibraryPrefixes.code: [ RemoveLeadingUnderscore.new, ], - LintNames.no_literal_bool_comparisons: [ - ConvertToBooleanExpression.new, - ], - LintNames.no_leading_underscores_for_local_identifiers: [ + NoLeadingUnderscoresForLocalIdentifiers.code: [ RemoveLeadingUnderscore.new, ], - LintNames.non_constant_identifier_names: [ + NoLiteralBoolComparisons.code: [ + ConvertToBooleanExpression.new, + ], + NonConstantIdentifierNames.code: [ RenameToCamelCase.new, ], - LintNames.noop_primitive_operations: [ + NoopPrimitiveOperations.code: [ RemoveInvocation.new, ], - LintNames.null_check_on_nullable_type_parameter: [ + NullCheckOnNullableTypeParameter.code: [ ReplaceNullCheckWithCast.new, ], - LintNames.null_closures: [ + NullClosures.code: [ ReplaceNullWithClosure.new, ], - LintNames.omit_local_variable_types: [ + OmitLocalVariableTypes.code: [ ReplaceWithVar.new, ], - LintNames.omit_obvious_local_variable_types: [ + OmitObviousLocalVariableTypes.code: [ ReplaceWithVar.new, ], - LintNames.prefer_adjacent_string_concatenation: [ + PreferAdjacentStringConcatenation.code: [ RemoveOperator.new, ], - LintNames.prefer_collection_literals: [ + PreferCollectionLiterals.code: [ ConvertToMapLiteral.new, ConvertToSetLiteral.new, ], - LintNames.prefer_conditional_assignment: [ + PreferConditionalAssignment.code: [ ReplaceWithConditionalAssignment.new, ], - LintNames.prefer_const_constructors: [ + PreferConstConstructors.code: [ AddConst.new, ReplaceNewWithConst.new, ], - LintNames.prefer_const_constructors_in_immutables: [ + PreferConstConstructorsInImmutables.code: [ AddConst.new, ], - LintNames.prefer_const_declarations: [ + PreferConstDeclarations.code: [ ReplaceFinalWithConst.new, ], - LintNames.prefer_const_literals_to_create_immutables: [ + PreferConstLiteralsToCreateImmutables.code: [ AddConst.new, ], - LintNames.prefer_contains: [ + PreferContains.alwaysFalse: [ + ConvertToContains.new, + ], + PreferContains.alwaysTrue: [ + ConvertToContains.new, + ], + PreferContains.useContains: [ ConvertToContains.new, ], - LintNames.prefer_double_quotes: [ + PreferDoubleQuotes.code: [ ConvertToDoubleQuotes.new, ], - LintNames.prefer_expression_function_bodies: [ + PreferExpressionFunctionBodies.code: [ ConvertToExpressionFunctionBody.new, ], - LintNames.prefer_final_fields: [ + PreferFinalFields.code: [ MakeFinal.new, ], - LintNames.prefer_final_in_for_each: [ + PreferFinalInForEach.code: [ MakeFinal.new, ], - LintNames.prefer_final_locals: [ + PreferFinalLocals.code: [ MakeFinal.new, ], - LintNames.prefer_final_parameters: [ + PreferFinalParameters.code: [ MakeFinal.new, ], - LintNames.prefer_for_elements_to_map_fromIterable: [ + PreferForElementsToMapFromIterable.code: [ ConvertMapFromIterableToForLiteral.new, ], - LintNames.prefer_function_declarations_over_variables: [ + PreferFunctionDeclarationsOverVariables.code: [ ConvertToFunctionDeclaration.new, ], - LintNames.prefer_generic_function_type_aliases: [ + PreferGenericFunctionTypeAliases.code: [ ConvertToGenericFunctionSyntax.new, ], - LintNames.prefer_if_elements_to_conditional_expressions: [ + PreferIfElementsToConditionalExpressions.code: [ ConvertConditionalExpressionToIfElement.new, ], - LintNames.prefer_if_null_operators: [ + PreferIfNullOperators.code: [ ConvertToIfNull.new, ], - LintNames.prefer_initializing_formals: [ + PreferInitializingFormals.code: [ ConvertToInitializingFormal.new, ], - LintNames.prefer_inlined_adds: [ + PreferInlinedAdds.single: [ ConvertAddAllToSpread.new, InlineInvocation.new, ], - LintNames.prefer_int_literals: [ + PreferInlinedAdds.multiple: [ + ConvertAddAllToSpread.new, + InlineInvocation.new, + ], + PreferIntLiterals.code: [ ConvertToIntLiteral.new, ], - LintNames.prefer_interpolation_to_compose_strings: [ + PreferInterpolationToComposeStrings.code: [ ReplaceWithInterpolation.new, ], - LintNames.prefer_is_empty: [ + PreferIsEmpty.alwaysFalse: [ + ReplaceWithIsEmpty.new, + ], + PreferIsEmpty.alwaysTrue: [ + ReplaceWithIsEmpty.new, + ], + PreferIsEmpty.useIsEmpty: [ + ReplaceWithIsEmpty.new, + ], + PreferIsEmpty.useIsNotEmpty: [ ReplaceWithIsEmpty.new, ], - LintNames.prefer_is_not_empty: [ + PreferIsNotEmpty.code: [ UseIsNotEmpty.new, ], - LintNames.prefer_is_not_operator: [ + PreferIsNotOperator.code: [ ConvertIntoIsNot.new, ], - LintNames.prefer_iterable_whereType: [ + PreferIterableWhereType.code: [ ConvertToWhereType.new, ], - LintNames.prefer_null_aware_operators: [ + PreferNullAwareOperators.code: [ ConvertToNullAware.new, ], - LintNames.prefer_relative_imports: [ + PreferRelativeImports.code: [ ConvertToRelativeImport.new, ], - LintNames.prefer_single_quotes: [ + PreferSingleQuotes.code: [ ConvertToSingleQuotes.new, ], - LintNames.prefer_spread_collections: [ + PreferSpreadCollections.code: [ ConvertAddAllToSpread.new, ], - LintNames.prefer_typing_uninitialized_variables: [ + PreferTypingUninitializedVariables.forField: [ + AddTypeAnnotation.bulkFixable, + ], + PreferTypingUninitializedVariables.forVariable: [ AddTypeAnnotation.bulkFixable, ], - LintNames.prefer_void_to_null: [ + PreferVoidToNull.code: [ ReplaceNullWithVoid.new, ], - LintNames.require_trailing_commas: [ + RequireTrailingCommas.code: [ AddTrailingComma.new, ], - LintNames.sized_box_for_whitespace: [ + SizedBoxForWhitespace.code: [ ReplaceContainerWithSizedBox.new, ], - LintNames.slash_for_doc_comments: [ + SlashForDocComments.code: [ ConvertDocumentationIntoLine.new, ], - LintNames.sort_child_properties_last: [ + SortChildPropertiesLast.code: [ SortChildPropertyLast.new, ], - LintNames.sort_constructors_first: [ + SortConstructorsFirst.code: [ SortConstructorFirst.new, ], - LintNames.sort_unnamed_constructors_first: [ + SortUnnamedConstructorsFirst.code: [ SortUnnamedConstructorFirst.new, ], - LintNames.type_annotate_public_apis: [ + TypeAnnotatePublicApis.code: [ AddTypeAnnotation.bulkFixable, ], - LintNames.type_init_formals: [ + TypeInitFormals.code: [ RemoveTypeAnnotation.other, ], - LintNames.type_literal_in_constant_pattern: [ + TypeLiteralInConstantPattern.code: [ ConvertToConstantPattern.new, ConvertToWildcardPattern.new, ], - LintNames.unawaited_futures: [ + UnawaitedFutures.code: [ AddAwait.unawaited, WrapInUnawaited.new, ], - LintNames.unnecessary_await_in_return: [ + UnnecessaryAwaitInReturn.code: [ RemoveAwait.new, ], - LintNames.unnecessary_brace_in_string_interps: [ + UnnecessaryBraceInStringInterps.code: [ RemoveInterpolationBraces.new, ], - LintNames.unnecessary_breaks: [ + UnnecessaryBreaks.code: [ RemoveBreak.new, ], - LintNames.unnecessary_const: [ + UnnecessaryConst.code: [ RemoveUnnecessaryConst.new, ], - LintNames.unnecessary_constructor_name: [ + UnnecessaryConstructorName.code: [ RemoveConstructorName.new, ], - LintNames.unnecessary_final: [ + UnnecessaryFinal.withType: [ ReplaceFinalWithVar.new, ], - LintNames.unnecessary_getters_setters: [ + UnnecessaryFinal.withoutType: [ + ReplaceFinalWithVar.new, + ], + UnnecessaryGettersSetters.code: [ MakeFieldPublic.new, ], - LintNames.unnecessary_lambdas: [ + UnnecessaryLambdas.code: [ ReplaceWithTearOff.new, ], - LintNames.unnecessary_late: [ + UnnecessaryLate.code: [ RemoveUnnecessaryLate.new, ], - LintNames.unnecessary_library_directive: [ + UnnecessaryLibraryDirective.code: [ RemoveUnnecessaryLibraryDirective.new, ], - LintNames.unnecessary_library_name: [ + UnnecessaryLibraryName.code: [ RemoveLibraryName.new, ], - LintNames.unnecessary_new: [ + UnnecessaryNew.code: [ RemoveUnnecessaryNew.new, ], - LintNames.unnecessary_null_aware_assignments: [ + UnnecessaryNullAwareAssignments.code: [ RemoveAssignment.new, ], - LintNames.unnecessary_null_checks: [ + UnnecessaryNullChecks.code: [ RemoveNonNullAssertion.new, ], - LintNames.unnecessary_null_in_if_null_operators: [ + UnnecessaryNullInIfNullOperators.code: [ RemoveIfNullOperator.new, ], - LintNames.unnecessary_nullable_for_final_variable_declarations: [ + UnnecessaryNullableForFinalVariableDeclarations.code: [ RemoveQuestionMark.new, ], - LintNames.unnecessary_overrides: [ + UnnecessaryOverrides.code: [ RemoveMethodDeclaration.new, ], - LintNames.unnecessary_parenthesis: [ + UnnecessaryParenthesis.code: [ RemoveUnnecessaryParentheses.new, ], - LintNames.unnecessary_raw_strings: [ + UnnecessaryRawStrings.code: [ RemoveUnnecessaryRawString.new, ], - LintNames.unnecessary_string_escapes: [ + UnnecessaryStringEscapes.code: [ RemoveUnnecessaryStringEscape.new, ], - LintNames.unnecessary_string_interpolations: [ + UnnecessaryStringInterpolations.code: [ RemoveUnnecessaryStringInterpolation.new, ], - LintNames.unnecessary_to_list_in_spreads: [ + UnnecessaryToListInSpreads.code: [ RemoveToList.new, ], - LintNames.unnecessary_this: [ + UnnecessaryThis.code: [ RemoveThisExpression.new, ], - LintNames.unreachable_from_main: [ + UnreachableFromMain.code: [ RemoveUnusedElement.new, ], - LintNames.use_decorated_box: [ + UseDecoratedBox.code: [ ReplaceWithDecoratedBox.new, ], - LintNames.use_enums: [ + UseEnums.code: [ ConvertClassToEnum.new, ], - LintNames.use_full_hex_values_for_flutter_colors: [ + UseFullHexValuesForFlutterColors.code: [ ReplaceWithEightDigitHex.new, ], - LintNames.use_function_type_syntax_for_parameters: [ + UseFunctionTypeSyntaxForParameters.code: [ ConvertToGenericFunctionSyntax.new, ], - LintNames.use_key_in_widget_constructors: [ + UseKeyInWidgetConstructors.code: [ AddKeyToConstructors.new, ], - LintNames.use_named_constants: [ + UseNamedConstants.code: [ ReplaceWithNamedConstant.new, ], - LintNames.use_raw_strings: [ + UseRawStrings.code: [ ConvertToRawString.new, ], - LintNames.use_rethrow_when_possible: [ + UseRethrowWhenPossible.code: [ UseRethrow.new, ], - LintNames.use_string_in_part_of_directives: [ + UseStringInPartOfDirectives.code: [ ReplaceWithPartOrUriEmpty.new, ], - LintNames.use_super_parameters: [ + UseSuperParameters.singleParam: [ + ConvertToSuperParameters.new, + ], + UseSuperParameters.multipleParams: [ ConvertToSuperParameters.new, ], }; @@ -1958,7 +2137,7 @@ class FixInFileProcessor { List _getGenerators(ErrorCode errorCode) { if (errorCode is LintCode) { - return FixProcessor.lintProducerMap[errorCode.uniqueLintName] ?? []; + return FixProcessor.lintProducerMap[errorCode] ?? []; } else { // TODO(pq): consider support for multiGenerators return FixProcessor.nonLintProducerMap[errorCode] ?? []; 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 4b69733a7c03..6c587d9883b5 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix_processor.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix_processor.dart @@ -42,7 +42,7 @@ class FixProcessor { /// the lint, so most of the keys are constants defined by [LintNames]. But /// when a lint produces multiple codes, each with a different unique name, /// the unique name must be used here. - static final Map> lintProducerMap = {}; + static final Map> lintProducerMap = {}; /// A map from error codes to a list of generators used to create multiple /// correction producers used to build fixes for those diagnostics. @@ -131,7 +131,7 @@ class FixProcessor { List? multiGenerators; if (errorCode is LintCode) { var uniqueLintName = errorCode.uniqueLintName; - generators = lintProducerMap[uniqueLintName]; + generators = lintProducerMap[errorCode]; multiGenerators = lintMultiProducerMap[uniqueLintName]; } else { generators = nonLintProducerMap[errorCode]; @@ -172,7 +172,7 @@ class FixProcessor { return _bulkFixableErrorCodes.putIfAbsent(errorCode, () { if (errorCode is LintCode) { - var producers = FixProcessor.lintProducerMap[errorCode.name]; + var producers = FixProcessor.lintProducerMap[errorCode]; if (hasBulkFixProducers(producers)) { return true; } @@ -194,9 +194,10 @@ class FixProcessor { } /// Associates the given correction producer [generator] with the lint with - /// the given [lintName]. - static void registerFixForLint(String lintName, ProducerGenerator generator) { - lintProducerMap.putIfAbsent(lintName, () => []).add(generator); + /// the given [lintCode]. + static void registerFixForLint( + LintCode lintCode, ProducerGenerator generator) { + lintProducerMap.putIfAbsent(lintCode, () => []).add(generator); } } diff --git a/pkg/analysis_server/test/src/cider/assists_test.dart b/pkg/analysis_server/test/src/cider/assists_test.dart index b2956c90c87e..8bc9e03296ee 100644 --- a/pkg/analysis_server/test/src/cider/assists_test.dart +++ b/pkg/analysis_server/test/src/cider/assists_test.dart @@ -7,6 +7,7 @@ import 'package:analysis_server/src/cider/assists.dart'; import 'package:analysis_server/src/services/correction/assist.dart'; import 'package:analysis_server/src/services/correction/assist_internal.dart'; import 'package:analysis_server/src/services/correction/fix_processor.dart'; +import 'package:analyzer/error/error.dart'; import 'package:analyzer/source/line_info.dart'; import 'package:analyzer_plugin/protocol/protocol_common.dart' show SourceEdit; import 'package:analyzer_plugin/utilities/assist/assist.dart'; @@ -29,7 +30,7 @@ class CiderAssistsComputerTest extends CiderServiceTest { /// A mapping of [ProducerGenerator]s to the set of lint names with which they /// are associated (can fix). - late Map> _producerGeneratorsForLintRules; + late Map> _producerGeneratorsForLintRules; void assertHasAssist(AssistKind kind, String expected) { var assist = _getAssist(kind); diff --git a/pkg/analysis_server/test/src/services/correction/assist/assist_processor.dart b/pkg/analysis_server/test/src/services/correction/assist/assist_processor.dart index e261ddd538d5..c845f711e68b 100644 --- a/pkg/analysis_server/test/src/services/correction/assist/assist_processor.dart +++ b/pkg/analysis_server/test/src/services/correction/assist/assist_processor.dart @@ -8,6 +8,7 @@ import 'package:analysis_server/src/services/correction/assist_internal.dart'; import 'package:analysis_server/src/services/correction/fix_processor.dart'; import 'package:analysis_server_plugin/src/correction/change_workspace.dart'; import 'package:analysis_server_plugin/src/correction/dart_change_workspace.dart'; +import 'package:analyzer/error/error.dart'; import 'package:analyzer/src/test_utilities/platform.dart'; import 'package:analyzer_plugin/protocol/protocol_common.dart' hide AnalysisError; @@ -30,7 +31,7 @@ abstract class AssistProcessorTest extends AbstractSingleUnitTest { /// A mapping of [ProducerGenerator]s to the set of lint names with which they /// are associated (can fix). - late Map> _producerGeneratorsForLintRules; + late Map> _producerGeneratorsForLintRules; /// Return the kind of assist expected by this class. AssistKind get kind; diff --git a/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart b/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart index 046ea514065b..43f6e0f45f9b 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart @@ -90,7 +90,7 @@ abstract class BulkFixProcessorTest extends AbstractSingleUnitTest { @override List get experiments => const []; - /// Return the lint code being tested. + /// The name of the lint code being tested. String? get lintCode => null; /// The workspace in which fixes contributor operates. diff --git a/pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart b/pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart index c37192f235ec..8f275c8ddaa4 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart @@ -5,6 +5,7 @@ import 'package:analysis_server/src/services/correction/fix_internal.dart'; import 'package:analysis_server/src/services/correction/fix_processor.dart'; import 'package:analysis_server_plugin/edit/dart/correction_producer.dart'; +import 'package:analyzer/error/error.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -42,15 +43,15 @@ class FixProcessorMapTest { {required CorrectionProducerContext context}) => MockCorrectionProducer(); - var lintName = 'not_a_lint'; - expect(FixProcessor.lintProducerMap[lintName], null); - FixProcessor.registerFixForLint(lintName, generator); - expect(FixProcessor.lintProducerMap[lintName], contains(generator)); + var lintCode = LintCode('test_rule', 'Test rule.'); + expect(FixProcessor.lintProducerMap[lintCode], null); + FixProcessor.registerFixForLint(lintCode, generator); + expect(FixProcessor.lintProducerMap[lintCode], contains(generator)); // Restore the map to it's original state so as to not impact other tests. - FixProcessor.lintProducerMap.remove(lintName); + FixProcessor.lintProducerMap.remove(lintCode); } - void _assertMap(Map> producerMap, + void _assertMap(Map> producerMap, [List codesAllowedToHaveMultipleBulkFixes = const []]) { var unexpectedBulkCodes = []; for (var MapEntry(:key, value: generators) in producerMap.entries) { @@ -64,7 +65,7 @@ class FixProcessorMapTest { } } if (bulkCount > 1) { - var name = key.toString(); + var name = key.name; if (!codesAllowedToHaveMultipleBulkFixes.contains(name)) { unexpectedBulkCodes.add(name); } 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 917045a21c28..d7ebe4b5aa3d 100644 --- a/pkg/analysis_server/tool/presubmit/verify_error_fix_status.dart +++ b/pkg/analysis_server/tool/presubmit/verify_error_fix_status.dart @@ -185,13 +185,13 @@ class ErrorData { } extension on ErrorCode { - /// Whether this [errorCode] is likely to have a fix associated with + /// Whether this [ErrorCode] is likely to have a fix associated with /// it. bool get hasFix { var self = this; if (self is LintCode) { var lintName = self.name; - return FixProcessor.lintProducerMap.containsKey(lintName) || + return FixProcessor.lintProducerMap.containsKey(self) || FixProcessor.lintMultiProducerMap.containsKey(lintName); } return FixProcessor.nonLintProducerMap.containsKey(self) || diff --git a/pkg/linter/lib/src/rules/avoid_renaming_method_parameters.dart b/pkg/linter/lib/src/rules/avoid_renaming_method_parameters.dart index 5506fcdc1b41..1f5988fa948f 100644 --- a/pkg/linter/lib/src/rules/avoid_renaming_method_parameters.dart +++ b/pkg/linter/lib/src/rules/avoid_renaming_method_parameters.dart @@ -47,7 +47,7 @@ abstract class B extends A { '''; class AvoidRenamingMethodParameters extends LintRule { - static const LintCode parameterCode = LintCode( + static const LintCode code = LintCode( 'avoid_renaming_method_parameters', "The parameter name '{0}' doesn't match the name '{1}' in the overridden " 'method.', @@ -62,7 +62,7 @@ class AvoidRenamingMethodParameters extends LintRule { categories: {Category.documentationCommentMaintenance}); @override - LintCode get lintCode => parameterCode; + LintCode get lintCode => code; @override void registerNodeProcessors(