spaced-line-comment
強制行註解 //
後面的一致空格。
某些風格指南要求或不允許在行註解的初始 //
之後立即加上空白。在 //
之後加上空白可以讓註解中的文字更容易閱讀。另一方面,在 //
之後不需加上空白即可更輕鬆地註解掉程式碼。
規則詳情
此規則將強制行註解 //
開始後的空格一致性。
此規則接受兩個參數。如果第一個是 "always"
,則 //
後面必須至少跟一個空白。如果為 "never"
,則後面不應有空白。預設值為 "always"
。
第二個參數是一個物件,其中一個鍵為 "exceptions"
。值是一個字串模式陣列,這些模式被視為規則的例外。請務必注意,如果第一個參數是 "never"
,則會忽略例外。例外情況不能混合使用。
此規則的不正確程式碼範例
// When ["never"]
// This is a comment with a whitespace at the beginning
//When ["always"]
//This is a comment with no whitespace at the beginning
var foo = 5;
// When ["always",{"exceptions":["-","+"]}]
//------++++++++
// Comment block
//------++++++++
此規則的正確程式碼範例
// When ["always"]
// This is a comment with a whitespace at the beginning
var foo = 5;
//When ["never"]
//This is a comment with no whitespace at the beginning
var foo = 5;
// When ["always",{"exceptions":["-"]}]
//--------------
// Comment block
//--------------
// When ["always",{"exceptions":["-+"]}]
//-+-+-+-+-+-+-+
// Comment block
//-+-+-+-+-+-+-+
相關規則
版本
此規則在 ESLint v0.9.0 中引入,並在 v1.0.0-rc-1 中移除。