版本

space-after-keywords

强制关键字后空格的一致性。

一些代码风格指南会要求或禁止在某些关键字后添加空格。

if (condition) {
    doSomething();
} else {
    doSomethingElse();
}

if(condition) {
    doSomething();
}else{
    doSomethingElse();
}

规则详情

此规则将强制关键字 if, else, for, while, do, switch, try, catch, finallywith 后空格的一致性。

此规则接受一个参数。如果参数是 "always",则关键字后必须至少有一个空格。如果参数是 "never",则关键字后不应有空格。默认值是 "always"

此规则的 错误 代码示例

/*eslint space-after-keywords: "error"*/

if(a) {}

if (a) {} else{}

do{} while (a);
/*eslint space-after-keywords: ["error", "never"]*/

if (a) {}

此规则的 正确 代码示例

/*eslint space-after-keywords: "error"*/

if (a) {}

if (a) {} else {}
/*eslint space-after-keywords: ["error", "never"]*/

if(a) {}

版本

此规则在 ESLint v0.6.0 中引入,并在 v2.0.0-beta.3 中移除。

更改语言