linter: Remove two deprecated linter rules

Fixes https://github.com/dart-lang/linter/issues/4800

Change-Id: I4eef17ca19ea7469fba372c28eef7618249c48dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334080
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Sam Rawlins 2023-11-09 17:03:15 +00:00 committed by Commit Queue
parent 682c82a7a6
commit 93541c708c
9 changed files with 13 additions and 470 deletions

View file

@ -28,6 +28,7 @@ linter:
- camel_case_extensions
- camel_case_types
- cancel_subscriptions
- collection_methods_unrelated_type
- comment_references
#- constant_identifier_names
- control_flow_in_finally
@ -38,8 +39,6 @@ linter:
- empty_statements
- hash_and_equals
- implementation_imports
#- invariant_booleans
- collection_methods_unrelated_type
- library_names
- library_prefixes
#- literal_only_boolean_expressions

View file

@ -2107,6 +2107,8 @@ LintCode.invariant_booleans:
Removed.
LintCode.iterable_contains_unrelated_type:
status: noFix
notes: |-
Removed.
LintCode.join_return_with_assignment:
status: needsFix
LintCode.leading_newlines_in_multiline_strings:
@ -2131,6 +2133,8 @@ LintCode.lines_longer_than_80_chars:
status: noFix
LintCode.list_remove_unrelated_type:
status: noFix
notes: |-
Removed.
LintCode.literal_only_boolean_expressions:
status: noFix
LintCode.matching_super_parameters:

View file

@ -46,7 +46,8 @@ import 'package:glob/glob.dart';
import 'package:path/path.dart' as p;
export 'package:analyzer/src/lint/linter_visitor.dart' show NodeLintRegistry;
export 'package:analyzer/src/lint/state.dart' show dart2_12, dart3, State;
export 'package:analyzer/src/lint/state.dart'
show dart2_12, dart3, dart3_3, State;
typedef Printer = void Function(String msg);

View file

@ -10,6 +10,9 @@ final Version dart2_12 = Version(2, 12, 0);
/// A version describing Dart language version 3.0.0.
final Version dart3 = Version(3, 0, 0);
/// A version describing Dart language version 3.3.0.
final Version dart3_3 = Version(3, 3, 0);
/// A state that marks a lint as deprecated.
class DeprecatedState extends State {
/// An optional lint name that replaces the rule with this state.

View file

@ -28,6 +28,7 @@ export 'package:analyzer/src/lint/linter.dart'
show
dart2_12,
dart3,
dart3_3,
DartLinter,
Group,
LintFilter,

View file

@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import '../analyzer.dart';
import '../util/unrelated_types_visitor.dart';
const _desc = r'Invocation of Iterable<E>.contains with references of unrelated'
r' types.';
@ -115,10 +114,6 @@ abstract class Mixin {}
class DerivedClass3 extends ClassBase implements Mixin {}
```
**DEPRECATED:** This rule is deprecated in favor of
`collection_methods_unrelated_type`.
The rule will be removed in a future Dart release.
''';
class IterableContainsUnrelatedType extends LintRule {
@ -131,30 +126,9 @@ class IterableContainsUnrelatedType extends LintRule {
description: _desc,
details: _details,
group: Group.errors,
state:
State.deprecated(replacedBy: 'collection_methods_unrelated_type'),
state: State.removed(since: dart3_3),
);
@override
LintCode get lintCode => code;
@override
void registerNodeProcessors(
NodeLintRegistry registry, LinterContext context) {
var visitor = _Visitor(this, context.typeSystem, context.typeProvider);
registry.addMethodInvocation(this, visitor);
}
}
class _Visitor extends UnrelatedTypesProcessors {
_Visitor(super.rule, super.typeSystem, super.typeProvider);
@override
List<MethodDefinition> get methods => [
MethodDefinitionForElement(
typeProvider.iterableElement,
'contains',
ExpectedArgumentKind.assignableToCollectionTypeArgument,
)
];
}

View file

@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import '../analyzer.dart';
import '../util/unrelated_types_visitor.dart';
const _desc = r'Invocation of `remove` with references of unrelated types.';
@ -115,10 +114,6 @@ abstract class Mixin {}
class DerivedClass3 extends ClassBase implements Mixin {}
```
**DEPRECATED:** This rule is deprecated in favor of
`collection_methods_unrelated_type`.
The rule will be removed in a future Dart release.
''';
class ListRemoveUnrelatedType extends LintRule {
@ -131,30 +126,9 @@ class ListRemoveUnrelatedType extends LintRule {
description: _desc,
details: _details,
group: Group.errors,
state:
State.deprecated(replacedBy: 'collection_methods_unrelated_type'),
state: State.removed(since: dart3_3),
);
@override
LintCode get lintCode => code;
@override
void registerNodeProcessors(
NodeLintRegistry registry, LinterContext context) {
var visitor = _Visitor(this, context.typeSystem, context.typeProvider);
registry.addMethodInvocation(this, visitor);
}
}
class _Visitor extends UnrelatedTypesProcessors {
_Visitor(super.rule, super.typeSystem, super.typeProvider);
@override
List<MethodDefinition> get methods => [
MethodDefinitionForElement(
typeProvider.listElement,
'remove',
ExpectedArgumentKind.assignableToCollectionTypeArgument,
),
];
}

View file

@ -1,206 +0,0 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// TODO(https://github.com/dart-lang/linter/issues/4143): Use 3.0.0
// @dart=2.19
void someFunction() {
var list = <int>[];
if (list.contains('1')) print('someFunction'); // LINT
list
..add(1)
..contains('1'); // LINT
}
void someFunction1() {
var list = <int>[];
if (list.contains(1)) print('someFunction1'); // OK
}
void someFunction3() {
List<int> list = <int>[];
if (list.contains('1')) print('someFunction3'); // LINT
}
void someFunction4() {
List<int> list = <int>[];
if (list.contains(1)) print('someFunction4'); // OK
}
void someFunction4_1() {
List<dynamic> list = [];
if (list.contains(null)) print('someFunction4_1');
}
void someFunction5_1() {
List<ClassBase> list = <ClassBase>[];
Object instance = '';
if (list.contains(instance)) print('someFunction5_1'); // OK
}
void someFunction5() {
List<ClassBase> list = <ClassBase>[];
DerivedClass1 instance = DerivedClass1();
if (list.contains(instance)) print('someFunction5'); // OK
}
void someFunction6() {
List<Mixin> list = <Mixin>[];
DerivedClass2 instance = DerivedClass2();
if (list.contains(instance)) print('someFunction6'); // OK
}
class MixedIn with Mixin {}
void someFunction6_1() {
List<DerivedClass2> list = <DerivedClass2>[];
Mixin instance = MixedIn();
if (list.contains(instance)) print('someFunction6_1'); // OK
}
void someFunction7() {
List<Mixin> list = <Mixin>[];
DerivedClass3 instance = DerivedClass3();
if (list.contains(instance)) print('someFunction7'); // OK
}
void someFunction7_1() {
List<DerivedClass3> list = <DerivedClass3>[];
Mixin instance = MixedIn();
if (list.contains(instance)) print('someFunction7_1'); // OK
}
void someFunction8() {
List<DerivedClass2> list = <DerivedClass2>[];
DerivedClass3 instance = DerivedClass3();
if (list.contains(instance)) print('someFunction8'); // OK
}
void someFunction9() {
List<Implementation> list = <Implementation>[];
Abstract instance = new Abstract();
if (list.contains(instance)) print('someFunction9'); // OK
}
void someFunction10() {
var list = [];
if (list.contains(1)) print('someFunction10'); // OK
}
void someFunction11(unknown) {
var what = unknown - 1;
List<int> list = <int>[];
list.forEach((int i) {
if (what == i) print('someFunction11'); // OK
});
}
void someFunction12() {
List<DerivedClass4> list = <DerivedClass4>[];
DerivedClass5 instance = DerivedClass5();
if (list.contains(instance)) print('someFunction12'); // LINT
}
void bug_267(list) {
if (list.contains('1')) // https://github.com/dart-lang/linter/issues/267
print('someFunction');
}
abstract class ClassBase {}
class DerivedClass1 extends ClassBase {}
abstract class Mixin {}
class DerivedClass2 extends ClassBase with Mixin {}
class DerivedClass3 extends ClassBase implements Mixin {}
abstract class Abstract {
factory Abstract() {
return new Implementation();
}
Abstract._internal();
}
class Implementation extends Abstract {
Implementation() : super._internal();
}
class DerivedClass4 extends DerivedClass2 {}
class DerivedClass5 extends DerivedClass3 {}
bool takesIterable(Iterable<int> iterable) => iterable.contains('a'); // LINT
bool takesIterable2(Iterable<String> iterable) => iterable.contains('a'); // OK
bool takesIterable3(Iterable iterable) => iterable.contains('a'); // OK
abstract class A implements Iterable<int> {}
abstract class B extends A {}
bool takesB(B b) => b.contains('a'); // LINT
abstract class A1 implements Iterable<String> {}
abstract class B1 extends A1 {}
bool takesB1(B1 b) => b.contains('a'); // OK
abstract class A3 implements Iterable {}
abstract class B3 extends A3 {}
bool takesB3(B3 b) => b.contains('a'); // OK
abstract class AddlInterface {}
abstract class SomeIterable<E> implements Iterable<E>, AddlInterface {}
abstract class MyClass implements SomeIterable<int> {
bool badMethod(String thing) => this.contains(thing); // LINT
bool badMethod1(String thing) => contains(thing); // LINT
}
abstract class MyDerivedClass extends MyClass {
bool myConcreteBadMethod(String thing) => this.contains(thing); // LINT
bool myConcreteBadMethod1(String thing) => contains(thing); // LINT
}
abstract class MyMixedClass extends Object with MyClass {
bool myConcreteBadMethod(String thing) => this.contains(thing); // LINT
bool myConcreteBadMethod1(String thing) => contains(thing); // LINT
}
abstract class MyIterableMixedClass extends Object
with MyClass
implements Iterable<int> {
bool myConcreteBadMethod(String thing) => this.contains(thing); // LINT
bool myConcreteBadMethod1(String thing) => contains(thing); // LINT
}
enum E implements List<int> {
one,
two;
@override
dynamic noSuchMethod(_) => throw UnsupportedError('');
void f() {
contains('string'); // LINT
this.contains('string'); // LINT
contains(1); // OK
}
}
extension on List<int> {
void f() {
contains('string'); // LINT
this.contains('string'); // LINT
contains(1); // OK
}
}

View file

@ -1,207 +0,0 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
void someFunction() {
var list = <int>[];
if (list.remove('1')) print('someFunction'); // LINT
list
..add(1)
..remove('1'); // LINT
}
void someFunction1() {
var list = <int>[];
if (list.remove(1)) print('someFunction1'); // OK
}
void someFunction3() {
List<int> list = <int>[];
if (list.remove('1')) print('someFunction3'); // LINT
}
void someFunction4() {
List<int> list = <int>[];
if (list.remove(1)) print('someFunction4'); // OK
}
void someFunction4_1() {
List list = [];
if (list.remove(null)) print('someFunction4_1');
}
void someFunction5_1() {
List<ClassBase> list = <ClassBase>[];
Object instance = '';
if (list.remove(instance)) print('someFunction5_1'); // OK
}
void someFunction5() {
List<ClassBase> list = <ClassBase>[];
DerivedClass1 instance = DerivedClass1();
if (list.remove(instance)) print('someFunction5'); // OK
}
void someFunction6() {
List<Mixin> list = <Mixin>[];
DerivedClass2 instance = DerivedClass2();
if (list.remove(instance)) print('someFunction6'); // OK
}
class MixedIn with Mixin {}
void someFunction6_1() {
List<DerivedClass2> list = <DerivedClass2>[];
Mixin instance = MixedIn();
if (list.remove(instance)) print('someFunction6_1'); // OK
}
void someFunction7() {
List<Mixin> list = <Mixin>[];
DerivedClass3 instance = DerivedClass3();
if (list.remove(instance)) print('someFunction7'); // OK
}
void someFunction7_1() {
List<DerivedClass3> list = <DerivedClass3>[];
Mixin instance = MixedIn();
if (list.remove(instance)) print('someFunction7_1'); // OK
}
void someFunction8() {
List<DerivedClass2> list = <DerivedClass2>[];
DerivedClass3 instance = DerivedClass3();
if (list.remove(instance)) print('someFunction8'); // OK
}
void someFunction9() {
List<Implementation> list = <Implementation>[];
Abstract instance = new Abstract();
if (list.remove(instance)) print('someFunction9'); // OK
}
void someFunction10() {
var list = [];
if (list.remove(1)) print('someFunction10'); // OK
}
void someFunction11(unknown) {
var what = unknown - 1;
List<int> list = <int>[];
list.forEach((int i) {
if (what == i) print('someFunction11'); // OK
});
}
void someFunction12() {
List<DerivedClass4> list = <DerivedClass4>[];
DerivedClass5 instance = DerivedClass5();
if (list.remove(instance)) print('someFunction12'); // LINT
}
void bug_267(list) {
if (list.remove('1'))
print('someFunction'); // https://github.com/dart-lang/linter/issues/267
}
abstract class ClassBase {}
class DerivedClass1 extends ClassBase {}
mixin class Mixin {}
class DerivedClass2 extends ClassBase with Mixin {}
class DerivedClass3 extends ClassBase implements Mixin {}
abstract class Abstract {
factory Abstract() {
return new Implementation();
}
Abstract._internal();
}
class Implementation extends Abstract {
Implementation() : super._internal();
}
class DerivedClass4 extends DerivedClass2 {}
class DerivedClass5 extends DerivedClass3 {}
bool takesList(List<int> list) => list.remove('a'); // LINT
bool takesList2(List<String> list) => list.remove('a'); // OK
bool takesList3(List list) => list.remove('a'); // OK
abstract class A implements List<int> {}
abstract class B extends A {}
bool takesB(B b) => b.remove('a'); // LINT
abstract class A1 implements List<String> {}
abstract class B1 extends A1 {}
bool takesB1(B1 b) => b.remove('a'); // OK
abstract class A3 implements List {}
abstract class B3 extends A3 {}
bool takesB3(B3 b) => b.remove('a'); // OK
abstract class A2 implements List<String> {}
abstract class B2 extends A2 {}
bool takesB2(B2 b) => b.remove('a'); // OK
abstract class SomeList<E> implements List<E> {}
abstract mixin class MyClass implements SomeList<int> {
bool badMethod(String thing) => this.remove(thing); // LINT
bool badMethod1(String thing) => remove(thing); // LINT
}
abstract class MyDerivedClass extends MyClass {
bool myConcreteBadMethod(String thing) => this.remove(thing); // LINT
bool myConcreteBadMethod1(String thing) => remove(thing); // LINT
}
abstract class MyMixedClass extends Object with MyClass {
bool myConcreteBadMethod(String thing) => this.remove(thing); // LINT
bool myConcreteBadMethod1(String thing) => remove(thing); // LINT
}
abstract class MyListMixedClass extends Object
with MyClass
implements List<int> {
bool myConcreteBadMethod(String thing) => this.remove(thing); // LINT
bool myConcreteBadMethod1(String thing) => remove(thing); // LINT
}
enum E implements List<int> {
one,
two;
@override
dynamic noSuchMethod(_) => throw UnsupportedError('');
void f() {
remove('string'); // LINT
this.remove('string'); // LINT
remove(1); // OK
}
}
extension on List<int> {
void f() {
remove('string'); // LINT
this.remove('string'); // LINT
remove(1); // OK
}
}