spaced-line-comment

在行注释中强制在 // 之后保持一致的间距。

¥Enforces consistent spacing after // in line comments.

一些风格指南要求或不允许在行注释的初始 // 之后立即使用空格。// 之后的空格使阅读注释中的文本更容易。另一方面,注释掉代码更容易,无需在 // 之后放置空格。

¥Some style guides require or disallow a whitespace immediately after the initial // of a line comment. Whitespace after the // makes it easier to read text in comments. On the other hand, commenting out code is easier without having to put a whitespace right after the //.

规则详情

¥Rule Details

此规则将强制行注释 // 开始后的间距保持一致。

¥This rule will enforce consistency of spacing after the start of a line comment //.

这条规则有两个参数。如果第一个是 "always",那么 // 后面必须至少跟一个空格。如果 "never" 那么后面应该没有空格。默认值为 "always"

¥This rule takes two arguments. If the first is "always" then the // must be followed by at least once whitespace. If "never" then there should be no whitespace following. The default is "always".

第二个参数是一个带有一个键 "exceptions" 的对象。该值是一个字符串模式数组,被视为规则的例外。需要注意的是,如果第一个参数是 "never",则忽略异常。例外不能混用。

¥The second argument is an object with one key, "exceptions". The value is an array of string patterns which are considered exceptions to the rule. It is important to note that the exceptions are ignored if the first argument is "never". Exceptions cannot be mixed.

此规则的错误代码示例:

¥Examples of incorrect code for this rule:

// 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
//------++++++++

此规则的正确代码示例:

¥Examples of correct code for this rule:

// 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 中删除。