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>
213 lines
4.1 KiB
Dart
213 lines
4.1 KiB
Dart
// Copyright (c) 2024, 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:test_reflective_loader/test_reflective_loader.dart';
|
|
|
|
import '../rule_test_support.dart';
|
|
|
|
void main() {
|
|
defineReflectiveSuite(() {
|
|
defineReflectiveTests(AvoidFutureOrVoidTest);
|
|
});
|
|
}
|
|
|
|
@reflectiveTest
|
|
class AvoidFutureOrVoidTest extends LintRuleTest {
|
|
@override
|
|
String get lintRule => LintNames.avoid_futureor_void;
|
|
|
|
test_asExpression() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
var x = 1 as [!FutureOr<void>!];
|
|
''');
|
|
}
|
|
|
|
test_castPattern() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
f() {
|
|
// ignore: unnecessary_cast_pattern
|
|
var [Object? x as [!FutureOr<void>!]] = [1];
|
|
return x;
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_class_bound() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
class A<X extends [!FutureOr<void>!]> {}
|
|
''');
|
|
}
|
|
|
|
test_enum_bound() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
enum E<X extends [!FutureOr<void>!]> {
|
|
one;
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_extension_bound() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
extension E<X extends [!FutureOr<void>!]> on X {}
|
|
''');
|
|
}
|
|
|
|
test_extensionOnClause() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
extension E on [!FutureOr<void>!] {}
|
|
''');
|
|
}
|
|
|
|
test_extensionType_bound() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
extension type E<X extends [!FutureOr<void>!]>(X x) {}
|
|
''');
|
|
}
|
|
|
|
test_extensionType_representation() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
extension type E([!FutureOr<void>!] _) {}
|
|
''');
|
|
}
|
|
|
|
test_function_bound() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
void f<X extends [!FutureOr<void>!]>(List<X> x) {}
|
|
''');
|
|
}
|
|
|
|
test_functionTypedFormalParameter_bound() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
void f(g<X extends [!FutureOr<void>!]>(X x)) {}
|
|
''');
|
|
}
|
|
|
|
test_functionTypedFormalParameter_parameter1() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
void f(g([!FutureOr<void>!] x)) {}
|
|
''');
|
|
}
|
|
|
|
test_functionTypedFormalParameter_parameter2() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
void f(g([[!FutureOr<void>!] x])) {}
|
|
''');
|
|
}
|
|
|
|
test_functionTypedFormalParameter_parameter3() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
void f(g({required [!FutureOr<void>!] name})) {}
|
|
''');
|
|
}
|
|
|
|
test_functionTypedFormalParameter_return() async {
|
|
await assertNoDiagnostics(r'''
|
|
import 'dart:async';
|
|
|
|
void f(FutureOr<void> g()) {}
|
|
''');
|
|
}
|
|
|
|
test_isExpression() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
// ignore: unnecessary_type_check
|
|
var x = 1 is [!FutureOr<void>!];
|
|
''');
|
|
}
|
|
|
|
test_mixin_bound() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
mixin A<X extends [!FutureOr<void>!]> {}
|
|
''');
|
|
}
|
|
|
|
test_objectPattern() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
f(Object? x) {
|
|
if (x case [!FutureOr<void>!]()) return;
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_oldTypeAlias_bound() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
typedef void F<X extends [!FutureOr<void>!]>(X arg);
|
|
''');
|
|
}
|
|
|
|
test_oldTypeAlias_parameter() async {
|
|
await assertNoDiagnostics(r'''
|
|
import 'dart:async';
|
|
|
|
typedef void F(FutureOr<void> arg);
|
|
''');
|
|
}
|
|
|
|
test_oldTypeAlias_return() async {
|
|
await assertNoDiagnostics(r'''
|
|
import 'dart:async';
|
|
|
|
typedef FutureOr<void> F();
|
|
''');
|
|
}
|
|
|
|
test_typeAlias_body() async {
|
|
await assertNoDiagnostics(r'''
|
|
import 'dart:async';
|
|
|
|
typedef F = FutureOr<void>;
|
|
''');
|
|
}
|
|
|
|
test_typeAlias_body2() async {
|
|
await assertNoDiagnostics(r'''
|
|
import 'dart:async';
|
|
|
|
typedef F = void Function(FutureOr<void>);
|
|
''');
|
|
}
|
|
|
|
test_typeAlias_bound() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import 'dart:async';
|
|
|
|
typedef F<X extends [!FutureOr<void>!]> = int;
|
|
''');
|
|
}
|
|
}
|