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

example.dartdart
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() {}
}
Add a blank line before method declaration.
2 void first() {}
3 void second() {}
Add a blank line before method declaration.
8 }
9 void nested() {
Add a blank line before method declaration.
16 int value = 0;
17 void run() {}
Add a blank line before method declaration.
21 int get doubled => this * 2;
22 void run() {}
Add a blank line before method declaration.
26 run;
27 void execute() {}
Add a blank line before method declaration.
32 /// No blank line above this documentation.
33 void second() {}

Valid

example.dartdart
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.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "newline-before-method": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/newline-before-method: <reason>