Skip to main content

lines-between-class-members

Require or disallow an empty line between class members.

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. This rule will require or disallow an empty line between class members.

Attributes

  • Included in configs
    • ✅ Recommended
    • 🔒 Strict
  • Fixable
    • 🔧 Automated Fixer
    • 💡 Suggestion Fixer
  • 💭 Requires type information

Rule Details

This rule extends the base eslint/lines-between-class-members rule. It adds support for ignoring overload methods in a class.

How to Use

.eslintrc.cjs
module.exports = {
// Note: you must disable the base rule as it can report incorrect errors
"lines-between-class-members": "off",
"@typescript-eslint/lines-between-class-members": "warn"
};

Options

See eslint/lines-between-class-members options.

In addition to the options supported by the lines-between-class-members rule in ESLint core, the rule adds the following options:

  • Object option:

    • "exceptAfterOverload": true (default) - Skip checking empty lines after overload class members
    • "exceptAfterOverload": false - do not skip checking empty lines after overload class members
  • See the other options allowed

exceptAfterOverload: true

Examples of correct code for the { "exceptAfterOverload": true } option:

/*eslint @typescript-eslint/lines-between-class-members: ["error", "always", { "exceptAfterOverload": true }]*/

class foo {
bar(a: string): void;
bar(a: string, b: string): void;
bar(a: string, b: string) {}

baz() {}

qux() {}
}

exceptAfterOverload: false

Examples of correct code for the { "exceptAfterOverload": false } option:

/*eslint @typescript-eslint/lines-between-class-members: ["error", "always", { "exceptAfterOverload": false }]*/

class foo {
bar(a: string): void;

bar(a: string, b: string): void;

bar(a: string, b: string) {}

baz() {}

qux() {}
}

Taken with ❤️ from ESLint core

Resources