Index

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