newline-before-method
- Group
- Style
- Path
lint/style/newline-before-method- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 277 of 512
Requires a blank line before method declarations following another member.
The first member is exempt unless enum constants precede it. Checks methods in classes, mixins, enums, and extensions; top-level and local functions are not method declarations. Blank lines above attached comments count.
Invalid
class Example {
void first() {}
void second() {}
void spaced() {
void local() {}
local();
}
void nested() {
final callback = () { print('not a declaration'); };
callback();
}
}
mixin Actions {
int value = 0;
void run() {}
}
extension ActionsOnInt on int {
int get doubled => this * 2;
void run() {}
}
enum Action {
run;
void execute() {}
}
class Documented {
void first() {}
/// No blank line above this documentation.
void second() {}
} void first() {} void second() {} } void nested() { int value = 0; void run() {} int get doubled => this * 2; void run() {} run; void execute() {} /// No blank line above this documentation. void second() {}Valid
class Example {
void first() {}
void second() {}
@override
String toString() => 'Example';
}
mixin Actions {
void first() {}
void second() {}
}
extension ActionsOnInt on int {
void first() {}
void second() {}
}
void topLevel() {}
void anotherTopLevel() {}
class Documented {
void first() {}
/// Runs the second action.
/// The blank line belongs above these comments.
void second() {}
/* A block comment can also introduce a method. */
void third() {}
}
enum Action {
run;
/// Executes the action.
void execute() {}
}Configure newline-before-method
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"newline-before-method": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/newline-before-method: <reason>More style rules
- newline-before-return
newline-before-returnFlags
returnstatements that are not preceded by a blank line. - newline-before-throw
Requires a blank line before a throw that follows another statement.
- 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?).