line-comment-position

强制行注释的位置

行注释可以位于代码上方或旁边。此规则有助于团队保持一致的风格。

// above comment
var foo = "bar";  // beside comment

规则详情

此规则强制行注释的位置一致。块评论不受此规则的影响。默认情况下,此规则忽略以以下单词开头的注释:eslintjshintjslintistanbulglobalexportedjscsfalls through

选项

此规则接受一个参数,可以是字符串或对象。字符串设置与 position 属性的设置相同(解释如下)。object 选项具有以下属性:

position

position 选项有两个设置:

    4vpWmV7idSj/wUN/xHRP+zKm7aNjehTYUzR1/ysIHenI4E67hzRqmOeZOWtdZp5nTFUhGEs1Q2BF4yxz13ZjTWxc8tSZTRUxIGQEFCIw3ZawUiq9o8aNkXyHzM3chnTRFaCCt/6EVNgsKWArexDBOXu5wQZtTbcnxSlq8tYH6OJTUQ2FBOHaNBkk2+bXMp1HgCXS4UXA5leXj6VGsQ/spcZMFtQ/L4jB4kNnlqvZANQ=

position: above

doDYTffqv/gZP7wSal4DlzEgcHUjEyNr26oFx91mncNAmC/OQ9OEZC/+YXI7gL5NuVKhIu1J0SDHZTqVfgE/ehk+vZbeb/ogtt702suOXW0=

/*eslint line-comment-position: ["error", { "position": "above" }]*/
// valid comment
1 + 1;

doDYTffqv/gZP7wSal4DlzEgcHUjEyNr26oFx91mncMWSxsY0FgrRFJ0ewARu5/eyQ5LemvNKCciIz7hhka0dgIgGi7zDUs4iKcHzo2tAUg=

/*eslint line-comment-position: ["error", { "position": "above" }]*/
1 + 1; // invalid comment

position: beside

doDYTffqv/gZP7wSal4DlzCbZi0CXdqLH+NCLjcBPa5jMaykaSzQHwoD6XYc+wRSGGHb+bgRPLuncF/YkXTKCD5ETioVO8nRDCUkKwEap2Y=

/*eslint line-comment-position: ["error", { "position": "beside" }]*/
1 + 1; // valid comment

doDYTffqv/gZP7wSal4DlzCbZi0CXdqLH+NCLjcBPa5ZD8YTh/lyoOC3ws292g+KbkvZYz70tcNSW3gX2SkOvcvrSD+a2VpJjNTBYx0Xopk=

/*eslint line-comment-position: ["error", { "position": "beside" }]*/
// invalid comment
1 + 1;

ignorePattern

4MJGsCSBV7Wimr5FSX87fFlUhSoCWko8f+IsjCIbFKbAJXqVtV7qgjAv24hmLSzxqC2JNyVQMqH0ONMI0TxzC2BR8njkwnbYXWHRb9i5nAyYG2lhKAaZuMJtnLMCuChaCincqK/BWtWAaBYaTdLzVjS3Dp8RJdIGevT8jUaXzvqgAtq1+Ft7gVX7Sfpltr3bcXxLEbRmBfO4Q2d/+3cGrwjEozfK+N+qE5bJSW31hDTE6TGsUWlhn6qzUeH4RhLcIABcjhfGlRl88vmohZHKKvguqrLTtRfq7Od8PndLOJwU5t01c6htsc4GHfexBbW7vaUGfld89rlicFQklRqo1hU4U2I38XsHFltiuHxwrOzQfNhmn3noZHMM59DshTlYaKFtfeoPcFjWEj6FZcq27Q==

YtaSSaqIh80Uqzglhjvym9EoQXEJ0u3/J6anY5fKRjfG4Omlcv4+fza+evDK88oRShd/2nB6PpveFYQPzbxILg==

/*eslint line-comment-position: ["error", { "ignorePattern": "pragma" }]*/
1 + 1; // pragma valid comment

YtaSSaqIh80Uqzglhjvym9EoQXEJ0u3/J6anY5fKRjdvh3qFNJ+aRjfD4LQeOUMeUWDSNGuK/4uDzF5eXrSPfA==

/*eslint line-comment-position: ["error", { "ignorePattern": "pragma" }]*/
1 + 1; // invalid comment

applyDefaultIgnorePatterns

6t27VaRdTHZvEJneageswkGtSHwf2Bc8suewrxtdMZb/6p7NyovLxcX7D/UDgZkIvctTkLFaO+YmqTlwuL/5gWCtconDQwD932qjlekgyGiVC+wqkdihyKfcwgFCEO3QLsodYykFssiNHt0Qw0YkTW98KXmBUWslPq/4Z8VLza5G6UhowvQAESoqzmLGY2ZPmzgH1UOnG5OK21MWh+Lnow==

GHXEq0mM2I6ki4906lm9p3Qhy64PrE5pkt1WxZTNylA0bzDXodPsjA8bx2awXUj2xqqU71ObNtws+mPzOH3S6kVzTJ/7WthfGgjdISD/O9OBCq3wSz8r6ktDWVu47NkN

/*eslint line-comment-position: ["error", { "ignorePattern": "pragma", "applyDefaultIgnorePatterns": false }]*/
1 + 1; // pragma valid comment

GHXEq0mM2I6ki4906lm9p3Qhy64PrE5pkt1WxZTNylA0bzDXodPsjA8bx2awXUj2NOi69C/XssOyEBwwZSyti8P8EYyYpDFDtoJPyxJHA/5h5hMJ6i/cRYnibNG1t8zB

/*eslint line-comment-position: ["error", { "ignorePattern": "pragma", "applyDefaultIgnorePatterns": false }]*/
1 + 1; // falls through

V6oy6VcKjfDGV7C7tqfUSGxuVHm3EXQJALCEqBy0vr/KJrzVU+X2q8MMVGT1a1WZmEu9zDSQ3EGjtyXDWEcF3aQDB0obEn65eOX64mwBetzmNLIs337bHfsIGnS5NtnrVDG/d3RrDDEbkv7RIbs6+jSj3EH1CW22hwT97OxX2WISXBW1by6WD9BpR4B6jKvDNKmbvRNXZSZGPvcz4AfFgA==

何时不使用

6C0urmKX5N4cFGCPyxiuIz8TKtCnbZcNWdbaDCV1tIL8P/KIt70a6BHKCduRAzhAvQ6lBzrgHWUVBfT5B43PAGXqBdcNMsm0MBi+cUgbbhaod5i6+KvXusgcAmeDkIN+

兼容性

jZIXiaFuhNx5MUiQ8JyeE8sdkJDlpwVZHXch9f/fmcH5E5zRlqQ6odS37CI9gBckLkO6LGE1Z5lOvpyKtCI/dhSAB/acWS3WONDxTPOJDZ+SQgMl2IdyTOItM7flsIR4rPP0xTBZqQuLXqM/ui1JGA==