newline-before-constructor

Group
Style
Path
lint/style/newline-before-constructor
Default
Off, opt in
Origin
Falcon
Rule
275 of 512

Requires a blank line before constructors following another member.

Includes named, redirecting, and factory constructor declarations. The first member is exempt unless enum constants precede it; constructor invocations are not checked. Blank lines above attached comments count.

Invalid

example.dartdart
class Example {
  final int value;
  Example(this.value);
  Example.zero() : value = 0;

  Example.one() : value = 1;
}

class FactoryExample {
  FactoryExample();
  factory FactoryExample.create() => FactoryExample();
}

class Nested {
  void method() {
    final value = Example(1);
    print(value);
  }
  Nested();
}

enum Action {
  run;
  const Action();
}

class Documented {
  final int value;
  /// No blank line above this documentation.
  Documented(this.value);
}
Add a blank line before constructor declaration.
2 final int value;
3 Example(this.value);
Add a blank line before constructor declaration.
3 Example(this.value);
4 Example.zero() : value = 0;
Add a blank line before constructor declaration.
10 FactoryExample();
11 factory FactoryExample.create() => FactoryExample();
Add a blank line before constructor declaration.
18 }
19 Nested();
Add a blank line before constructor declaration.
23 run;
24 const Action();
Add a blank line before constructor declaration.
29 /// No blank line above this documentation.
30 Documented(this.value);

Valid

example.dartdart
class Example {
  Example();

  Example.named();

  factory Example.create() => Example();
}

class FirstConstructor {
  FirstConstructor() {
    final make = () { return Example(); };
    make();
  }
}

class Fields {
  final int value;

  const Fields(this.value);
}

class Documented {
  final int value;

  /// Creates a documented instance.
  Documented(this.value);
}

enum Action {
  run;

  /// Creates an action.
  const Action();
}

Configure newline-before-constructor

Set its severity in falcon.json. See the configuration guide.

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

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

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