require or disallow an empty line between class members (lines-between-class-members)

The --fix option on the command line can automatically fix some of the problems reported by this rule.

This rule improves readability by enforcing lines between class members. It will not check empty lines before the first member and after the last member, since that is already taken care of by padded-blocks.

Rule Details

Examples of incorrect code for this rule:

/* eslint lines-between-class-members: ["error", "always"]*/
class MyClass {
  foo() {
    //...
  }
  bar() {
    //...
  }
}

Examples of correct code for this rule:

/* eslint lines-between-class-members: ["error", "always"]*/
class MyClass {
  foo() {
    //...
  }

  bar() {
    //...
  }
}

Options

This rule has a string option and an object option.

String option:

Object option:

Examples of incorrect code for this rule with the string option:

/* eslint lines-between-class-members: ["error", "always"]*/
class Foo{
  bar(){}
  baz(){}
}

/* eslint lines-between-class-members: ["error", "never"]*/
class Foo{
  bar(){}

  baz(){}
}

Examples of correct code for this rule with the string option:

/* eslint lines-between-class-members: ["error", "always"]*/
class Foo{
  bar(){}

  baz(){}
}

/* eslint lines-between-class-members: ["error", "never"]*/
class Foo{
  bar(){}
  baz(){}
}

Examples of correct code for this rule with the object option:

/* eslint lines-between-class-members: ["error", "always", { exceptAfterSingleLine: true }]*/
class Foo{
  bar(){} // single line class member
  baz(){
    // multi line class member
  }

  qux(){}
}

When Not To Use It

If you don't want to enforce empty lines between class members, you can disable this rule.

Compatibility

Version

This rule was introduced in ESLint 4.9.0.

Resources