block-spacing
在打开块之后和关闭块之前禁止或强制在块内使用空格
此规则报告的一些问题可通过 --fix
命令行选项自动修复
此规则在 ESLint v8.53.0 中已弃用。请在 @stylistic/eslint-plugin-js
中使用 相应的规则。
¥This rule was deprecated in ESLint v8.53.0. Please use the corresponding rule in @stylistic/eslint-plugin-js
.
规则详情
¥Rule Details
此规则强制在打开的块标记内和同一行上的下一个标记内保持一致的间距。此规则还强制关闭块令牌和同一行上的前一个令牌内的间距一致。
¥This rule enforces consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line.
选项
¥Options
此规则有一个字符串选项:
¥This rule has a string option:
-
"always"
(默认)需要一个或多个空格¥
"always"
(default) requires one or more spaces -
"never"
不允许有空格¥
"never"
disallows spaces
always
使用默认 "always"
选项的此规则的错误代码示例:
¥Examples of incorrect code for this rule with the default "always"
option:
/*eslint block-spacing: "error"*/
function foo() {return true;}
if (foo) { bar = 0;}
function baz() {let i = 0;
return i;
}
class C {
static {this.bar = 0;}
}
使用默认 "always"
选项的此规则的正确代码示例:
¥Examples of correct code for this rule with the default "always"
option:
/*eslint block-spacing: "error"*/
function foo() { return true; }
if (foo) { bar = 0; }
class C {
static { this.bar = 0; }
}
never
使用 "never"
选项的此规则的错误代码示例:
¥Examples of incorrect code for this rule with the "never"
option:
/*eslint block-spacing: ["error", "never"]*/
function foo() { return true; }
if (foo) { bar = 0;}
class C {
static { this.bar = 0; }
}
使用 "never"
选项的此规则的正确代码示例:
¥Examples of correct code for this rule with the "never"
option:
/*eslint block-spacing: ["error", "never"]*/
function foo() {return true;}
if (foo) {bar = 0;}
class C {
static {this.bar = 0;}
}
何时不使用
¥When Not To Use It
如果你不想收到有关块内间距样式的通知,你可以安全地禁用此规则。
¥If you don’t want to be notified about spacing style inside of blocks, you can safely disable this rule.
相关规则
版本
此规则是在 ESLint v1.2.0 中引入。