avoid-top-level-members-in-tests
- Group
- Suspicious
- Path
lint/suspicious/avoid-top-level-members-in-tests- Default
- Off, opt in
- Origin
- Falcon
- Domain
- test
- Rule
- 147 of 512
Requires public declarations in test files, except main, to be private.
Private test helpers and fixtures cannot accidentally become another file's API and can be identified as unused without cross-library consumers.
Invalid
import 'package:test/test.dart';
var count = 0;
const value = 1;
final values = <int>[];
void helper() {}
class Helper {}
mixin Behavior {}
enum Choice { first }
extension Description on int { String describe() => '$this'; }
typedef Callback = void Function();
void main() { test('case', () {}); }import 'package:test/test.dart';var count = 0;var count = 0;const value = 1;const value = 1;final values = <int>[];final values = <int>[];void helper() {}void helper() {}class Helper {}class Helper {}mixin Behavior {}mixin Behavior {}enum Choice { first }enum Choice { first }extension Description on int { String describe() => '$this'; }extension Description on int { String describe() => '$this'; }typedef Callback = void Function();Valid
import 'package:test/test.dart';
var _count = 0;
const _value = 1;
final _values = <int>[];
void _helper() {}
class _Helper { int publicMember = 1; }
mixin _Behavior {}
enum _Choice { first }
extension _Description on int { String describe() => '$this'; }
extension on String { int get lengthTwice => length * 2; }
typedef _Callback = void Function();
void main() { var local = 0; test('case', () { local++; }); }Configure avoid-top-level-members-in-tests
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"avoid-top-level-members-in-tests": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-top-level-members-in-tests: <reason>More suspicious rules
- avoid-types-as-parameter-names
avoid_types_as_parameter_namesrecommendedFlags implicit formal parameters, catch variables, and type parameters that shadow a type in their enclosing scope.
- avoid-unrelated-type-assertions
avoid-unrelated-type-assertionsrecommendedFlags an
ischeck proven impossible by canonical resolved types. - banned-usage
Ban resolved API references, not identifiers that merely share their spelling.
- cascade-after-null-coalescing
Flags a cascade after an unparenthesized null-coalescing expression.
- control-flow-in-finally
control_flow_in_finallyrecommendedFlags
return,break, orcontinuethat escapes afinallyblock. - empty-catches
empty_catchesrecommendedFlags empty
catchblocks. - empty-statements
empty_statementsrecommendedFlags stray empty statements (a lone
;). - no-duplicate-case-values
no_duplicate_case_valuesrecommendedFlags semantically equal constant values within one switch.