lines-between-class-members

要求或禁止类成员之间有空行

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

此规则通过强制类成员之间的线来提高可读性。它不会检查第一个成员之前和最后一个成员之后的空行,因为它已经被填充块处理了。

规则详情

此规则的错误代码示例:

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

此规则的正确代码示例:

/* eslint lines-between-class-members: ["error", "always"]*/
class MyClass {
  x;

  foo() {
    //...
  }

  bar() {
    //...
  }
}

elAMLlFU+Y8IlZxILzWtotder9W9Gxp/o3qPkoSI3BopSAgGiVzCBtEChGd4QG87

/* eslint lines-between-class-members: ["error", "always"]*/
class MyClass {
  x = 1

  ;in = 2
}

选项

OFJv0xwnTt0N7ha7Ki3udUDBBFmPkRO07WYWuQbslr6DmopqUgjwZFlS6XuLapBTXGYF8eHfJdMnLiwAv5uQcQ==

cG9hjZka/FnLE7PrIih5nU8GN+i8rKO5oV5m/M2R71M=

    zU8A07vJo025i6xT9/Fe6SW75wF8fGJNfczgDHh0ooh+zCg5ZLqrBHn+2uvPvVcVbzotDgJgVft1mTH2XLE2ETgWvbbYjWcZ+gmZOnfT19eaEnlZOMl3L7hx0td3f9PBI5LAbfFDD2NY8Rt7ICvz4kdtiKb4O1eyqOv2oo0Vb/KqRG1B7h6+r5AnYDJAJAK94i85enNWbPSM0zxTjY1kig==

NIAHMwKittJaGoQe74sM1w==

    RY1VN83S1gbfhSluwR6WSFwtUB+raIoyisaZUSf22N7Qz/lKWR+Z2HUaH4v/foHsspMLax8/JO60/7rjA+YFsfUQ/F2Uf6pIRPW+jO5LV7IxaSoz4STvnBRtUukaEn9EDj+pbWApXoxixJt8TO4TrFKIivDpLAmPNx1hJIQLePEHWbymgOdYQraVpJkv83E2mR4cz8A64+G3R/EyU4Nq42/I9sZsoH2CIoNzVpgDD6rbgNJhgVhhZKuCQV+xU385/Yrl0UqSYqpS8RHKMDL87g==

sKgc7qFjN+o/iUbkVaNu8CBxm+WaToeIH9L3W2YEqz1/dZeZZWjuVdaGyBJlJCWEU4z3FQlVbaB5GpDPWKqP6Q==

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

/* eslint lines-between-class-members: ["error", "never"]*/
class Foo{
  x;

  bar(){}

  baz(){}
}

sKgc7qFjN+o/iUbkVaNu8CBxm+WaToeIH9L3W2YEqz2xUZvkuJHoMTERj5SJLZk/8QaTzgYG8JZIARbYpGLWag==

/* eslint lines-between-class-members: ["error", "always"]*/
class Foo{
  x;

  bar(){}

  baz(){}
}

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

WgtWTVHtzFI8XFG5xuFUgymUJ7OKZem+VGPFvz149ylf4IHilHVy7E0Tm/g+VGy+V+dx6DveRrRI4nvQ8wVQ5Q==

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

  qux(){}
}

何时不使用

wvBsBKrLnai3JsVzULurqw+v7px48tJf9wwqmD7v+0ukmXFbCBzElR2SmAOQ5DGUIMTTofs+fNJDbPYpTykZqjdOQcZVuRvlKOP6YzPzChufjZab8kavTenhnE25SE2I

兼容性

    ohMFBr5Rdm5vJMzN9aq0C76WVLBJ7FCWB2qQTRHQ2HDglk4pm2VWWEermO6SHOfPyV33FXgYpykiFtrE8stz8UOv2q+WFmz9NKqF2nrCBUraDd2RdjFsgH+yMxcLXQZPyR4l7NbFgP9xsgr/twlKs/Q7ZSe74c4prgC+CZZwO5tQrJHFhtQ+cN+Oy6xjLG3LxCWT+cPYOeMyhF6ciG5XnhsY/b+3hnjv9U7D/iWw8yXQNuIeP9Ztxf1ih1OsQ126