版本

space-after-keywords

強制關鍵字後的一致空格。

某些樣式指南會要求或禁止在某些關鍵字後方加上空格。

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

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

規則詳細資訊

此規則將強制在關鍵字 ifelseforwhiledoswitchtrycatchfinallywith 後面加上一致的空格。

此規則接受一個參數。如果參數是 "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 中移除。

變更語言