Skip to main content

prefer-assert-initializers-first

effort: 2m
has IDE fix
has auto-fix
pro+

Suggests placing assert initializers at the beginning of the initializer list.

Example

❌ Bad:

class SomeClass {
final String value;
final int another;

SomeClass(int val, int some)
: value = '123',
// LINT: Prefer placing assert initializers at the beginning of the initializer list.
assert(val > 0),
another = 123,
// LINT: Prefer placing assert initializers at the beginning of the initializer list.
assert(some > 2);
}

✅ Good:

class SomeClass {
final String value;
final int another;

SomeClass(int val, int some)
: assert(val > 0),
assert(some > 2),
value = '123',
another = 123;
}