版本

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 中移除。

變更語言