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