block-spacing
在打开块之后和关闭块之前禁止或强制在块内使用空格
此规则报告的一些问题可通过 --fix 命令行 选项自动修复
This rule was deprecated in ESLint v8.53.0. It will be removed in v11.0.0. Please use the corresponding rule in @stylistic/eslint-plugin.
规则详情
🌐 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"(默认)需要一个或多个空格"never"不允许有空格
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 中引入。