1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-03 00:08:46 +00:00

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 <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
This commit is contained in:
pq 2023-02-07 20:56:35 +00:00 committed by Commit Queue
parent 8e0b66b3c0
commit ad2da86f18
11 changed files with 82 additions and 48 deletions

View File

@ -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<dynamic>?` to parameters
typed `FutureOr<void>?`.
- 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

2
DEPS
View File

@ -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

View File

@ -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:

View File

@ -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<void> 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<void> test_appliesCorrectEdits_withDocumentChangesSupport() async {

View File

@ -19,23 +19,6 @@ void main() {
@reflectiveTest
class ResultConverterTest extends ProtocolTestUtilities {
static const List<String> strings = <String>[
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n'
];
ResultConverter converter = ResultConverter();
void test_convertAnalysisErrorFixes() {

View File

@ -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:

View File

@ -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) {

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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