a16de199d7
This is a rediculously large CL, and if you want me to split it up I'm willing to do so. However, the changes were all made by running a script I wrote and then running the formatter over the code, so hopefully a spot-check will be sufficient. Change-Id: Ifc59b2cc3bf9e4edf0229a130cd587dc73f95615 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505042 Reviewed-by: Samuel Rawlins <srawlins@google.com> SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
124 lines
2.5 KiB
Dart
124 lines
2.5 KiB
Dart
// Copyright (c) 2021, 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.
|
|
|
|
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
|
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
|
|
|
import '../rule_test_support.dart';
|
|
|
|
void main() {
|
|
defineReflectiveSuite(() {
|
|
defineReflectiveTests(NullClosuresTest);
|
|
});
|
|
}
|
|
|
|
@reflectiveTest
|
|
class NullClosuresTest extends LintRuleTest {
|
|
@override
|
|
String get lintRule => LintNames.null_closures;
|
|
|
|
test_futureWait_cleanUp_closure() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f() {
|
|
Future.wait([], cleanUp: (_) => print('clean'));
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_futureWait_cleanUp_null() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
void f() {
|
|
Future.wait([], [!cleanUp: null!]);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_iterableFirstWhere_orElse_null() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
void f(List<int> list) {
|
|
list.firstWhere((e) => e.isEven, [!orElse: null!]);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_iterableSingleWhere_orElse_closure() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f(List<int?> list) {
|
|
list.singleWhere((e) => e?.isEven ?? false, orElse: () => null);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_iterableSingleWhere_orElse_null() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
void f(Set<int> set) {
|
|
set.singleWhere((e) => e.isEven, [!orElse: null!]);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_iterableWhere_noOrElse() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f(List<int> list) {
|
|
list.where((e) => e.isEven);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_listGenerate_closure() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f() {
|
|
new List.generate(3, (_) => null);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_mapKeys() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f(Map<int, int> map) {
|
|
map.keys;
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_mapOtherMethod() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f(Map<int, int> map) {
|
|
map.addAll({});
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_mapPutIfAbsent_closure() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f(Map<int, int?> map) {
|
|
map.putIfAbsent(7, () => null);
|
|
}
|
|
''');
|
|
}
|
|
|
|
///https://github.com/dart-lang/linter/issues/1414
|
|
test_recursiveInterfaceInheritance() async {
|
|
await assertDiagnostics(
|
|
r'''
|
|
class A extends B {
|
|
A(int x);
|
|
}
|
|
|
|
class B extends A {}
|
|
|
|
void test_cycle() {
|
|
A(null);
|
|
}
|
|
''',
|
|
[
|
|
// No lint
|
|
error(diag.recursiveInterfaceInheritance, 6, 1),
|
|
error(diag.recursiveInterfaceInheritance, 41, 1),
|
|
error(diag.argumentTypeNotAssignable, 81, 4),
|
|
],
|
|
);
|
|
}
|
|
}
|