diff --git a/docs/rules/capitalized-comments.md b/docs/rules/capitalized-comments.md index ec3253b31718..341d1790805a 100644 --- a/docs/rules/capitalized-comments.md +++ b/docs/rules/capitalized-comments.md @@ -52,7 +52,7 @@ This rule has two options: a string value `"always"` or `"never"` which determin Here are the supported object options: * `ignorePattern`: A string representing a regular expression pattern of words that should be ignored by this rule. If the first word of a comment matches the pattern, this rule will not report that comment. - * Note that the following words are always ignored by this rule: `["jscs", "jshint", "eslint", "istanbul", "global", "globals", "exported"]`. + * Note that the following words are always ignored by this rule: `["jscs", "jshint", "eslint", "istanbul", "global", "globals", "exported"]` and all [Webpack magic comments](https://webpack.js.org/api/module-methods/#magic-comments). * `ignoreInlineComments`: If this is `true`, the rule will not report on comments in the middle of code. By default, this is `false`. * `ignoreConsecutiveComments`: If this is `true`, the rule will not report on a comment which violates the rule, as long as the comment immediately follows another comment. By default, this is `false`. diff --git a/docs/rules/line-comment-position.md b/docs/rules/line-comment-position.md index 734453411c94..9715f378f391 100644 --- a/docs/rules/line-comment-position.md +++ b/docs/rules/line-comment-position.md @@ -9,7 +9,7 @@ var foo = "bar"; // beside comment ## Rule Details -This rule enforces consistent position of line comments. Block comments are not affected by this rule. By default, this rule ignores comments starting with the following words: `eslint`, `jshint`, `jslint`, `istanbul`, `global`, `exported`, `jscs`, `falls through`. +This rule enforces consistent position of line comments. Block comments are not affected by this rule. By default, this rule ignores comments starting with the following words: `eslint`, `jshint`, `jslint`, `istanbul`, `global`, `exported`, `jscs`, `falls through` and all [Webpack magic comments](https://webpack.js.org/api/module-methods/#magic-comments). ## Options @@ -61,7 +61,8 @@ Examples of **incorrect** code for the `{ "position": "beside" }` option: ### ignorePattern -By default this rule ignores comments starting with the following words: `eslint`, `jshint`, `jslint`, `istanbul`, `global`, `exported`, `jscs`, `falls through`. An alternative regular expression can be provided. +By default this rule ignores comments starting with the following words: `eslint`, `jshint`, `jslint`, `istanbul`, `global`, `exported`, `jscs`, `falls through` +and all [Webpack magic comments](https://webpack.js.org/api/module-methods/#magic-comments). An alternative regular expression can be provided. Examples of **correct** code for the `ignorePattern` option: diff --git a/docs/rules/lines-around-comment.md b/docs/rules/lines-around-comment.md index 61af59698130..32a818713b76 100644 --- a/docs/rules/lines-around-comment.md +++ b/docs/rules/lines-around-comment.md @@ -437,7 +437,7 @@ const [ ### ignorePattern -By default this rule ignores comments starting with the following words: `eslint`, `jshint`, `jslint`, `istanbul`, `global`, `exported`, `jscs`. An alternative regular expression can be provided. +By default this rule ignores comments starting with the following words: `eslint`, `jshint`, `jslint`, `istanbul`, `global`, `exported`, `jscs` and all [Webpack magic comments](https://webpack.js.org/api/module-methods/#magic-comments). An alternative regular expression can be provided. Examples of **correct** code for the `ignorePattern` option: diff --git a/docs/rules/no-inline-comments.md b/docs/rules/no-inline-comments.md index cde77e9e4991..b7dc058a1f6f 100644 --- a/docs/rules/no-inline-comments.md +++ b/docs/rules/no-inline-comments.md @@ -3,6 +3,8 @@ Some style guides disallow comments on the same line as code. Code can become difficult to read if comments immediately follow the code on the same line. On the other hand, it is sometimes faster and more obvious to put comments immediately following code. +By default this rule ignores comments starting with the following words: `eslint`, `jshint`, `jslint`, `istanbul`, `global`, `exported`, `jscs`, and all [Webpack magic comments](https://webpack.js.org/api/module-methods/#magic-comments). + ## Rule Details This rule disallows comments on the same line as code. diff --git a/lib/rules/no-inline-comments.js b/lib/rules/no-inline-comments.js index 41b0f1e664c7..e2368e74daea 100644 --- a/lib/rules/no-inline-comments.js +++ b/lib/rules/no-inline-comments.js @@ -80,9 +80,9 @@ module.exports = { return { Program() { - const comments = sourceCode.getAllComments(); - - comments.filter(token => token.type !== "Shebang").forEach(testCodeAroundComment); + return sourceCode.getAllComments() + .filter(comment => !astUtils.COMMENTS_IGNORE_PATTERN.test(comment.value)) + .filter(token => token.type !== "Shebang").forEach(testCodeAroundComment); } }; } diff --git a/lib/rules/utils/ast-utils.js b/lib/rules/utils/ast-utils.js index 82156a34ec9f..978103b92e78 100644 --- a/lib/rules/utils/ast-utils.js +++ b/lib/rules/utils/ast-utils.js @@ -31,7 +31,7 @@ const bindOrCallOrApplyPattern = /^(?:bind|call|apply)$/u; const thisTagPattern = /^[\s*]*@this/mu; -const COMMENTS_IGNORE_PATTERN = /^\s*(?:eslint|jshint\s+|jslint\s+|istanbul\s+|globals?\s+|exported\s+|jscs)/u; +const COMMENTS_IGNORE_PATTERN = /^\s*(?:eslint|jshint\s+|jslint\s+|istanbul\s+|globals?\s+|exported\s+|jscs|webpackInclude:|webpackExclude:|webpackChunkName:|webpackMode:|webpackPrefetch:|webpackPreload:)/u; const LINEBREAKS = new Set(["\r\n", "\r", "\n", "\u2028", "\u2029"]); // A set of node types that can contain a list of statements diff --git a/tests/lib/rules/capitalized-comments.js b/tests/lib/rules/capitalized-comments.js index 043226055b4f..6d79c85173a7 100644 --- a/tests/lib/rules/capitalized-comments.js +++ b/tests/lib/rules/capitalized-comments.js @@ -71,6 +71,12 @@ ruleTester.run("capitalized-comments", rule, { "/* globals var1, var2 */", "/* globals var1:true, var2 */", "/* exported myVar */", + "/* webpackInclude: /\\.json$/ */", + "/* webpackExclude: /\\.noimport\\.json$/ */", + "/* webpackChunkName: \"my-chunk-name\" */", + "/* webpackMode: \"lazy\" */", + "/* webpackPrefetch: true */", + "/* webpackPreload: true */", // Ignores shebangs "#!foo", diff --git a/tests/lib/rules/no-inline-comments.js b/tests/lib/rules/no-inline-comments.js index ecb475997f7c..1a2b05f8d696 100644 --- a/tests/lib/rules/no-inline-comments.js +++ b/tests/lib/rules/no-inline-comments.js @@ -88,7 +88,13 @@ ruleTester.run("no-inline-comments", rule, { comment */} - )` + )`, + + // Webpack + { + code: "import(/* webpackChunkName: \"my-chunk-name\" */'./locale/language');", + parserOptions: { ecmaVersion: 2020 } + } ], invalid: [