space-before-blocks

在块之前强制保持一致的间距

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

一致性是任何风格指南的重要组成部分。虽然将块的左大括号放在哪里是个人喜好,但它应该在整个项目中保持一致。风格不一致会分散读者看到代码重要部分的注意力。

规则详情

此规则将强制块前间距的一致性。它仅适用于不在新行开始的块。

  • 此规则忽略 => 和块之间的间距。间距由 arrow-spacing 规则处理。
  • 此规则忽略关键字和块之间的间距。间距由 keyword-spacing 规则处理。
  • 此规则忽略开关盒的 : 和块之间的间距。间距由 switch-colon-spacing 规则处理。

选项

hFE7Sojla52syLPf0o+KJ+mQMbZnBR/amItRf/JFFwjdIMJa6mflZ4WVlFoxVK7rduPi130F4wxT6L+UFJ6XQpJjTTq4RaUH/XxBLub/zrbR46KO8KiQZZj2X8ubERbNjx5s8jK1Jnc/XsGo/qRsd4GLaLRWifuBrlXLXxXi8uyfdTByZ1doS9xGCFC/lMB2luFY3pLkOaEuFNFMiTA0bqhtGBTOwFsG84qH0C6npQQq/bWwtLqRezYV+AorR0VB5wBgNk5haG9PBxMdpisMnOHYW52MYnxWSj004790PFlTBtXOHYoPkMgGEVEEyBSCh5QmkgQIvOXSxDJ8SJSV+J7JXV7cRS4pRuKlluumqDXOLuOfchgWAVRrRRCBMQIdce1C3eRD1TE6+L9HlE46Sdtv3craB4kjQKZnJWSN8vUYj3oxU85EtcSHMAdFJr0klspasiN0v9GG6vBguWurEzKo40rHV/ndd1j9QGhfHVjXXsOYpC/SwK+RbBXGCkSL2YjziBojrL4jAz5p+QXllMIcWo3LaodwWkypD4H4sBL+FMwyP1ob55mkxyiWSyh81giI3ArJp41ngtgUMn1ciT3vwJCi94Tz28MEwvucvRs=

eyt+JsJfA6hBdSCzSDSuU3xDdd1NGCUNry4QcVkROmSG//BJe8We2EobrJZA1Du4W8CUgdO+o5Ls2uwL3bYSAxoCZ6yQvG95HeeI4snIyfT3056Dd6/OEvdYi3d9w5Dz

wjIxzHBd+zCPFQpl1eqYOxJFJnYUEolCF/Do2DF5aviQnVz1TQtzsNAhFWtTSn2F

"always"

cHf/0vFMNJSQMO1JxuxkQBSqhrgwxoGrL9EOlDT2sfna2ItCmzGgniIauTet4ACgyepXfsAv69Jnq5UyImOotA==

/*eslint space-before-blocks: "error"*/

if (a){
    b();
}

function a(){}

for (;;){
    b();
}

try {} catch(a){}

class Foo{
  constructor(){}
}

cHf/0vFMNJSQMO1JxuxkQA9Dym10qcconkeF0QQGEvTltVEL1N907nMZOm7X5Fyk+anzhfdsAwY0YmPKcyX7FzFNrJxVS2r8n3vG2HLWjww=

/*eslint space-before-blocks: "error"*/

if (a) {
    b();
}

if (a) {
    b();
} else{ /*no error. this is checked by `keyword-spacing` rule.*/
    c();
}

class C {
    static{} /*no error. this is checked by `keyword-spacing` rule.*/
}

function a() {}

for (;;) {
    b();
}

try {} catch(a) {}

"never"

cHf/0vFMNJSQMO1JxuxkQGLWYNnrcIwAItSZv5wfIODh2r9cmbK35Awqz9FmTcLYb/eerR3vE56VY6dM/ne8DtJhlVmDzh7T7rOXZEu5ecE=

/*eslint space-before-blocks: ["error", "never"]*/

if (a) {
    b();
}

function a() {}

for (;;) {
    b();
}

try {} catch(a) {}

cHf/0vFMNJSQMO1JxuxkQGLWYNnrcIwAItSZv5wfIODhI+dsTIuxuv33xeY2QEPi+mCtJqbo/xI28GjjwbDxEbfey+sFq92Z8lBMYA8Of5Y=

/*eslint space-before-blocks: ["error", "never"]*/

if (a){
    b();
}

function a(){}

for (;;){
    b();
}

try{} catch(a){}

class Foo{
  constructor(){}
}

QZPKOkPqFGCO9wfRjSFJCVKLO/FbETrOTpMSz95r4kAAZiLXusZNKSdylP1EpQAvye46jJZRQg9BLRBNxJC+CkZ5KyCWKpDuHahHeZozvR8+Hqgq9QDcOFuiq2z/VwV5pxN99MK2no27XjoV3ZgUUZqA4GRptgkmw/czOKm05uo=

/*eslint space-before-blocks: ["error", { "functions": "never", "keywords": "always", "classes": "never" }]*/
/*eslint-env es6*/

function a() {}

try {} catch(a){}

class Foo{
  constructor() {}
}

QZPKOkPqFGCO9wfRjSFJCVKLO/FbETrOTpMSz95r4kAAZiLXusZNKSdylP1EpQAvye46jJZRQg9BLRBNxJC+CkZ5KyCWKpDuHahHeZozvR8+Hqgq9QDcOFuiq2z/VwV5OBCRvD1izHpl8eiR79L/NhgdrY96TcEYoOVb2mBJeT0=

/*eslint space-before-blocks: ["error", { "functions": "never", "keywords": "always", "classes": "never" }]*/
/*eslint-env es6*/

for (;;) {
  // ...
}

describe(function(){
  // ...
});

class Foo{
  constructor(){}
}

QZPKOkPqFGCO9wfRjSFJCeBZJRhrq9vvgIer2IfkELDJvecsQXEbWburW0eeJVu/RdGRq+Ju1kK6bO4xfe0w+Aab5V3w0Ks5c6NnA3wYQrZQ7MH0GdAZcG4L9E08uDc6lkPRg2/8zbdJ/FP2KwDZc/pdeTNOhn51d4esm1z6/a0=

/*eslint space-before-blocks: ["error", { "functions": "always", "keywords": "never", "classes": "never" }]*/
/*eslint-env es6*/

function a(){}

try {} catch(a) {}

class Foo {
  constructor(){}
}

QZPKOkPqFGCO9wfRjSFJCeBZJRhrq9vvgIer2IfkELDJvecsQXEbWburW0eeJVu/RdGRq+Ju1kK6bO4xfe0w+Aab5V3w0Ks5c6NnA3wYQrZQ7MH0GdAZcG4L9E08uDc6KpbSjE+CY4uah1p7Yc4JozvcjuG2bN1xwpmtyoalmeM=

/*eslint space-before-blocks: ["error", { "functions": "always", "keywords": "never", "classes": "never" }]*/
/*eslint-env es6*/

if (a){
  b();
}

var a = function() {}

class Foo{
  constructor() {}
}

QZPKOkPqFGCO9wfRjSFJCVKLO/FbETrOTpMSz95r4kAAZiLXusZNKSdylP1EpQAvAYQGcK4t3lZ4RU2hQFYf7mXxfZVxwQagxn9hD9GU/IHVrIilKbYOOIoZPUsBB+aUQD7ep7tfI39M8VagqFKiV47ekIgLPzupb2EifIetdUY=

/*eslint space-before-blocks: ["error", { "functions": "never", "keywords": "never", "classes": "always" }]*/
/*eslint-env es6*/

class Foo{
  constructor(){}
}

QZPKOkPqFGCO9wfRjSFJCVKLO/FbETrOTpMSz95r4kAAZiLXusZNKSdylP1EpQAvAYQGcK4t3lZ4RU2hQFYf7mXxfZVxwQagxn9hD9GU/IHVrIilKbYOOIoZPUsBB+aUEJipnwz/8aonGSbMDXNvrVOM/oBU7BinB6EbSU0ypkc=

/*eslint space-before-blocks: ["error", { "functions": "never", "keywords": "never", "classes": "always" }]*/
/*eslint-env es6*/

class Foo {
  constructor(){}
}

何时不使用

zXXq1lVIqQfAG97FXseTuaCqbG7VktoUvFBw7FQ0bULEzHXD+FRUQI/jQH3BZ6pLL52bK0S2RMUwCivRXyyVoRJfj1ifl8n9JVwiMQ/KARc=