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

Commit cf4fbcd

Browse files
authored
Move unnecessary_constructor_name tests (#4501)
1 parent 9012511 commit cf4fbcd

File tree

3 files changed

+72
-15
lines changed

3 files changed

+72
-15
lines changed

test/rules/all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ import 'unnecessary_brace_in_string_interps_test.dart'
133133
as unnecessary_brace_in_string_interps;
134134
import 'unnecessary_breaks_test.dart' as unnecessary_breaks;
135135
import 'unnecessary_const_test.dart' as unnecessary_const;
136+
import 'unnecessary_constructor_name_test.dart' as unnecessary_constructor_name;
136137
import 'unnecessary_final_test.dart' as unnecessary_final;
137138
import 'unnecessary_lambdas_test.dart' as unnecessary_lambdas;
138139
import 'unnecessary_library_directive_test.dart'
@@ -261,6 +262,7 @@ void main() {
261262
unnecessary_brace_in_string_interps.main();
262263
unnecessary_breaks.main();
263264
unnecessary_const.main();
265+
unnecessary_constructor_name.main();
264266
unnecessary_final.main();
265267
unnecessary_lambdas.main();
266268
unnecessary_library_directive.main();
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:test_reflective_loader/test_reflective_loader.dart';
6+
7+
import '../rule_test_support.dart';
8+
9+
main() {
10+
defineReflectiveSuite(() {
11+
defineReflectiveTests(UnnecessaryConstructorNameTest);
12+
});
13+
}
14+
15+
@reflectiveTest
16+
class UnnecessaryConstructorNameTest extends LintRuleTest {
17+
@override
18+
String get lintRule => 'unnecessary_constructor_name';
19+
20+
test_constructorDeclaration_named() async {
21+
await assertNoDiagnostics(r'''
22+
class A {
23+
A.ok();
24+
}
25+
''');
26+
}
27+
28+
test_constructorDeclaration_new() async {
29+
await assertDiagnostics(r'''
30+
class A {
31+
A.new();
32+
}
33+
''', [
34+
lint(14, 3),
35+
]);
36+
}
37+
38+
test_constructorTearoff_new() async {
39+
await assertNoDiagnostics(r'''
40+
class A {
41+
}
42+
var makeA = A.new;
43+
''');
44+
}
45+
46+
test_instanceCreation_named() async {
47+
await assertNoDiagnostics(r'''
48+
class A {
49+
A.ok();
50+
}
51+
var aaa = A.ok();
52+
''');
53+
}
54+
55+
test_instanceCreation_new() async {
56+
await assertDiagnostics(r'''
57+
class A {}
58+
var a = A.new();
59+
''', [
60+
lint(21, 3),
61+
]);
62+
}
63+
64+
test_instanceCreation_unnamed() async {
65+
await assertNoDiagnostics(r'''
66+
class A {}
67+
var aa = A();
68+
''');
69+
}
70+
}

test_data/rules/unnecessary_constructor_name.dart

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)