Skip to content
Closed
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
4 changes: 3 additions & 1 deletion pkg/linter/lib/src/rules/unreachable_from_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ class _DeclarationGatherer {
rawName.startsWith('test_') ||
rawName.startsWith('solo_test_') ||
rawName == 'setUp' ||
rawName == 'tearDown';
rawName == 'tearDown' ||
rawName == 'setUpClass' ||
rawName == 'tearDownClass';
if (!isOverride(element) && !isTestMethod) {
declarations.add(member);
}
Expand Down
46 changes: 46 additions & 0 deletions pkg/linter/test/rules/unreachable_from_main_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,29 @@ mixin M {}
);
}

test_setUpClass_class_static_member_reachable() async {
await assertNoDiagnostics('''
void main() {
A();
}

final class A {
static setUpClass() {}
}
''');
}

test_setUpClass_top_level_unreachable() async {
await assertDiagnostics(
'''
void main() {}

setUpClass() {}
''',
[lint(16, 10)],
);
}

test_staticField_unreachable() async {
await assertDiagnostics(
r'''
Expand Down Expand Up @@ -1349,6 +1372,29 @@ class C {
);
}

test_tearDownClass_class_static_member_reachable() async {
await assertNoDiagnostics('''
void main() {
A();
}

final class A {
static tearDownClass() {}
}
''');
}

test_tearDownClass_top_level_unreachable() async {
await assertDiagnostics(
'''
void main() {}

tearDownClass() {}
''',
[lint(16, 13)],
);
}

test_topLevelFunction_reachable() async {
await assertNoDiagnostics(r'''
void main() {
Expand Down