Skip to main content

prefer-test-name-first

effort: 2m
has IDE fix
pro+

Suggests having the name of a test invocation or test group as its first argument.

Example​

❌ Bad:

void main() {
// LINT: The name of a test or group should go before the other arguments.
// Try moving the name above other arguments.
test(() {
final array = [1, 2, 3];
expect(array, hasLength(1));
}, 'some test');

// LINT: The name of a test or group should go before the other arguments.
// Try moving the name above other arguments.
group(skip: true, 'some group', () {
test('some test', () {
final array = [1, 2, 3];
expect(array, hasLength(1));
});
});
}

✅ Good:

void main() {
test('some test', () {
final array = [1, 2, 3];
expect(array, hasLength(1));
});

group('some group', skip: true, () {
test('some test', () {
final array = [1, 2, 3];
expect(array, hasLength(1));
});
});
}