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