Skip to main content

lines-between-class-members

danger
This rule will soon be moved to eslint-stylistic. See What About Formatting? for more information.

Require or disallow an empty line between class members.

🔧

此规则报告的一些问题可通过 --fix ESLint 命令行选项自动修复


此规则扩展了基本 eslint/lines-between-class-members 规则。 它添加了对忽略类中重载方法的支持。

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

选项

除了 ESLint 核心中 lines-between-class-members 规则支持的选项外,该规则还添加了以下选项:

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

  • 对象选项:

    • "exceptAfterOverload": true(默认)- 跳过检查重载类成员后的空行
    • "exceptAfterOverload": false - 不要 在重载类成员之后跳过检查空行
  • 查看允许的其他选项

exceptAfterOverload: true

{ "exceptAfterOverload": true } 选项的 correct 代码示例:

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

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

baz() {}

qux() {}
}
Open in Playground

exceptAfterOverload: false

{ "exceptAfterOverload": false } 选项的 correct 代码示例:

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

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

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

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

baz() {}

qux() {}
}
Open in Playground

如何使用

.eslintrc.cjs
module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"lines-between-class-members": "off",
"@typescript-eslint/lines-between-class-members": "error"
}
};
在线运行试试这个规则 ↗

选项

参见 eslint/lines-between-class-members 选项

资源

摘自 ❤️ ESLint 内核