Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Test diagnostic cleanup #2997

Merged
merged 2 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/rules/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ import 'prefer_const_constructors_in_immutables.dart'
import 'prefer_const_literals_to_create_immutables.dart'
as prefer_const_literals_to_create_immutables;
import 'prefer_contains.dart' as prefer_contains;
import 'prefer_generic_function_type_aliases.dart'
as prefer_generic_function_type_aliases;
import 'prefer_spread_collections.dart' as prefer_spread_collections;
import 'super_goes_last.dart' as super_goes_last;
import 'type_init_formals.dart' as type_init_formals;
import 'unawaited_futures.dart' as unawaited_futures;
import 'unnecessary_null_checks.dart' as unnecessary_null_checks;
import 'void_checks.dart' as void_checks;

void main() {
Expand All @@ -35,8 +39,11 @@ void main() {
prefer_const_constructors_in_immutables.main();
prefer_const_literals_to_create_immutables.main();
prefer_contains.main();
prefer_generic_function_type_aliases.main();
prefer_spread_collections.main();
super_goes_last.main();
type_init_formals.main();
unawaited_futures.main();
unnecessary_null_checks.main();
void_checks.main();
}
30 changes: 30 additions & 0 deletions test/rules/prefer_generic_function_type_aliases.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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:test_reflective_loader/test_reflective_loader.dart';

import '../rule_test_support.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(PreferGenericFunctionTypeAliasesTest);
});
}

@reflectiveTest
class PreferGenericFunctionTypeAliasesTest extends LintRuleTest {
@override
String get lintRule => 'prefer_generic_function_type_aliases';

/// https://github.com/dart-lang/linter/issues/2777
test_undefinedFunction() async {
await assertDiagnostics(r'''
typedef Cb2
''', [
// No lint
error(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, 12, 0),
error(ParserErrorCode.EXPECTED_TOKEN, 12, 0),
]);
}
}
39 changes: 39 additions & 0 deletions test/rules/super_goes_last.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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:test_reflective_loader/test_reflective_loader.dart';

import '../rule_test_support.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(SuperGoesLastTest);
});
}

@reflectiveTest
class SuperGoesLastTest extends LintRuleTest {
@override
String get lintRule => 'super_goes_last';

test_invalidSuperInvocation() async {
await assertDiagnostics(r'''
class A {
int a;
A(this.a);
}

class C extends A {
int _c;
C(int a)
: super(a), _c = a + 1;
}

''', [
error(HintCode.UNUSED_FIELD, 61, 2),
error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 84, 5),
lint('super_goes_last', 84, 8),
]);
}
}
30 changes: 30 additions & 0 deletions test/rules/unnecessary_null_checks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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:test_reflective_loader/test_reflective_loader.dart';

import '../rule_test_support.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(UnnecessaryNullChecksTest);
});
}

@reflectiveTest
class UnnecessaryNullChecksTest extends LintRuleTest {
@override
String get lintRule => 'unnecessary_null_checks';

test_undefinedFunction() async {
await assertDiagnostics(r'''
f6(int? p) {
return B() + p!; // OK
}
''', [
// No lint
error(CompileTimeErrorCode.UNDEFINED_FUNCTION, 22, 1),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class A {
@override
operator ==(other) => other is A && other.key == key; // OK
@override
int hashCode() => key.hashCode; // OK
int get hashCode => key.hashCode; // OK
}

class B {
Expand All @@ -22,7 +22,7 @@ class B {
@override
operator ==(other) => other is B && other.key == key; // LINT
@override
int hashCode() => key.hashCode; // LINT
int get hashCode => key.hashCode; // LINT
}

@immutable
Expand Down
16 changes: 8 additions & 8 deletions test_data/rules/avoid_redundant_argument_values.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import 'package:meta/meta.dart';

class A {
A({bool valWithDefault = true, bool val});
void f({bool valWithDefault = true, bool val}) {}
void g({int valWithDefault = 1, bool val}) {}
void h({String valWithDefault = 'default', bool val}) {}
A({bool valWithDefault = true, bool? val});
void f({bool valWithDefault = true, bool? val}) {}
void g({int valWithDefault = 1, bool? val}) {}
void h({String valWithDefault = 'default', bool? val}) {}
}


Expand All @@ -21,14 +21,14 @@ f(void g([bool b = false])) {

bool q() => true;

void ff({bool valWithDefault = true, bool val}) {}
void g({@required bool valWithDefault = true, bool val}) {}
void ff({bool valWithDefault = true, bool? val}) {}
void g({@required bool valWithDefault = true, bool? val}) {}

void gg(int x, [int y = 0]) {}
void ggg([int a = 1, int b = 2]) {}
void gggg([int a = 0, int b]) {}
void gggg([int a = 0, int? b]) {}

void h([int a, int b = 1]) {}
void h([int? a, int? b = 1]) {}

void main() {

Expand Down
2 changes: 1 addition & 1 deletion test_data/rules/avoid_relative_lib_imports.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

// test w/ `dart test -N avoid_relative_lib_imports`

import '../_data/avoid_relative_lib_imports/lib/dummy.dart'; //LINT
import '../integration/avoid_relative_lib_imports/lib/dummy.dart'; //LINT
import 'avoid_catching_errors.dart'; //OK

Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ abstract class BBB {
abstract final String s;
}

class AAA extends BBB {
class AAAA extends BBB {
@override
String s = ''; // OK
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,3 @@ f5(int? p) {
v1 ??= p!; // OK
}

f6(int? p) {
return B() + p!; // OK
}

4 changes: 2 additions & 2 deletions test_data/rules/no_logic_in_create_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import 'package:flutter/widgets.dart';

class MyState extends State {
int field;
int field = 0;
}

class MyStatefulOK extends StatefulWidget {
Expand All @@ -24,7 +24,7 @@ class MyStatefulOK2 extends StatefulWidget {
}


MyState global;
MyState global = MyState();

class MyStatefulBad extends StatefulWidget {
@override
Expand Down
4 changes: 0 additions & 4 deletions test_data/rules/prefer_generic_function_type_aliases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@

// test w/ `dart test -N prefer_generic_function_type_aliases`


//https://github.com/dart-lang/linter/issues/2777
typedef Cb2 // OK

typedef void F1(); // LINT
typedef F2 = void Function(); // OK