Skip to content

Commit 27e8a4a

Browse files
RohitSailyCommit Queue
authored andcommitted
unreachable_from_main: exempt setUpClass, tearDownClass
Closes #61528 GitOrigin-RevId: a273eb8 Change-Id: Icb0c309eb15f579b2d431911bd5273240ce00383 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450182 Reviewed-by: Keerti Parthasarathy <[email protected]> Commit-Queue: Keerti Parthasarathy <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 91b26a3 commit 27e8a4a

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

pkg/linter/lib/src/rules/unreachable_from_main.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ class _DeclarationGatherer {
129129
rawName.startsWith('test_') ||
130130
rawName.startsWith('solo_test_') ||
131131
rawName == 'setUp' ||
132-
rawName == 'tearDown';
132+
rawName == 'tearDown' ||
133+
rawName == 'setUpClass' ||
134+
rawName == 'tearDownClass';
133135
if (!isOverride(element) && !isTestMethod) {
134136
declarations.add(member);
135137
}

pkg/linter/test/rules/unreachable_from_main_test.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,29 @@ mixin M {}
11511151
);
11521152
}
11531153

1154+
test_setUpClass_class_static_member_reachable() async {
1155+
await assertNoDiagnostics('''
1156+
void main() {
1157+
A();
1158+
}
1159+
1160+
final class A {
1161+
static setUpClass() {}
1162+
}
1163+
''');
1164+
}
1165+
1166+
test_setUpClass_top_level_unreachable() async {
1167+
await assertDiagnostics(
1168+
'''
1169+
void main() {}
1170+
1171+
setUpClass() {}
1172+
''',
1173+
[lint(16, 10)],
1174+
);
1175+
}
1176+
11541177
test_staticField_unreachable() async {
11551178
await assertDiagnostics(
11561179
r'''
@@ -1349,6 +1372,29 @@ class C {
13491372
);
13501373
}
13511374

1375+
test_tearDownClass_class_static_member_reachable() async {
1376+
await assertNoDiagnostics('''
1377+
void main() {
1378+
A();
1379+
}
1380+
1381+
final class A {
1382+
static tearDownClass() {}
1383+
}
1384+
''');
1385+
}
1386+
1387+
test_tearDownClass_top_level_unreachable() async {
1388+
await assertDiagnostics(
1389+
'''
1390+
void main() {}
1391+
1392+
tearDownClass() {}
1393+
''',
1394+
[lint(16, 13)],
1395+
);
1396+
}
1397+
13521398
test_topLevelFunction_reachable() async {
13531399
await assertNoDiagnostics(r'''
13541400
void main() {

0 commit comments

Comments
 (0)