prefer-asserts-with-message
Same as prefer_asserts_with_message in Dart lints
- Group
- Style
- Path
lint/style/prefer-asserts-with-message- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 315 of 512
Flags assert statements and assert initializers that have no message.
When an assertion fails, the message is the only hint about why the invariant mattered. Supply one as the second argument:
assert(count >= 0); // flagged
assert(count >= 0, 'count must not be negative'); // ok
Invalid
// Asserts without a message.
class Range {
final int start;
final int end;
Range(this.start, this.end) : assert(start <= end);
Range.unit(this.start)
: end = start + 1,
assert(start >= 0);
}
void check(int value, List<int> items) {
assert(value > 0);
assert(items.isNotEmpty);
if (value > 10) {
assert(value < 100);
}
final f = () {
assert(items.length < 5);
};
f();
} final int end; Range(this.start, this.end) : assert(start <= end); : end = start + 1, assert(start >= 0);void check(int value, List<int> items) { assert(value > 0); assert(value > 0); assert(items.isNotEmpty); if (value > 10) { assert(value < 100); final f = () { assert(items.length < 5);Valid
// Asserts that carry a message.
class Range {
final int start;
final int end;
Range(this.start, this.end) : assert(start <= end, 'start must not exceed end');
Range.unit(this.start)
: end = start + 1,
assert(start >= 0, 'start must be non-negative');
}
void check(int value, List<int> items) {
assert(value > 0, 'value must be positive');
assert(items.isNotEmpty, 'items must not be empty');
assert(() {
return true;
}(), 'debug-only check');
if (value > 10) {
assert(value < 100, 'value is too large: $value');
}
}Configure prefer-asserts-with-message
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-asserts-with-message": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-asserts-with-message: <reason>More style rules
- prefer-async-await
prefer-async-awaitFlags
.then(...)future chains that should useasync/await. - prefer-async-callback
prefer_async_callbackflutterFlags the type
Future<void> Function()in favor of Flutter'sAsyncCallback. - prefer-bloc-event-suffixbloc
Enforce the package-confirmed Bloc convention.
- prefer-bloc-extensionsbloc
Prefer context.read/watch over
package:flutter_bloc's provider lookups. - prefer-bloc-state-suffixbloc
Enforce the package-confirmed Bloc convention.
- prefer-center-over-alignflutter
Prefers
Centerover anAlignwhose alignment is known to be centered. - prefer-collection-literals
prefer_collection_literalsrecommendedFlags no-argument collection constructor calls that a literal would express.
- prefer-commenting-analyzer-ignores
Require explanations for analyzer
ignore:andignore_for_file:comments.