newline-before-throw
- Group
- Style
- Path
lint/style/newline-before-throw- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 279 of 512
Requires a blank line before a throw that follows another statement.
Checks blocks, including nested bodies and closures. First statements, unbraced throws, and switch-case lists are exempt. Blank lines above attached comments count.
Invalid
void fail(bool condition) {
print('start');
throw StateError('failure');
}
void nested(bool condition) {
if (condition) {
print('nested');
throw StateError('nested');
}
final callback = () {
print('closure');
throw StateError('closure');
};
callback();
}
void cases(int value) {
switch (value) {
case 0: {
print(value);
throw StateError('case block');
}
default:
throw StateError('first');
}
}
void commented() {
print('before');
// No separating blank line.
throw StateError('failure');
} print('start'); throw StateError('failure'); print('nested'); throw StateError('nested'); print('closure'); throw StateError('closure'); print(value); throw StateError('case block'); // No separating blank line. throw StateError('failure');Valid
void first() {
throw StateError('first');
}
void separated() {
print('before');
throw StateError('after blank line');
}
void nested(bool condition) {
if (condition) {
throw StateError('first in nested block');
}
final callback = () {
throw StateError('first in closure');
};
callback();
}
void guarded(bool condition) {
if (condition) throw StateError('unbraced');
}
void cases(int value) {
switch (value) {
default:
throw StateError('first');
}
}
void followingCaseStatement(int value) {
switch (value) {
default:
print(value);
throw StateError('case');
}
}
void commented() {
print('before');
// Explain the failure.
throw StateError('failure');
}Configure newline-before-throw
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"newline-before-throw": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/newline-before-throw: <reason>More style rules
- no-default-cases
no_default_casesFlags
default:in switch statements over enums and enum-like classes. - no-leading-underscores-for-library-prefixes
no_leading_underscores_for_library_prefixesrecommendedFlags import prefixes that begin with an underscore.
- no-leading-underscores-for-local-identifiers
no_leading_underscores_for_local_identifiersrecommendedFlags local variables and parameters whose names begin with an underscore.
- no-literal-bool-comparisons
no_literal_bool_comparisonsFlags boolean literals compared or combined with a non-nullable
bool. - no-magic-number
no-magic-numberFlags unnamed numeric literals (magic numbers) used inline in expressions.
- no-object-declaration
no-object-declarationFlags class members declared with the type
Object(orObject?). - no-runtime-type-to-string
no_runtimeType_toStringAvoid calling
toString()onruntimeType. - non-constant-identifier-names
non_constant_identifier_namesrecommendedFlags non-constant identifiers that are not written in lowerCamelCase.