Skip to content

Latest commit

 

History

History
75 lines (46 loc) · 1.34 KB

space-after-keywords.md

File metadata and controls

75 lines (46 loc) · 1.34 KB
规则名
space-after-keywords

Enforces consistent spacing after keywords.

(removed) This rule was removed in ESLint v2.0 and replaced by the keyword-spacing rule.

(fixable) The --fix option on the command line automatically fixed problems reported by this rule.

Some style guides will require or disallow spaces following the certain keywords.

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

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

规则详解

This rule will enforce consistency of spacing after the keywords if, else, for, while, do, switch, try, catch, finally, and with.

This rule takes one argument. If it is "always" then the keywords must be followed by at least one space. If "never" then there should be no spaces following. The default is "always".

此规则的 错误 代码实例:

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

if(a) {}

if (a) {} else{}

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

if (a) {}

此规则的 正确 代码实例:

::: correct

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

if (a) {}

if (a) {} else {}

::: correct

/*eslint space-after-keywords: ["error", "never"]*/

if(a) {}