From ad2da86f18c06ab348f748ad2354ebb5e577f52c Mon Sep 17 00:00:00 2001 From: pq Date: Tue, 7 Feb 2023 20:56:35 +0000 Subject: [PATCH] linter 1.33.0 rc Some notes. * There are a number of tests that should get decoupled from the linter being pulled into `DEPS`. Instead of depending on the state of lints there, we should update the tests instead to use a more hermetic environment. (See for example `options_rule_validator_test.dart` for how that might look.) Downstream (blocking) fixes: * https://github.com/flutter/flutter/pull/119736 * https://github.com/flutter/gallery/pull/878 Change-Id: I5671b0abde3eeda75513abaaf9fef3bcd5115f9b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280054 Reviewed-by: Brian Wilkerson Commit-Queue: Phil Quitslund Reviewed-by: Paul Berry --- CHANGELOG.md | 21 +++++- DEPS | 2 +- .../services/correction/error_fix_status.yaml | 4 ++ .../test/lsp/code_actions_fixes_test.dart | 71 +++++++++++++------ .../src/plugin/result_converter_test.dart | 17 ----- .../analysis_options/remove_lint_test.dart | 8 +-- .../fix/analysis_options/test_support.dart | 3 +- .../test/stress/replay/replay.dart | 1 + .../code_completion/relevance_metrics.dart | 1 + pkg/analyzer_utilities/analysis_options.yaml | 1 - pkg/test_runner/analysis_options.yaml | 1 - 11 files changed, 82 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36c6a1e8ea4..77efdbe0c44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -125,15 +125,30 @@ #### Linter -Updates the Linter to `1.32.0`, which includes changes that +Updates the Linter to `1.33.0`, which includes changes that +- add new lint: `unnecessary_breaks`. +- remove support for: + - `enable_null_safety` + - `invariant_booleans` + - `prefer_bool_in_asserts` + - `prefer_equal_for_default_values` + - `super_goes_last` +- fix `unnecessary_parenthesis` false-positives with null-aware expressions. +- fix `void_checks` to allow assignments of `Future?` to parameters + typed `FutureOr?`. +- fix `use_build_context_synchronously` in if conditions. +- fix a false positive for `avoid_private_typedef_functions` with generalized type aliases. +- update `unnecessary_parenthesis` to detect some doubled parens. +- update `void_checks` to allow returning `Never` as void. +- update `no_adjacent_strings_in_list` to support set literals and for- and + if-elements. - update `avoid_types_as_parameter_names` to handle type variables. - update `avoid_positional_boolean_parameters` to handle typedefs. -- improve `unnecessary_parenthesis` support for property accesses and method invocations. - update `avoid_redundant_argument_values` to check parameters of redirecting constructors. - improve performance for `prefer_const_literals_to_create_immutables`. - update `use_build_context_synchronously` to check context properties. -- fix a false positive for `avoid_private_typedef_functions` with generalized type aliases. +- improve `unnecessary_parenthesis` support for property accesses and method invocations. #### Migration tool removal diff --git a/DEPS b/DEPS index f8ac44fa50c..dc9320ec3e7 100644 --- a/DEPS +++ b/DEPS @@ -146,7 +146,7 @@ vars = { "http_parser_rev": "1c0c17a1a5d9ca62c85f0940d9edbf2a98209bfa", "intl_rev": "fca552f2ec5d682b5fa36f02bdd72a5a4e2edcee", "json_rpc_2_rev": "0280ac6cb4f3905d81c47ba927123ba2b95f7940", - "linter_rev": "8f7b75f8a3501ca2c4d5bbc1f003d90d66447544", # 1.32.0 + "linter_rev": "70fb087e39e6882ad331ee1e3f52f3f3a88e2d16", # 1.33.0 (+ `unnecessary_parenthesis` fix) "lints_rev": "dfded5e265015f21ce154577fe8488dc244e33c2", "logging_rev": "abef3717d958158eb8b0ddb2871f4b15a9804cd4", "markdown_rev": "ee3f4e976efcfed87c6ec78364bc2dd3c6e717b9", # https://github.com/dart-lang/markdown/pull/494 diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml index aaa22e68585..51f682f739f 100644 --- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml +++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml @@ -1996,6 +1996,10 @@ LintCode.unnecessary_await_in_return: status: needsEvaluation LintCode.unnecessary_brace_in_string_interps: status: hasFix +LintCode.unnecessary_breaks: + status: needsFix + notes: |- + https://github.com/dart-lang/sdk/issues/49960 LintCode.unnecessary_const: status: hasFix LintCode.unnecessary_constructor_name: diff --git a/pkg/analysis_server/test/lsp/code_actions_fixes_test.dart b/pkg/analysis_server/test/lsp/code_actions_fixes_test.dart index 41acfa75dc6..4006329a630 100644 --- a/pkg/analysis_server/test/lsp/code_actions_fixes_test.dart +++ b/pkg/analysis_server/test/lsp/code_actions_fixes_test.dart @@ -4,6 +4,8 @@ import 'package:analysis_server/lsp_protocol/protocol.dart'; import 'package:analysis_server/src/analysis_server.dart'; +import 'package:analyzer/src/lint/linter.dart'; +import 'package:analyzer/src/lint/registry.dart'; import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin; import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; import 'package:linter/src/rules.dart'; @@ -19,6 +21,18 @@ void main() { }); } +/// A version of `camel_case_types` that is deprecated. +class DeprecatedCamelCaseTypes extends LintRule { + DeprecatedCamelCaseTypes() + : super( + name: 'camel_case_types', + group: Group.style, + state: State.deprecated(), + description: '', + details: '', + ); +} + @reflectiveTest class FixesCodeActionsTest extends AbstractCodeActionsTest { /// Helper to check plugin fixes for [filePath]. @@ -84,40 +98,57 @@ class FixesCodeActionsTest extends AbstractCodeActionsTest { Future test_analysisOptions() async { registerLintRules(); - const content = r''' + + // To ensure there's an associated code action, we manually deprecate an + // existing lint (`camel_case_types`) for the duration of this test. + + // Fetch the "actual" lint so we can restore it after the test. + var camelCaseTypes = Registry.ruleRegistry.getRule('camel_case_types')!; + + // Overwrite it. + Registry.ruleRegistry.register(DeprecatedCamelCaseTypes()); + + // Now we can assume it will have an action associated... + + try { + const content = r''' linter: rules: - prefer_is_empty - - [[invariant_booleans]] + - [[camel_case_types]] - lines_longer_than_80_chars '''; - const expectedContent = r''' + const expectedContent = r''' linter: rules: - prefer_is_empty - lines_longer_than_80_chars '''; - newFile(analysisOptionsPath, withoutMarkers(content)); - await initialize( - textDocumentCapabilities: withCodeActionKinds( - emptyTextDocumentClientCapabilities, [CodeActionKind.QuickFix]), - ); + newFile(analysisOptionsPath, withoutMarkers(content)); + await initialize( + textDocumentCapabilities: withCodeActionKinds( + emptyTextDocumentClientCapabilities, [CodeActionKind.QuickFix]), + ); - // Expect a fix. - final codeActions = await getCodeActions(analysisOptionsUri, - range: rangeFromMarkers(content)); - final fix = findEditAction(codeActions, - CodeActionKind('quickfix.removeLint'), "Remove 'invariant_booleans'")!; + // Expect a fix. + final codeActions = await getCodeActions(analysisOptionsUri, + range: rangeFromMarkers(content)); + final fix = findEditAction(codeActions, + CodeActionKind('quickfix.removeLint'), "Remove 'camel_case_types'")!; - // Ensure it makes the correct edits. - final edit = fix.edit!; - final contents = { - analysisOptionsPath: withoutMarkers(content), - }; - applyChanges(contents, edit.changes!); - expect(contents[analysisOptionsPath], equals(expectedContent)); + // Ensure it makes the correct edits. + final edit = fix.edit!; + final contents = { + analysisOptionsPath: withoutMarkers(content), + }; + applyChanges(contents, edit.changes!); + expect(contents[analysisOptionsPath], equals(expectedContent)); + } finally { + // Restore the "real" `camel_case_types`. + Registry.ruleRegistry.register(camelCaseTypes); + } } Future test_appliesCorrectEdits_withDocumentChangesSupport() async { diff --git a/pkg/analysis_server/test/src/plugin/result_converter_test.dart b/pkg/analysis_server/test/src/plugin/result_converter_test.dart index 220ca9adac3..4abd37f2274 100644 --- a/pkg/analysis_server/test/src/plugin/result_converter_test.dart +++ b/pkg/analysis_server/test/src/plugin/result_converter_test.dart @@ -19,23 +19,6 @@ void main() { @reflectiveTest class ResultConverterTest extends ProtocolTestUtilities { - static const List strings = [ - 'a', - 'b', - 'c', - 'd', - 'e', - 'f', - 'g', - 'h', - 'i', - 'j', - 'k', - 'l', - 'm', - 'n' - ]; - ResultConverter converter = ResultConverter(); void test_convertAnalysisErrorFixes() { diff --git a/pkg/analysis_server/test/src/services/correction/fix/analysis_options/remove_lint_test.dart b/pkg/analysis_server/test/src/services/correction/fix/analysis_options/remove_lint_test.dart index deb6eb4ac81..7ff11672b4d 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/analysis_options/remove_lint_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/analysis_options/remove_lint_test.dart @@ -24,7 +24,7 @@ class RemoveLintTest extends AnalysisOptionsFixTest { linter: rules: - camel_case_types - - super_goes_last + - avoid_returning_null ''', ''' linter: rules: @@ -36,7 +36,7 @@ linter: await assertHasFix(''' linter: rules: - - super_goes_last + - avoid_returning_null ''', ''' '''); } @@ -46,7 +46,7 @@ linter: linter: rules: - camel_case_types - - super_goes_last + - avoid_returning_null section: - foo ''', ''' @@ -67,7 +67,7 @@ analyzer: linter: rules: - camel_case_types - - super_goes_last + - avoid_returning_null ''', ''' analyzer: exclude: diff --git a/pkg/analysis_server/test/src/services/correction/fix/analysis_options/test_support.dart b/pkg/analysis_server/test/src/services/correction/fix/analysis_options/test_support.dart index 3e75f38c25b..84987c790a6 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/analysis_options/test_support.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/analysis_options/test_support.dart @@ -6,6 +6,7 @@ import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; import 'package:analysis_server/src/services/correction/fix/analysis_options/fix_generator.dart'; import 'package:analyzer/error/error.dart'; import 'package:analyzer/src/generated/source.dart'; +import 'package:analyzer/src/lint/state.dart'; import 'package:analyzer/src/task/options.dart'; import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart'; import 'package:analyzer_plugin/protocol/protocol_common.dart' @@ -47,7 +48,7 @@ class AnalysisOptionsFixTest with ResourceProviderMixin { content, sourceFactory, '/', - null, + dart2_12, ); if (errorFilter != null) { if (errors.length == 1) { diff --git a/pkg/analysis_server/test/stress/replay/replay.dart b/pkg/analysis_server/test/stress/replay/replay.dart index 8988b189dd1..0b65f364eb1 100644 --- a/pkg/analysis_server/test/stress/replay/replay.dart +++ b/pkg/analysis_server/test/stress/replay/replay.dart @@ -50,6 +50,7 @@ class Driver { static String OVERLAY_STYLE_OPTION_NAME = 'overlay-style'; /// The name of the branch used to clean-up after making temporary changes. + // ignore: unreachable_from_main static const String TEMP_BRANCH_NAME = 'temp'; /// The name of the command-line flag that will cause verbose output to be diff --git a/pkg/analysis_server/tool/code_completion/relevance_metrics.dart b/pkg/analysis_server/tool/code_completion/relevance_metrics.dart index 254802dad67..0c00310f979 100644 --- a/pkg/analysis_server/tool/code_completion/relevance_metrics.dart +++ b/pkg/analysis_server/tool/code_completion/relevance_metrics.dart @@ -116,6 +116,7 @@ class RelevanceData { /// A number identifying the version of this code that produced a given JSON /// encoded file. The number should be incremented whenever the shape of the /// JSON file is changed. + // ignore: unreachable_from_main static const String currentVersion = '1'; /// A table mapping match distances to counts by kind of distance. diff --git a/pkg/analyzer_utilities/analysis_options.yaml b/pkg/analyzer_utilities/analysis_options.yaml index 3596ce5c235..712121e243a 100644 --- a/pkg/analyzer_utilities/analysis_options.yaml +++ b/pkg/analyzer_utilities/analysis_options.yaml @@ -12,7 +12,6 @@ linter: # Enable when we require Dart 2.19.0. #- dangling_library_doc_comments - depend_on_referenced_packages - - enable_null_safety - implicit_call_tearoffs - library_annotations - unawaited_futures diff --git a/pkg/test_runner/analysis_options.yaml b/pkg/test_runner/analysis_options.yaml index 3f45629968a..bd9e22af3b5 100644 --- a/pkg/test_runner/analysis_options.yaml +++ b/pkg/test_runner/analysis_options.yaml @@ -7,7 +7,6 @@ analyzer: linter: rules: avoid_bool_literals_in_conditional_expressions: true - avoid_returning_null: true avoid_unused_constructor_parameters: true cancel_subscriptions: true comment_references: true