no-inline-comments

禁止代码后的内联注释

一些样式指南不允许注释与代码在同一行。如果注释紧跟在同一行的代码后面,代码可能会变得难以阅读。另一方面,有时将注释紧跟在代码后面会更快、更明显。

规则详情

此规则不允许注释与代码位于同一行。

此规则的错误代码示例:

/*eslint no-inline-comments: "error"*/

var a = 1; // declaring a to 1

function getRandomNumber(){
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

/* A block comment before code */ var b = 2;

var c = 3; /* A block comment after code */

此规则的正确代码示例:

/*eslint no-inline-comments: "error"*/

// This is a comment above a line of code
var foo = 5;

var bar = 5;
//This is a comment below a line of code

JSX 异常

VRGVPZOa4SQK0fouFE8UofNYL2db3h2ASs5uu1cuqG4vEfTcmTWCcXH0c+76eksZYvBc5+nfbixQtDR0VxqonzemGixQi9noCGYvbcxP278mrJ0cDSyvPDYptpmeUlX9+coLP52oFtBoidNQsTF0akvPieLmqaEYDqHTqlTmYAWdEFw4TNxYQtff858uLcy6281L2rTxLqAzEin+TU7zLQ==

r6hi7htUov+vPER817DMpSRTvHu5NMFNJX5PKtsQSh4quBRUaItxaVoNlZcysCNG

/*eslint no-inline-comments: "error"*/

var foo = <div>{ /* On the same line with other code */ }<h1>Some heading</h1></div>;

var bar = (
    <div>
    {   // These braces are not just for the comment, so it can't be on the same line
        baz
    }
    </div>
);

6RXgRVcYea97/4k5PNW/nItJttC+MHc4vVjxm8VW+ghbeqd3KsyvO/XAfiqXOEJI

/*eslint no-inline-comments: "error"*/

var foo = (
    <div>
      {/* These braces are just for this comment and there is nothing else on this line */}
      <h1>Some heading</h1>
    </div>
)

var bar = (
    <div>
    {
        // There is nothing else on this line
        baz
    }
    </div>
);

var quux = (
    <div>
      {/*
        Multiline
        comment
      */}
      <h1>Some heading</h1>
    </div>
)

选项

ignorePattern

rK24Fet9oVJGgxdM1gFvcneYPXiAn+8foOyFNCFUM0olSPhux8ixoYlFDIkOxVZdbVwlW10bNGFmVcwaC00piDwmdCVnJwEDem+MV3//NX1ANVgo3/9kkbcvLoS66ysyJnqYi8KGaM1cZ1EK0lI//hsLyKwWRx00MNsVq4dZBDoUppOP/o3svtyYP+NUA/e+OdyDEG4NeVkSifqR6QILOMBwaKX8d0fAggOIoI18mWmE40et9DCwLrbH2brBZ9BbE8p61+g1HbA1jp2wpJ9g8w==

oPUfyzwcCVHhoBwbpRMph+pwSTEIj4PRx2+q7eoCtqUB+EZ9voU01zF22f3SrHJrW3lgOBG1aMmwoReaVILQAQ==

/*eslint no-inline-comments: ["error", { "ignorePattern": "webpackChunkName:\\s.+" }]*/

import(/* webpackChunkName: "my-chunk-name" */ './locale/en');

oPUfyzwcCVHhoBwbpRMph+pwSTEIj4PRx2+q7eoCtqVwy2JJ2R8uOSiZW6D8BL72qNbxfe994+crC1nG2fEJxw==

/*eslint no-inline-comments: ["error", { "ignorePattern": "something" }] */

var foo = 4; // other thing