From 068821248e2d2eff11152f270102d537d8fa8126 Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Tue, 5 Jan 2021 19:11:45 -0500 Subject: [PATCH 01/28] Sponsors: Sync README with website --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 42702c12ff10..f80edf7191fa 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,7 @@ The following companies, organizations, and individuals support ESLint's ongoing

Automattic

Gold Sponsors

Chrome's Web Framework & Tools Performance Fund Shopify Salesforce Airbnb Microsoft FOSS Fund Sponsorships

Silver Sponsors

Liftoff AMP Project

Bronze Sponsors

-

The Standard Daily Writers Per Hour Buy.Fineproxy.Org Veikkaajat.com Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

+

The Standard Daily Writers Per Hour 2021 calendar Buy.Fineproxy.Org Veikkaajat.com Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

## Technology Sponsors From f6948f6bdc763dca0787bb2786bc9f6f9ed88f43 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Wed, 6 Jan 2021 11:28:14 -0800 Subject: [PATCH 02/28] Docs: Update semantic versioning policy (#13970) * Docs: Update semantic versioning policy Explicitly mention how we handle new language features for rules. * Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f80edf7191fa..015639b51c85 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,7 @@ ESLint follows [semantic versioning](https://semver.org). However, due to the na * A bug fix in a rule that results in ESLint reporting more linting errors. * A new rule is created. * A new option to an existing rule that does not result in ESLint reporting more linting errors by default. + * A new addition to an existing rule to support a newly-added language feature (within the last 12 months) that will result in ESLint reporting more linting errors by default. * An existing rule is deprecated. * A new CLI capability is created. * New capabilities to the public API are added (new classes, new methods, new arguments to existing methods, etc.). From 78cb48345c725e9f90fd0e631c476802244df4a4 Mon Sep 17 00:00:00 2001 From: Chris Brody Date: Wed, 6 Jan 2021 16:22:01 -0500 Subject: [PATCH 03/28] Chore: test `foo( )` with space-in-parens option "always" (#13986) --- tests/lib/rules/space-in-parens.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/rules/space-in-parens.js b/tests/lib/rules/space-in-parens.js index a68c6bae7df2..e304fb788586 100644 --- a/tests/lib/rules/space-in-parens.js +++ b/tests/lib/rules/space-in-parens.js @@ -22,6 +22,7 @@ ruleTester.run("space-in-parens", rule, { valid: [ { code: "foo()", options: ["never"] }, { code: "foo()", options: ["always"] }, + { code: "foo( )", options: ["always"] }, { code: "foo( bar )", options: ["always"] }, { code: "foo\n(\nbar\n)\n", options: ["always"] }, { code: "foo\n( \nbar\n )\n", options: ["always"] }, From e83a6962b51b05c2ddfe42b0748b405d515eeb9d Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Thu, 7 Jan 2021 06:11:42 -0500 Subject: [PATCH 04/28] Sponsors: Sync README with website --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 015639b51c85..312c9413517c 100644 --- a/README.md +++ b/README.md @@ -263,7 +263,7 @@ The following companies, organizations, and individuals support ESLint's ongoing

Automattic

Gold Sponsors

Chrome's Web Framework & Tools Performance Fund Shopify Salesforce Airbnb Microsoft FOSS Fund Sponsorships

Silver Sponsors

Liftoff AMP Project

Bronze Sponsors

-

The Standard Daily Writers Per Hour 2021 calendar Buy.Fineproxy.Org Veikkaajat.com Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

+

Forex In Thai The Standard Daily Writers Per Hour 2021 calendar Buy.Fineproxy.Org Veikkaajat.com Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

## Technology Sponsors From 98a729c9def54cee9e5478e75e8bd6f28167d5e8 Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Thu, 7 Jan 2021 17:11:49 -0500 Subject: [PATCH 05/28] Sponsors: Sync README with website --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 312c9413517c..f6766aa9bc73 100644 --- a/README.md +++ b/README.md @@ -263,7 +263,7 @@ The following companies, organizations, and individuals support ESLint's ongoing

Automattic

Gold Sponsors

Chrome's Web Framework & Tools Performance Fund Shopify Salesforce Airbnb Microsoft FOSS Fund Sponsorships

Silver Sponsors

Liftoff AMP Project

Bronze Sponsors

-

Forex In Thai The Standard Daily Writers Per Hour 2021 calendar Buy.Fineproxy.Org Veikkaajat.com Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

+

Forex In Thai The Standard Daily Writers Per Hour 2021 calendar Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

## Technology Sponsors From c5bf1f2150a9fbbb9e74c04808dc3bfeda1ed321 Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Fri, 8 Jan 2021 08:11:45 -0500 Subject: [PATCH 06/28] Sponsors: Sync README with website --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6766aa9bc73..f6edc22fac09 100644 --- a/README.md +++ b/README.md @@ -263,7 +263,7 @@ The following companies, organizations, and individuals support ESLint's ongoing

Automattic

Gold Sponsors

Chrome's Web Framework & Tools Performance Fund Shopify Salesforce Airbnb Microsoft FOSS Fund Sponsorships

Silver Sponsors

Liftoff AMP Project

Bronze Sponsors

-

Forex In Thai The Standard Daily Writers Per Hour 2021 calendar Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

+

VPNyhteys.org Forex In Thai The Standard Daily Writers Per Hour 2021 calendar Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

## Technology Sponsors From 3e491698687aa08b3b798cee0931f0872ca1bc55 Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Fri, 8 Jan 2021 14:11:50 -0500 Subject: [PATCH 07/28] Sponsors: Sync README with website --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6edc22fac09..d3043b8f2e23 100644 --- a/README.md +++ b/README.md @@ -263,7 +263,7 @@ The following companies, organizations, and individuals support ESLint's ongoing

Automattic

Gold Sponsors

Chrome's Web Framework & Tools Performance Fund Shopify Salesforce Airbnb Microsoft FOSS Fund Sponsorships

Silver Sponsors

Liftoff AMP Project

Bronze Sponsors

-

VPNyhteys.org Forex In Thai The Standard Daily Writers Per Hour 2021 calendar Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

+

The Standard Daily Writers Per Hour 2021 calendar Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

## Technology Sponsors From 4a38bbe81b4b29ca1a4e62d0a0cc8d525455b063 Mon Sep 17 00:00:00 2001 From: Chris Brody Date: Sun, 10 Jan 2021 00:04:54 -0500 Subject: [PATCH 08/28] Docs: space-in-parens examples with no arguments etc. (#13987) --- docs/rules/space-in-parens.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/rules/space-in-parens.md b/docs/rules/space-in-parens.md index bfc0b46ed32e..ca5119247266 100644 --- a/docs/rules/space-in-parens.md +++ b/docs/rules/space-in-parens.md @@ -36,10 +36,14 @@ Examples of **incorrect** code for this rule with the default `"never"` option: ```js /*eslint space-in-parens: ["error", "never"]*/ +foo( ); + foo( 'bar'); foo('bar' ); foo( 'bar' ); +foo( /* bar */ ); + var foo = ( 1 + 2 ) * 3; ( function () { return 'bar'; }() ); ``` @@ -53,6 +57,8 @@ foo(); foo('bar'); +foo(/* bar */); + var foo = (1 + 2) * 3; (function () { return 'bar'; }()); ``` @@ -68,6 +74,8 @@ foo( 'bar'); foo('bar' ); foo('bar'); +foo(/* bar */); + var foo = (1 + 2) * 3; (function () { return 'bar'; }()); ``` @@ -78,9 +86,12 @@ Examples of **correct** code for this rule with the `"always"` option: /*eslint space-in-parens: ["error", "always"]*/ foo(); +foo( ); foo( 'bar' ); +foo( /* bar */ ); + var foo = ( 1 + 2 ) * 3; ( function () { return 'bar'; }() ); ``` From f2687e71f9e2a2773f821c4dc1a02abe95b97df4 Mon Sep 17 00:00:00 2001 From: Chris Brody Date: Sun, 10 Jan 2021 00:06:20 -0500 Subject: [PATCH 09/28] Docs: update space-in-parens related rules (#13985) --- docs/rules/space-in-parens.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/rules/space-in-parens.md b/docs/rules/space-in-parens.md index ca5119247266..339703661310 100644 --- a/docs/rules/space-in-parens.md +++ b/docs/rules/space-in-parens.md @@ -287,4 +287,6 @@ You can turn this rule off if you are not concerned with the consistency of spac ## Related Rules -* [space-in-brackets](space-in-brackets.md) (deprecated) +* [array-bracket-spacing](array-bracket-spacing.md) +* [object-curly-spacing](object-curly-spacing.md) +* [computed-property-spacing](computed-property-spacing.md) From 75fea9bcdd3dde5a07e0089d9011a4df518cdbe3 Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Thu, 14 Jan 2021 13:11:57 -0500 Subject: [PATCH 10/28] Sponsors: Sync README with website --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3043b8f2e23..31a16dd77c4b 100644 --- a/README.md +++ b/README.md @@ -263,7 +263,7 @@ The following companies, organizations, and individuals support ESLint's ongoing

Automattic

Gold Sponsors

Chrome's Web Framework & Tools Performance Fund Shopify Salesforce Airbnb Microsoft FOSS Fund Sponsorships

Silver Sponsors

Liftoff AMP Project

Bronze Sponsors

-

The Standard Daily Writers Per Hour 2021 calendar Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

+

The Standard Daily Writers Per Hour February 2021 calendar Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

## Technology Sponsors From 9250d167ceb5684669eabe93dae326e33f0684f2 Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Fri, 15 Jan 2021 18:02:38 +0100 Subject: [PATCH 11/28] Upgrade: Bump lodash to fix security issue (#13993) This commit updates Lodash to remove a security vulnerability related to Prototype Pollution, see: https://snyk.io/vuln/SNYK-JS-LODASH-590103 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8bc78f66b2ba..efce29eeef0d 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "js-yaml": "^3.13.1", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", - "lodash": "^4.17.19", + "lodash": "^4.17.20", "minimatch": "^3.0.4", "natural-compare": "^1.4.0", "optionator": "^0.9.1", From de61f9444cf58a4d70e126ab3d10bf20851de7c9 Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Fri, 15 Jan 2021 12:11:57 -0500 Subject: [PATCH 12/28] Sponsors: Sync README with website --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 31a16dd77c4b..73a30990e509 100644 --- a/README.md +++ b/README.md @@ -263,7 +263,7 @@ The following companies, organizations, and individuals support ESLint's ongoing

Automattic

Gold Sponsors

Chrome's Web Framework & Tools Performance Fund Shopify Salesforce Airbnb Microsoft FOSS Fund Sponsorships

Silver Sponsors

Liftoff AMP Project

Bronze Sponsors

-

The Standard Daily Writers Per Hour February 2021 calendar Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

+

Streamat The Standard Daily Writers Per Hour February 2021 calendar Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

## Technology Sponsors From 292b1c0017bc442d399f67e01d699c59e6b71453 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Fri, 15 Jan 2021 18:33:06 +0100 Subject: [PATCH 13/28] Fix: no-extra-parens false positive with `let` identifier in for-loop (#13981) --- lib/rules/no-extra-parens.js | 16 +++ tests/lib/rules/no-extra-parens.js | 175 +++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) diff --git a/lib/rules/no-extra-parens.js b/lib/rules/no-extra-parens.js index 8d358d23ad3b..19c6fced79d4 100644 --- a/lib/rules/no-extra-parens.js +++ b/lib/rules/no-extra-parens.js @@ -895,6 +895,22 @@ module.exports = { } if (node.init) { + + if (node.init.type !== "VariableDeclaration") { + const firstToken = sourceCode.getFirstToken(node.init, astUtils.isNotOpeningParenToken); + + if ( + firstToken.value === "let" && + astUtils.isOpeningBracketToken( + sourceCode.getTokenAfter(firstToken, astUtils.isNotClosingParenToken) + ) + ) { + + // ForStatement#init expression cannot start with `let[`. + tokensToIgnore.add(firstToken); + } + } + startNewReportsBuffering(); if (hasExcessParens(node.init)) { diff --git a/tests/lib/rules/no-extra-parens.js b/tests/lib/rules/no-extra-parens.js index 3fee9fefd8f4..43c66c7562ad 100644 --- a/tests/lib/rules/no-extra-parens.js +++ b/tests/lib/rules/no-extra-parens.js @@ -599,6 +599,22 @@ ruleTester.run("no-extra-parens", rule, { options: ["functions"] }, "(let)[foo]", + + // ForStatement#init expression cannot start with `let[`. It would be parsed as a `let` declaration with array pattern, or a syntax error. + "for ((let[a]);;);", + "for ((let)[a];;);", + "for ((let[a] = 1);;);", + "for ((let[a]) = 1;;);", + "for ((let)[a] = 1;;);", + "for ((let[a, b] = foo);;);", + "for ((let[a].b = 1);;);", + "for ((let[a].b) = 1;;);", + "for ((let[a]).b = 1;;);", + "for ((let)[a].b = 1;;);", + "for ((let[a])();;);", + "for ((let)[a]();;);", + "for ((let[a]) + b;;);", + "for ((let) in foo);", "for ((let[foo]) in bar);", "for ((let)[foo] in bar);", @@ -1880,6 +1896,165 @@ ruleTester.run("no-extra-parens", rule, { "Identifier", 1 ), + + // ForStatement#init expression cannot start with `let[`, but it can start with `let` if it isn't followed by `[` + invalid( + "for ((let);;);", + "for (let;;);", + "Identifier", + 1 + ), + invalid( + "for ((let = 1);;);", + "for (let = 1;;);", + "AssignmentExpression", + 1 + ), + invalid( + "for ((let) = 1;;);", + "for (let = 1;;);", + "Identifier", + 1 + ), + invalid( + "for ((let = []);;);", + "for (let = [];;);", + "AssignmentExpression", + 1 + ), + invalid( + "for ((let) = [];;);", + "for (let = [];;);", + "Identifier", + 1 + ), + invalid( + "for ((let());;);", + "for (let();;);", + "CallExpression", + 1 + ), + invalid( + "for ((let([]));;);", + "for (let([]);;);", + "CallExpression", + 1 + ), + invalid( + "for ((let())[a];;);", + "for (let()[a];;);", + "CallExpression", + 1 + ), + invalid( + "for ((let`[]`);;);", + "for (let`[]`;;);", + "TaggedTemplateExpression", + 1 + ), + invalid( + "for ((let.a);;);", + "for (let.a;;);", + "MemberExpression", + 1 + ), + invalid( + "for ((let).a;;);", + "for (let.a;;);", + "Identifier", + 1 + ), + invalid( + "for ((let).a = 1;;);", + "for (let.a = 1;;);", + "Identifier", + 1 + ), + invalid( + "for ((let).a[b];;);", + "for (let.a[b];;);", + "Identifier", + 1 + ), + invalid( + "for ((let.a)[b];;);", + "for (let.a[b];;);", + "MemberExpression", + 1 + ), + invalid( + "for ((let.a[b]);;);", + "for (let.a[b];;);", + "MemberExpression", + 1 + ), + invalid( + "for ((let);[];);", + "for (let;[];);", + "Identifier", + 1 + ), + invalid( + "for (((let[a]));;);", + "for ((let[a]);;);", + "MemberExpression", + 1 + ), + invalid( + "for (((let))[a];;);", + "for ((let)[a];;);", + "Identifier", + 1 + ), + invalid( + "for (((let[a])).b;;);", + "for ((let[a]).b;;);", + "MemberExpression", + 1 + ), + invalid( + "for (((let))[a].b;;);", + "for ((let)[a].b;;);", + "Identifier", + 1 + ), + invalid( + "for (((let)[a]).b;;);", + "for ((let)[a].b;;);", + "MemberExpression", + 1 + ), + invalid( + "for (((let[a]) = b);;);", + "for ((let[a]) = b;;);", + "AssignmentExpression", + 1 + ), + invalid( + "for (((let)[a]) = b;;);", + "for ((let)[a] = b;;);", + "MemberExpression", + 1 + ), + invalid( + "for (((let)[a] = b);;);", + "for ((let)[a] = b;;);", + "AssignmentExpression", + 1 + ), + invalid( + "for ((Let[a]);;);", + "for (Let[a];;);", + "MemberExpression", + 1 + ), + invalid( + "for ((lett)[a];;);", + "for (lett[a];;);", + "Identifier", + 1 + ), + invalid( "for ((let.foo) in bar);", "for (let.foo in bar);", From 179a910b32e853bc12a9dd71f7c10e762cbeac44 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Fri, 15 Jan 2021 18:49:10 +0100 Subject: [PATCH 14/28] Fix: --init crash on question to upgrade/downgrade ESLint (fixes #13978) (#13995) --- lib/init/config-initializer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/init/config-initializer.js b/lib/init/config-initializer.js index f7d4cc7a171f..6f62e7db87e7 100644 --- a/lib/init/config-initializer.js +++ b/lib/init/config-initializer.js @@ -565,7 +565,8 @@ function promptUser() { { type: "toggle", name: "installESLint", - message(answers) { + message() { + const { answers } = this.state; const verb = semver.ltr(answers.localESLintVersion, answers.requiredESLintVersionRange) ? "upgrade" : "downgrade"; From 672deb057a14a7acad8c669189870009f1edb8a6 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Fri, 15 Jan 2021 19:01:51 +0100 Subject: [PATCH 15/28] Docs: fix no-invalid-regexp docs regarding ecmaVersion (#13991) --- docs/rules/no-invalid-regexp.md | 19 ++-- tests/lib/rules/no-invalid-regexp.js | 129 +++++++++++++++++++++++---- 2 files changed, 116 insertions(+), 32 deletions(-) diff --git a/docs/rules/no-invalid-regexp.md b/docs/rules/no-invalid-regexp.md index d656da025d0b..478cbee95659 100644 --- a/docs/rules/no-invalid-regexp.md +++ b/docs/rules/no-invalid-regexp.md @@ -30,16 +30,9 @@ new RegExp this.RegExp('[') ``` -## Environments +Please note that this rule validates regular expressions per the latest ECMAScript specification, regardless of your parser settings. -ECMAScript 6 adds the following flag arguments to the `RegExp` constructor: - -* `"u"` ([unicode](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-regexp.prototype.unicode)) -* `"y"` ([sticky](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-regexp.prototype.sticky)) - -You can enable these to be recognized as valid by setting the ECMAScript version to 6 in your [ESLint configuration](../user-guide/configuring). - -If you want to allow additional constructor flags for any reason, you can specify them using an `allowConstructorFlags` option in `.eslintrc`. These flags will then be ignored by the rule regardless of the `ecmaVersion` setting. +If you want to allow additional constructor flags for any reason, you can specify them using the `allowConstructorFlags` option. These flags will then be ignored by the rule. ## Options @@ -49,14 +42,14 @@ This rule has an object option for exceptions: ### allowConstructorFlags -Examples of **correct** code for this rule with the `{ "allowConstructorFlags": ["u", "y"] }` option: +Examples of **correct** code for this rule with the `{ "allowConstructorFlags": ["a", "z"] }` option: ```js -/*eslint no-invalid-regexp: ["error", { "allowConstructorFlags": ["u", "y"] }]*/ +/*eslint no-invalid-regexp: ["error", { "allowConstructorFlags": ["a", "z"] }]*/ -new RegExp('.', 'y') +new RegExp('.', 'a') -new RegExp('.', 'yu') +new RegExp('.', 'az') ``` ## Further Reading diff --git a/tests/lib/rules/no-invalid-regexp.js b/tests/lib/rules/no-invalid-regexp.js index add1af81fa8a..485ce1e41fd3 100644 --- a/tests/lib/rules/no-invalid-regexp.js +++ b/tests/lib/rules/no-invalid-regexp.js @@ -24,30 +24,68 @@ ruleTester.run("no-invalid-regexp", rule, { "new RegExp('.', 'im')", "global.RegExp('\\\\')", "new RegExp('.', y)", - { code: "new RegExp('.', 'y')", options: [{ allowConstructorFlags: ["y"] }] }, - { code: "new RegExp('.', 'u')", options: [{ allowConstructorFlags: ["U"] }] }, - { code: "new RegExp('.', 'yu')", options: [{ allowConstructorFlags: ["y", "u"] }] }, - { code: "new RegExp('/', 'yu')", options: [{ allowConstructorFlags: ["y", "u"] }] }, - { code: "new RegExp('\\/', 'yu')", options: [{ allowConstructorFlags: ["y", "u"] }] }, - { code: "new RegExp('.', 'y')", parserOptions: { ecmaVersion: 6 } }, - { code: "new RegExp('.', 'u')", parserOptions: { ecmaVersion: 6 } }, - { code: "new RegExp('.', 'yu')", parserOptions: { ecmaVersion: 6 } }, - { code: "new RegExp('/', 'yu')", parserOptions: { ecmaVersion: 6 } }, - { code: "new RegExp('\\/', 'yu')", parserOptions: { ecmaVersion: 6 } }, - { code: "new RegExp('\\\\u{65}', 'u')", parserOptions: { ecmaVersion: 2015 } }, - { code: "new RegExp('[\\\\u{0}-\\\\u{1F}]', 'u')", parserOptions: { ecmaVersion: 2015 } }, - { code: "new RegExp('.', 's')", parserOptions: { ecmaVersion: 2018 } }, - { code: "new RegExp('(?<=a)b')", parserOptions: { ecmaVersion: 2018 } }, - { code: "new RegExp('(?b)\\k')", parserOptions: { ecmaVersion: 2018 } }, - { code: "new RegExp('(?b)\\k', 'u')", parserOptions: { ecmaVersion: 2018 } }, - { code: "new RegExp('\\\\p{Letter}', 'u')", parserOptions: { ecmaVersion: 2018 } }, + "new RegExp('.', 'y')", + "new RegExp('.', 'u')", + "new RegExp('.', 'yu')", + "new RegExp('/', 'yu')", + "new RegExp('\\/', 'yu')", + "new RegExp('\\\\u{65}', 'u')", + "new RegExp('\\\\u{65}*', 'u')", + "new RegExp('[\\\\u{0}-\\\\u{1F}]', 'u')", + "new RegExp('.', 's')", + "new RegExp('(?<=a)b')", + "new RegExp('(?b)\\k')", + "new RegExp('(?b)\\k', 'u')", + "new RegExp('\\\\p{Letter}', 'u')", // ES2020 "new RegExp('(?<\\\\ud835\\\\udc9c>.)', 'g')", "new RegExp('(?<\\\\u{1d49c}>.)', 'g')", "new RegExp('(?<𝒜>.)', 'g');", - "new RegExp('\\\\p{Script=Nandinagari}', 'u');" + "new RegExp('\\\\p{Script=Nandinagari}', 'u');", + + // allowConstructorFlags + { + code: "new RegExp('.', 'g')", + options: [{ allowConstructorFlags: [] }] + }, + { + code: "new RegExp('.', 'g')", + options: [{ allowConstructorFlags: ["a"] }] + }, + { + code: "new RegExp('.', 'a')", + options: [{ allowConstructorFlags: ["a"] }] + }, + { + code: "new RegExp('.', 'ag')", + options: [{ allowConstructorFlags: ["a"] }] + }, + { + code: "new RegExp('.', 'ga')", + options: [{ allowConstructorFlags: ["a"] }] + }, + { + code: "new RegExp('.', 'a')", + options: [{ allowConstructorFlags: ["a", "z"] }] + }, + { + code: "new RegExp('.', 'z')", + options: [{ allowConstructorFlags: ["a", "z"] }] + }, + { + code: "new RegExp('.', 'az')", + options: [{ allowConstructorFlags: ["a", "z"] }] + }, + { + code: "new RegExp('.', 'za')", + options: [{ allowConstructorFlags: ["a", "z"] }] + }, + { + code: "new RegExp('.', 'agz')", + options: [{ allowConstructorFlags: ["a", "z"] }] + } ], invalid: [ { @@ -66,6 +104,42 @@ ruleTester.run("no-invalid-regexp", rule, { type: "CallExpression" }] }, + { + code: "RegExp('.', 'a');", + options: [{}], + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid flags supplied to RegExp constructor 'a'" }, + type: "CallExpression" + }] + }, + { + code: "new RegExp('.', 'a');", + options: [{ allowConstructorFlags: [] }], + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid flags supplied to RegExp constructor 'a'" }, + type: "NewExpression" + }] + }, + { + code: "new RegExp('.', 'z');", + options: [{ allowConstructorFlags: ["a"] }], + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid flags supplied to RegExp constructor 'z'" }, + type: "NewExpression" + }] + }, + { + code: "new RegExp('.', 'az');", + options: [{ allowConstructorFlags: ["z"] }], + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid flags supplied to RegExp constructor 'a'" }, + type: "NewExpression" + }] + }, { code: "new RegExp(')');", errors: [{ @@ -74,6 +148,23 @@ ruleTester.run("no-invalid-regexp", rule, { type: "NewExpression" }] }, + { + code: String.raw`new RegExp('\\a', 'u');`, + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid regular expression: /\\a/u: Invalid escape" }, + type: "NewExpression" + }] + }, + { + code: String.raw`new RegExp('\\a', 'u');`, + options: [{ allowConstructorFlags: ["u"] }], + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid regular expression: /\\a/u: Invalid escape" }, + type: "NewExpression" + }] + }, // https://github.com/eslint/eslint/issues/10861 { From f17c3c371789ffa84f0cda57101e8193899adbe6 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Fri, 15 Jan 2021 21:13:22 +0100 Subject: [PATCH 16/28] Update: check logical assignment operators in the complexity rule (#13979) --- docs/rules/complexity.md | 9 +++++++++ lib/rules/complexity.js | 8 +++++++- tests/lib/rules/complexity.js | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/rules/complexity.md b/docs/rules/complexity.md index 3a665491c39f..a57b4366c1cc 100644 --- a/docs/rules/complexity.md +++ b/docs/rules/complexity.md @@ -32,6 +32,11 @@ function a(x) { return 4; // 3rd path } } + +function b() { + foo ||= 1; + bar &&= 1; +} ``` Examples of **correct** code for a maximum of 2: @@ -46,6 +51,10 @@ function a(x) { return 4; } } + +function b() { + foo ||= 1; +} ``` ## Options diff --git a/lib/rules/complexity.js b/lib/rules/complexity.js index 7fc8bf9bc2ea..5d62c6ff44b8 100644 --- a/lib/rules/complexity.js +++ b/lib/rules/complexity.js @@ -153,7 +153,13 @@ module.exports = { IfStatement: increaseComplexity, SwitchCase: increaseSwitchComplexity, WhileStatement: increaseComplexity, - DoWhileStatement: increaseComplexity + DoWhileStatement: increaseComplexity, + + AssignmentExpression(node) { + if (astUtils.isLogicalAssignmentOperator(node.operator)) { + increaseComplexity(); + } + } }; } diff --git a/tests/lib/rules/complexity.js b/tests/lib/rules/complexity.js index b49ccfc5077c..cf7605baffab 100644 --- a/tests/lib/rules/complexity.js +++ b/tests/lib/rules/complexity.js @@ -48,7 +48,7 @@ function makeError(name, complexity, max) { }; } -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2021 } }); ruleTester.run("complexity", rule, { valid: [ @@ -66,6 +66,18 @@ ruleTester.run("complexity", rule, { { code: "function a(x) {return x === 4 ? 3 : (x === 3 ? 2 : 1);}", options: [3] }, { code: "function a(x) {return x || 4;}", options: [2] }, { code: "function a(x) {x && 4;}", options: [2] }, + { code: "function a(x) {x ?? 4;}", options: [2] }, + { code: "function a(x) {x ||= 4;}", options: [2] }, + { code: "function a(x) {x &&= 4;}", options: [2] }, + { code: "function a(x) {x ??= 4;}", options: [2] }, + { code: "function a(x) {x = 4;}", options: [1] }, + { code: "function a(x) {x |= 4;}", options: [1] }, + { code: "function a(x) {x &= 4;}", options: [1] }, + { code: "function a(x) {x += 4;}", options: [1] }, + { code: "function a(x) {x >>= 4;}", options: [1] }, + { code: "function a(x) {x >>>= 4;}", options: [1] }, + { code: "function a(x) {x == 4;}", options: [1] }, + { code: "function a(x) {x === 4;}", options: [1] }, { code: "function a(x) {switch(x){case 1: 1; break; case 2: 2; break; default: 3;}}", options: [3] }, { code: "function a(x) {switch(x){case 1: 1; break; case 2: 2; break; default: if(x == 'foo') {5;};}}", options: [4] }, { code: "function a(x) {while(true) {'foo';}}", options: [2] }, @@ -95,6 +107,10 @@ ruleTester.run("complexity", rule, { { code: "function a(x) {return x === 4 ? 3 : (x === 3 ? 2 : 1);}", options: [2], errors: 1 }, { code: "function a(x) {return x || 4;}", options: [1], errors: 1 }, { code: "function a(x) {x && 4;}", options: [1], errors: 1 }, + { code: "function a(x) {x ?? 4;}", options: [1], errors: 1 }, + { code: "function a(x) {x ||= 4;}", options: [1], errors: 1 }, + { code: "function a(x) {x &&= 4;}", options: [1], errors: 1 }, + { code: "function a(x) {x ??= 4;}", options: [1], errors: 1 }, { code: "function a(x) {switch(x){case 1: 1; break; case 2: 2; break; default: 3;}}", options: [2], errors: 1 }, { code: "function a(x) {switch(x){case 1: 1; break; case 2: 2; break; default: if(x == 'foo') {5;};}}", options: [3], errors: 1 }, { code: "function a(x) {while(true) {'foo';}}", options: [1], errors: 1 }, From e3264b26a625d926a1ea96df1c4b643af5c3797c Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Fri, 15 Jan 2021 23:40:45 +0100 Subject: [PATCH 17/28] Upgrade: @eslint/eslintrc to improve error message for invalid extends (#14009) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index efce29eeef0d..7003a752d812 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "bugs": "https://github.com/eslint/eslint/issues/", "dependencies": { "@babel/code-frame": "^7.0.0", - "@eslint/eslintrc": "^0.2.2", + "@eslint/eslintrc": "^0.3.0", "ajv": "^6.10.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", From ad923cb9fde31fb2be0f53e1eccb25f21c412c02 Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Fri, 15 Jan 2021 18:00:03 -0500 Subject: [PATCH 18/28] Build: changelog update for 7.18.0 --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44e98b463cff..e647b2d0c351 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,25 @@ +v7.18.0 - January 15, 2021 + +* [`e3264b2`](https://github.com/eslint/eslint/commit/e3264b26a625d926a1ea96df1c4b643af5c3797c) Upgrade: @eslint/eslintrc to improve error message for invalid extends (#14009) (Milos Djermanovic) +* [`f17c3c3`](https://github.com/eslint/eslint/commit/f17c3c371789ffa84f0cda57101e8193899adbe6) Update: check logical assignment operators in the complexity rule (#13979) (Milos Djermanovic) +* [`672deb0`](https://github.com/eslint/eslint/commit/672deb057a14a7acad8c669189870009f1edb8a6) Docs: fix no-invalid-regexp docs regarding ecmaVersion (#13991) (Milos Djermanovic) +* [`179a910`](https://github.com/eslint/eslint/commit/179a910b32e853bc12a9dd71f7c10e762cbeac44) Fix: --init crash on question to upgrade/downgrade ESLint (fixes #13978) (#13995) (Milos Djermanovic) +* [`292b1c0`](https://github.com/eslint/eslint/commit/292b1c0017bc442d399f67e01d699c59e6b71453) Fix: no-extra-parens false positive with `let` identifier in for-loop (#13981) (Milos Djermanovic) +* [`de61f94`](https://github.com/eslint/eslint/commit/de61f9444cf58a4d70e126ab3d10bf20851de7c9) Sponsors: Sync README with website (ESLint Jenkins) +* [`9250d16`](https://github.com/eslint/eslint/commit/9250d167ceb5684669eabe93dae326e33f0684f2) Upgrade: Bump lodash to fix security issue (#13993) (Frederik Prijck) +* [`75fea9b`](https://github.com/eslint/eslint/commit/75fea9bcdd3dde5a07e0089d9011a4df518cdbe3) Sponsors: Sync README with website (ESLint Jenkins) +* [`f2687e7`](https://github.com/eslint/eslint/commit/f2687e71f9e2a2773f821c4dc1a02abe95b97df4) Docs: update space-in-parens related rules (#13985) (Chris Brody) +* [`4a38bbe`](https://github.com/eslint/eslint/commit/4a38bbe81b4b29ca1a4e62d0a0cc8d525455b063) Docs: space-in-parens examples with no arguments etc. (#13987) (Chris Brody) +* [`3e49169`](https://github.com/eslint/eslint/commit/3e491698687aa08b3b798cee0931f0872ca1bc55) Sponsors: Sync README with website (ESLint Jenkins) +* [`c5bf1f2`](https://github.com/eslint/eslint/commit/c5bf1f2150a9fbbb9e74c04808dc3bfeda1ed321) Sponsors: Sync README with website (ESLint Jenkins) +* [`98a729c`](https://github.com/eslint/eslint/commit/98a729c9def54cee9e5478e75e8bd6f28167d5e8) Sponsors: Sync README with website (ESLint Jenkins) +* [`e83a696`](https://github.com/eslint/eslint/commit/e83a6962b51b05c2ddfe42b0748b405d515eeb9d) Sponsors: Sync README with website (ESLint Jenkins) +* [`78cb483`](https://github.com/eslint/eslint/commit/78cb48345c725e9f90fd0e631c476802244df4a4) Chore: test `foo( )` with space-in-parens option "always" (#13986) (Chris Brody) +* [`f6948f6`](https://github.com/eslint/eslint/commit/f6948f6bdc763dca0787bb2786bc9f6f9ed88f43) Docs: Update semantic versioning policy (#13970) (Nicholas C. Zakas) +* [`0688212`](https://github.com/eslint/eslint/commit/068821248e2d2eff11152f270102d537d8fa8126) Sponsors: Sync README with website (ESLint Jenkins) +* [`aeba5e5`](https://github.com/eslint/eslint/commit/aeba5e5e6062095a06d9b867d7e7ee75422f25b9) Chore: fix typo (#13975) (Nitin Kumar) +* [`4ee1134`](https://github.com/eslint/eslint/commit/4ee113414bdcbea240a5d9db27da6a10df472005) Sponsors: Sync README with website (ESLint Jenkins) + v7.17.0 - January 1, 2021 * [`e128e77`](https://github.com/eslint/eslint/commit/e128e775e9fa116a0ad68a071f1f0997589f8cd4) Update: check logical assignment in no-constant-condition (#13946) (Milos Djermanovic) From 6509705a3b8d2542d09d1c22041fe73dd0d0638f Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Fri, 15 Jan 2021 18:00:03 -0500 Subject: [PATCH 19/28] 7.18.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7003a752d812..297e8c5df404 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint", - "version": "7.17.0", + "version": "7.18.0", "author": "Nicholas C. Zakas ", "description": "An AST-based pattern checker for JavaScript.", "bin": { From f7ca48165d025e01c38698352cff24d1de87cc8b Mon Sep 17 00:00:00 2001 From: Brandon Mills Date: Sun, 17 Jan 2021 21:26:19 -0500 Subject: [PATCH 20/28] Docs: Explain why we disable lock files (refs eslint/tsc-meetings#234) (#14006) --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 73a30990e509..b7a9d18ad625 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,16 @@ Once a language feature has been adopted into the ECMAScript standard (stage 4 a Join our [Mailing List](https://groups.google.com/group/eslint) or [Chatroom](https://eslint.org/chat). +### Why doesn't ESLint lock dependency versions? + +Lock files like `package-lock.json` are helpful for deployed applications. They ensure that dependencies are consistent between environments and across deployments. + +Packages like `eslint` that get published to the npm registry do not include lock files. `npm install eslint` as a user will respect version constraints in ESLint's `package.json`. ESLint and its dependencies will be included in the user's lock file if one exists, but ESLint's own lock file would not be used. + +We intentionally don't lock dependency versions so that we have the latest compatible dependency versions in development and CI that our users get when installing ESLint in a project. + +The Twilio blog has a [deeper dive](https://www.twilio.com/blog/lockfiles-nodejs) to learn more. + ## Releases We have scheduled releases every two weeks on Friday or Saturday. You can follow a [release issue](https://github.com/eslint/eslint/issues?q=is%3Aopen+is%3Aissue+label%3Arelease) for updates about the scheduling of any particular release. From a4fdb7001aa41b9ad8bb92cc8a47b9135c94afc7 Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Mon, 18 Jan 2021 13:26:14 -0800 Subject: [PATCH 21/28] Docs: Fixed Typo (#14007) --- docs/rules/prefer-arrow-callback.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/prefer-arrow-callback.md b/docs/rules/prefer-arrow-callback.md index c9132122ea58..7b98aa1f8f66 100644 --- a/docs/rules/prefer-arrow-callback.md +++ b/docs/rules/prefer-arrow-callback.md @@ -86,7 +86,7 @@ foo(function() { this.a; }); foo(function() { (() => this); }); -someArray.map(function(itm) { return this.doSomething(itm); }, someObject); +someArray.map(function(item) { return this.doSomething(item); }, someObject); ``` ## When Not To Use It From c753b442ef67867a178ffc2ad29b4e0534f72469 Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Thu, 21 Jan 2021 05:11:45 -0500 Subject: [PATCH 22/28] Sponsors: Sync README with website --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b7a9d18ad625..b998a63a6868 100644 --- a/README.md +++ b/README.md @@ -271,7 +271,7 @@ The following companies, organizations, and individuals support ESLint's ongoing

Platinum Sponsors

Automattic

Gold Sponsors

-

Chrome's Web Framework & Tools Performance Fund Shopify Salesforce Airbnb Microsoft FOSS Fund Sponsorships

Silver Sponsors

+

Chrome's Web Framework & Tools Performance Fund Shopify Salesforce Airbnb Microsoft FOSS Fund Sponsorships

Silver Sponsors

Liftoff AMP Project

Bronze Sponsors

Streamat The Standard Daily Writers Per Hour February 2021 calendar Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

From f6602d569427e9e2a4f3b5ca3fc3a8bffb28d15e Mon Sep 17 00:00:00 2001 From: klkhan Date: Sat, 23 Jan 2021 06:24:59 +0500 Subject: [PATCH 23/28] Docs: Reorganize Configuration Documentation (#13837) * Create Configuration Files * Create Index File * Create Configuration Files * Delete Configuration Files * Create Configuration Files * Create Language Options * Create Rules * Create Plugins * Create Ignoring Code * Update README.md * Update README.md * Rename Language Options.md to language-options.md * Rename Configuration Files.md to configuration-files.md * Rename Rules.md to rules.md * Rename Plugins.md to plugins.md * Rename Ignoring Code.md to ignoring-code.md * Rename docs/user-guide/Configuring ESLint/README.md to docs/user-guide/configuring-ESLint/README.md * Rename docs/user-guide/Configuring ESLint/configuration-files.md to docs/user-guide/configuring-ESLint/configuration-files.md * Rename docs/user-guide/Configuring ESLint/ignoring-code.md to docs/user-guide/configuring-ESLint/ignoring-code.md * Rename docs/user-guide/Configuring ESLint/language-options.md to docs/user-guide/configuring-ESLint/language-options.md * Rename docs/user-guide/Configuring ESLint/plugins.md to docs/user-guide/configuring-ESLint/plugins.md * Rename docs/user-guide/Configuring ESLint/rules.md to docs/user-guide/configuring-ESLint/rules.md * Update README.md * Update README.md * Update README.md * Update configuration-files.md * Update ignoring-code.md * Update ignoring-code.md * Update ignoring-code.md * Update ignoring-code.md * Update README.md * Update plugins.md * Update rules.md * Update configuration-files.md * Update language-options.md * Update rules.md * Update plugins.md * Update ignoring-code.md * Docs: Update Configurating ESLint README.md Added space before and after the list items to remove an error. * Docs: Update Plugins.md in Configuring ESLint Updated the file to remove the error in line 63. * Docs: Update README.md in Configuring ESLint Updated the heading to remove the error in line 1. * Docs: Renamed the directory to configuring-eslint Renamed parent directory to remove the uppercase letters from the name. * Docs: Renamed the directory to configuring-eslint Renamed the parent directory to remove the uppercase letters from the name. * Docs: Renamed the directory to configuring-eslint Renamed the parent directory to remove the uppercase letters from the name. * Docs: Renamed the directory to configuring-eslint Renamed the parent directory to remove the uppercase letters from the name. * Docs: Renamed the directory to configuring-eslint Renamed the parent directory to remove the uppercase letters from the name. * Docs: Renamed the directory to configuring-eslint Renamed the parent directory to remove the uppercase letters from the name. * Docs: Update README.md for configuring ESLint Updated the directory name by changing it from 'configuring-eslint' to 'configuring' to use the already-available directory. * Docs: Update configuration files Updated the directory name by changing it from 'configuring-eslint' to 'configuring' to use the already-available directory. * Docs: Update ignoring-code.md Updated the directory name by changing it from 'configuring-eslint' to 'configuring' to use the already-available directory. * Docs: Update language-options.md Updated the directory name by changing it from 'configuring-eslint' to 'configuring' to use the already-available directory. * Docs: Update plugins.md Updated the directory name by changing it from 'configuring-eslint' to 'configuring' to use the already-available directory. * Docs: Update rules.md Updated the directory name by changing it from 'configuring-eslint' to 'configuring' to use the already-available directory. * Docs: Update docs/user-guide/configuring/README.md Accepted a suggestion on the README.md file. Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/README.md Accepted a suggested change in the README.md file. Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/configuration-files.md Accepted a suggested change to configuration-files.md Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/configuration-files.md Accepted a suggesetd change to configuration-files.md Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/configuration-files.md Accepted a suggested change to configuration-files.md Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/configuration-files.md Accepted a suggested change to configuration-files.md Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/configuration-files.md Accepted a suggested change to configuration-files.md Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/configuration-files.md Accepted a suggested change to configuration-files.md Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/configuration-files.md Accepted a suggested change to configuration-files.md Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/configuration-files.md Accepted a suggested change to configuration-files.md Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/configuration-files.md Accepted a suggested change to configuration-files.md Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/configuration-files.md Accepted a suggested change to configuration-files.md Co-authored-by: Nicholas C. Zakas * Docs: Update configuration-files.md Accepted two suggested changes to configuration-files.md * Docs: Update configuration-files.md Removed the names of deprecated files (.eslintrc), using '.eslintrc.json' instead. * Docs: Update docs/user-guide/configuring/README.md Accepted a suggestion to improve the README.md file Co-authored-by: Kai Cataldo * Docs: Update configuration-files.md Accepted suggestions made to the configuration-files.md file in ESLint Configuration documentation. * Docs: Update configuration-files.md Accepted a suggestion to edit configuration-files.md * Docs: Update configuration-files.md Accepted suggestions made to the configuration-files. md file in ESLint COnfiguration Documentation. * Docs: Update docs/user-guide/configuring/rules.md Accepted a suggestion to rules. md file. Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/plugins.md Accepted a suggestion to plugins.md file. Co-authored-by: Nicholas C. Zakas * Docs: Update docs/user-guide/configuring/language-options.md Accepted a suggestion to language-options.md file. Co-authored-by: Nicholas C. Zakas * Docs: Update README.md Updated the Table of Content to change the name of a heading from "eslintignore" to "The eslintignore File" * Docs: Update ingoring-code.md Accepted suggestions to the ignoring-code.md file. * Docs: Update configuration-files.md Accepted suggestions made to configuration-files.md. * Docs: Update docs/user-guide/configuring/language-options.md Accepted a suggestion made to language-options.md Co-authored-by: Brandon Mills * Docs: Update docs/user-guide/configuring/plugins.md Accepted a suggestion made to plugins.md Co-authored-by: Brandon Mills * Docs: Update ignoring-code.md Accepted suggestions made to ignoring-code.md * Docs: Update configuration-files.md Accepted suggestions to configuration-files.md * Update docs/user-guide/configuring/ignoring-code.md Co-authored-by: Kai Cataldo * Update docs/user-guide/configuring/ignoring-code.md Co-authored-by: Kai Cataldo * Update docs/user-guide/configuring/language-options.md Co-authored-by: Kai Cataldo * Update docs/user-guide/configuring/language-options.md * Update ignoring-code.md Updated ignoring-code.md by incorporating some suggested changes. * [Docs] Update rules.md Updated rules.md by moving`Disabling Inline Comments` to this section. * [Docs] Update README.md Updated the table of contents * [Docs] Update rules.md * Update docs/user-guide/configuring/ignoring-code.md * Update docs/user-guide/configuring/ignoring-code.md * Update docs/user-guide/configuring/ignoring-code.md * Update docs/user-guide/configuring/ignoring-code.md * Update docs/user-guide/configuring/ignoring-code.md * Docs: Update configuration-files.md * Docs: Update configuration-files.md Co-authored-by: Nicholas C. Zakas Co-authored-by: Kai Cataldo Co-authored-by: Brandon Mills --- docs/user-guide/configuring/README.md | 52 +++ .../configuring/configuration-files.md | 408 ++++++++++++++++++ docs/user-guide/configuring/ignoring-code.md | 155 +++++++ .../configuring/language-options.md | 214 +++++++++ docs/user-guide/configuring/plugins.md | 177 ++++++++ docs/user-guide/configuring/rules.md | 264 ++++++++++++ 6 files changed, 1270 insertions(+) create mode 100644 docs/user-guide/configuring/README.md create mode 100644 docs/user-guide/configuring/configuration-files.md create mode 100644 docs/user-guide/configuring/ignoring-code.md create mode 100644 docs/user-guide/configuring/language-options.md create mode 100644 docs/user-guide/configuring/plugins.md create mode 100644 docs/user-guide/configuring/rules.md diff --git a/docs/user-guide/configuring/README.md b/docs/user-guide/configuring/README.md new file mode 100644 index 000000000000..0aeaffdd28c8 --- /dev/null +++ b/docs/user-guide/configuring/README.md @@ -0,0 +1,52 @@ +# Configuring ESLint + +ESLint is designed to be flexible and configurable for your use case. You can turn off every rule and run only with basic syntax validation or mix and match the bundled rules and your custom rules to fit the needs of your project. There are two primary ways to configure ESLint: + +1. **Configuration Comments** - use JavaScript comments to embed configuration information directly into a file. +1. **Configuration Files** - use a JavaScript, JSON, or YAML file to specify configuration information for an entire directory and all of its subdirectories. This can be in the form of an [`.eslintrc.*`](./configuring-files#configuration-file-formats) file or an `eslintConfig` field in a [`package.json`](https://docs.npmjs.com/files/package.json) file, both of which ESLint will look for and read automatically, or you can specify a configuration file on the [command line](https://eslint.org/docs/user-guide/command-line-interface). + +Here are some of the options that you can configure in ESLint: + +* [**Environments**](./language-options.md#specifying-environments) - which environments your script is designed to run in. Each environment brings with it a certain set of predefined global variables. +* [**Globals**](./language-options.md#specifying-globals) - the additional global variables your script accesses during execution. +* [**Rules**](rules.md) - which rules are enabled and at what error level. +* [**Plugins**](plugins.md) - which third-party plugins define additional rules, environments, configs, etc. for ESLint to use. + +All of these options give you fine-grained control over how ESLint treats your code. + +## Table of Contents + +[**Configuration Files**](configuration-files.md) + +* [Configuration File Formats](./configuration-files.md#configuration-file-formats) +* [Using Configuration Files](./configuration-files.md#using-configuration-files) +* [Adding Shared Settings](./configuration-files.md#adding-shared-settings) +* [Cascading and Hierarchy](./configuration-files.md#cascading-and-hierarchy) +* [Extending Configuration Files](./configuring-files.md#extending-configuration-files) +* [Configuration Based on Glob Patterns](./configuration-files.md#configuration-based-on-glon-patterns) +* [Personal Configuration Files](./configuration-files.md#personal-configuration-files) + +[**Language Options**](language-options.md) + +* [Specifying Environments](./language-options.md#specifying-environments) +* [Specifying Globals](./language-options.md#specifying-globals) +* [Specifying Parser Options](./language-options.md#specifying-parser-options) + +[**Rules**](rules.md) + +* [Configuring Rules](./rules.md#configuring-rules) +* [Disabling Rules](./rules.md#disabling-rules) + +[**Plugins**](plugins.md) + +* [Specifying Parser](./plugins.md#specifying-parser) +* [Specifying Processor](./plugins.md#specifying-processor) +* [Configuring Plugins](./plugins.md#configuring-plugins) + +[**Ignoring Code**](ignoring-code.md) + +* [`ignorePatterns` in Config Files](./ignoring-code.md#ignorepatterns-in-config-files) +* [The `.eslintignore` File](./ignoring-code.md#the-eslintignore-file) +* [Using an Alternate File](./ignoring-code.md#using-an-alternate-file) +* [Using eslintIgnore in package.json](./ignoring-code.md#using-eslintignore-in-package.json) +* [Ignored File Warnings](./ignoring-code.md#ignored-file-warnings) diff --git a/docs/user-guide/configuring/configuration-files.md b/docs/user-guide/configuring/configuration-files.md new file mode 100644 index 000000000000..da0ee1aba1be --- /dev/null +++ b/docs/user-guide/configuring/configuration-files.md @@ -0,0 +1,408 @@ +# Configuration Files + +* [Configuration File Formats](#configuration-file-formats) +* [Using Configuration Files](#using-configuration-files) +* [Adding Shared Settings](#adding-shared-settings) +* [Cascading and Hierarchy](#cascading-and-hierarchy) +* [Extending Configuration Files](#extending-configuration-files) +* [Configuration Based on Glob Patterns](#configuration-based-on-glob-patterns) +* [Personal Configuration Files](#personal-configuration-files) + +## Configuration File Formats + +ESLint supports configuration files in several formats: + +* **JavaScript** - use `.eslintrc.js` and export an object containing your configuration. +* **JavaScript (ESM)** - use `.eslintrc.cjs` when running ESLint in JavaScript packages that specify `"type":"module"` in their `package.json`. Note that ESLint does not support ESM configuration at this time. +* **YAML** - use `.eslintrc.yaml` or `.eslintrc.yml` to define the configuration structure. +* **JSON** - use `.eslintrc.json` to define the configuration structure. ESLint's JSON files also allow JavaScript-style comments. +* **package.json** - create an `eslintConfig` property in your `package.json` file and define your configuration there. + +If there are multiple configuration files in the same directory, ESLint will only use one. The priority order is as follows: + +1. `.eslintrc.js` +1. `.eslintrc.cjs` +1. `.eslintrc.yaml` +1. `.eslintrc.yml` +1. `.eslintrc.json` +1. `package.json` + +## Using Configuration Files + +There are two ways to use configuration files. + +The first way to use configuration files is via `.eslintrc.*` and `package.json` files. ESLint will automatically look for them in the directory of the file to be linted, and in successive parent directories all the way up to the root directory of the filesystem (unless `root: true` is specified). Configuration files can be useful when you want different configurations for different parts of a project or when you want others to be able to use ESLint directly without needing to remember to pass in the configuration file. + +The second way to use configuration files is to save the file wherever you would like and pass its location to the CLI using the `--config` option, such as: + + eslint -c myconfig.json myfiletotest.js + +If you are using one configuration file and want ESLint to ignore any `.eslintrc.*` files, make sure to use [`--no-eslintrc`](https://eslint.org/docs/user-guide/command-line-interface#-no-eslintrc) along with the [`-c`](https://eslint.org/docs/user-guide/command-line-interface#-c-config) flag. + +### Comments in configuration files + +Both the JSON and YAML configuration file formats support comments (package.json files should not include them). You can use JavaScript-style comments for JSON files and YAML-style comments for YAML files. ESLint safely ignores comments in configuration files. This allows your configuration files to be more human-friendly. + +For JavaScript-style comments: + +```js +{ + "env": { + "browser": true + }, + "rules": { + // Override our default settings just for this directory + "eqeqeq": "warn", + "strict": "off" + } +} +``` + +For YAML-style comments: + +```yaml +env: + browser: true +rules: + # Override default settings + eqeqeq: warn + strict: off +``` + +## Adding Shared Settings + +ESLint supports adding shared settings into configuration files. Plugins use `settings` to specify information that should be shared across all of its rules. You can add `settings` object to ESLint configuration file and it will be supplied to every rule being executed. This may be useful if you are adding custom rules and want them to have access to the same information and be easily configurable. + +In JSON: + +```json +{ + "settings": { + "sharedData": "Hello" + } +} +``` + +And in YAML: + +```yaml +--- + settings: + sharedData: "Hello" +``` + +## Cascading and Hierarchy + +When using `.eslintrc.*` and `package.json` files for configuration, you can take advantage of configuration cascading. Suppose you have the following structure: + +```text +your-project +├── .eslintrc.json +├── lib +│ └── source.js +└─┬ tests + ├── .eslintrc.json + └── test.js +``` + +The configuration cascade works based on the location of the file being linted. If there is a `.eslintrc` file in the same directory as the file being linted, then that configuration takes precedence. ESLint then searches up the directory structure, merging any `.eslintrc` files it finds along the way until reaching either a `.eslintrc` file with `root: true` or the root directory. + +In the same way, if there is a `package.json` file in the root directory with an `eslintConfig` field, the configuration it describes will apply to all subdirectories beneath it, but the configuration described by the `.eslintrc` file in the `tests/` directory will override it where there are conflicting specifications. + +```text +your-project +├── package.json +├── lib +│ └── source.js +└─┬ tests + ├── .eslintrc.json + └── test.js +``` + +If there is an `.eslintrc` and a `package.json` file found in the same directory, `.eslintrc` will take priority and `package.json` file will not be used. + +By default, ESLint will look for configuration files in all parent folders up to the root directory. This can be useful if you want all of your projects to follow a certain convention, but can sometimes lead to unexpected results. To limit ESLint to a specific project, place `"root": true` inside the `.eslintrc.*` file or `eslintConfig` field of the `package.json` file or in the `.eslintrc.*` file at your project's root level. ESLint will stop looking in parent folders once it finds a configuration with `"root": true`. + +```js +{ + "root": true +} +``` + +And in YAML: + +```yaml +--- + root: true +``` + +For example, consider `projectA` which has `"root": true` set in the `.eslintrc` file in the `lib/` directory. In this case, while linting `main.js`, the configurations within `lib/` will be used, but the `.eslintrc` file in `projectA/` will not. + +```text +home +└── user + └── projectA + ├── .eslintrc.json <- Not used + └── lib + ├── .eslintrc.json <- { "root": true } + └── main.js +``` + +The complete configuration hierarchy, from highest to lowest precedence, is as follows: + +1. Inline configuration + 1. `/*eslint-disable*/` and `/*eslint-enable*/` + 1. `/*global*/` + 1. `/*eslint*/` + 1. `/*eslint-env*/` +1. Command line options (or CLIEngine equivalents): + 1. `--global` + 1. `--rule` + 1. `--env` + 1. `-c`, `--config` +1. Project-level configuration: + 1. `.eslintrc.*` or `package.json` file in the same directory as the linted file + 1. Continue searching for `.eslintrc.*` and `package.json` files in ancestor directories up to and including the root directory or until a config with `"root": true` is found. + +## Extending Configuration Files + +A configuration file, once extended, can inherit all the traits of another configuration file (including rules, plugins, and language options) and modify all the options. As a result, there are three configurations, as defined below: + +* Base config: the configuration that is extended. +* Derived config: the configuration that extends the base configuration. +* Resulting actual config: the result of merging the derived configuration into the base configuration. + +The `extends` property value is either: + +* a string that specifies a configuration (either a path to a config file, the name of a shareable config, `eslint:recommended`, or `eslint:all`) +* an array of strings where each additional configuration extends the preceding configurations + +ESLint extends configurations recursively, so a base configuration can also have an `extends` property. Relative paths and shareable config names in an `extends` property are resolved from the location of the config file where they appear. + +The `eslint-config-` prefix can be omitted from the configuration name. For example, `airbnb` resolves as `eslint-config-airbnb`. + +The `rules` property can do any of the following to extend (or override) the set of rules: + +* enable additional rules +* change an inherited rule's severity without changing its options: + * Base config: `"eqeqeq": ["error", "allow-null"]` + * Derived config: `"eqeqeq": "warn"` + * Resulting actual config: `"eqeqeq": ["warn", "allow-null"]` +* override options for rules from base configurations: + * Base config: `"quotes": ["error", "single", "avoid-escape"]` + * Derived config: `"quotes": ["error", "single"]` + * Resulting actual config: `"quotes": ["error", "single"] + +### Using a shareable configuration package + +A [sharable configuration](https://eslint.org/docs/developer-guide/shareable-configs) is an npm package that exports a configuration object. Make sure that you have installed the package in your project root directory, so that ESLint can require it. + +The `extends` property value can omit the `eslint-config-` prefix of the package name. + +The `eslint --init` command can create a configuration so you can extend a popular style guide (for example, `eslint-config-standard`). + +Example of a configuration file in YAML format: + +```yaml +extends: standard +rules: + comma-dangle: + - error + - always + no-empty: warn +``` + +### Using `eslint:recommended` + +Using `"eslint:recommended"` in the `extends` property enables a subset of core rules that report common problems (these rules are identified with a checkmark (recommended) on the [rules page](https://eslint.org/docs/rules/)). + +Here's an example of extending `eslint:recommended` and overriding some of the set configuration options: + +Example of a configuration file in JavaScript format: + +```js +module.exports = { + "extends": "eslint:recommended", + "rules": { + // enable additional rules + "indent": ["error", 4], + "linebreak-style": ["error", "unix"], + "quotes": ["error", "double"], + "semi": ["error", "always"], + + // override configuration set by extending "eslint:recommended" + "no-empty": "warn", + "no-cond-assign": ["error", "always"], + + // disable rules from base configurations + "for-direction": "off", + } +} +``` + +### Using a configuration from a plugin + +A [plugin](https://eslint.org/docs/developer-guide/working-with-plugins) is an npm package that can add various extensions to ESLint. A plugin can perform numerous functions, including but not limited to adding new rules and exporting [shareable configurations](https://eslint.org/docs/developer-guide/working-with-plugins#configs-in-plugins). Make sure the package has been installed in a directory where ESLint can require it. + +The `plugins` [property value](./plugins.md#configuring-plugins) can omit the `eslint-plugin-` prefix of the package name. + +The `extends` property value can consist of: + +* `plugin:` +* the package name (from which you can omit the prefix, for example, `react` is short for `eslint-plugin-react`) +* `/` +* the configuration name (for example, `recommended`) + +Example of a configuration file in JSON format: + +```json +{ + "plugins": [ + "react" + ], + "extends": [ + "eslint:recommended", + "plugin:react/recommended" + ], + "rules": { + "react/no-set-state": "off" + } +} +``` + +### Using a configuration file + +The `extends` property value can be an absolute or relative path to a base [configuration file](#using-configuration-files). ESLint resolves a relative path to a base configuration file relative to the configuration file that uses it. + +Example of a configuration file in JSON format: + +```json +{ + "extends": [ + "./node_modules/coding-standard/eslintDefaults.js", + "./node_modules/coding-standard/.eslintrc-es6", + "./node_modules/coding-standard/.eslintrc-jsx" + ], + "rules": { + "eqeqeq": "warn" + } +} +``` + +### Using `"eslint:all"` + +The `extends` property value can be `"eslint:all"` to enable all core rules in the currently installed version of ESLint. The set of core rules can change at any minor or major version of ESLint. + +**Important:** This configuration is **not recommended for production use** because it changes with every minor and major version of ESLint. Use it at your own risk. + +You might enable all core rules as a shortcut to explore rules and options while you decide on the configuration for a project, especially if you rarely override options or disable rules. The default options for rules are not endorsements by ESLint (for example, the default option for the [`quotes`](https://eslint.org/docs/rules/quotes) rule does not mean double quotes are better than single quotes). + +If your configuration extends `eslint:all`, after you upgrade to a newer major or minor version of ESLint, review the reported problems before you use the `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fix), so you know if a new fixable rule will make changes to the code. + +Example of a configuration file in JavaScript format: + +```js +module.exports = { + "extends": "eslint:all", + "rules": { + // override default options + "comma-dangle": ["error", "always"], + "indent": ["error", 2], + "no-cond-assign": ["error", "always"], + + // disable now, but enable in the future + "one-var": "off", // ["error", "never"] + + // disable + "init-declarations": "off", + "no-console": "off", + "no-inline-comments": "off", + } +} +``` + +## Configuration Based on Glob Patterns + +v4.1.0+. Sometimes a more fine-controlled configuration is necessary, for example, if the configuration for files within the same directory has to be different. Therefore you can provide configurations under the `overrides` key that will only apply to files that match specific glob patterns, using the same format you would pass on the command line (e.g., `app/**/*.test.js`). + +### How do overrides work? + +It is possible to override settings based on file glob patterns in your configuration by using the `overrides` key. An example of using the `overrides` key is as follows: + +In your `.eslintrc.json`: + +```json +{ + "rules": { + "quotes": ["error", "double"] + }, + + "overrides": [ + { + "files": ["bin/*.js", "lib/*.js"], + "excludedFiles": "*.test.js", + "rules": { + "quotes": ["error", "single"] + } + } + ] +} +``` + +Here is how overrides work in a configuration file: + +* The patterns are applied against the file path relative to the directory of the config file. For example, if your config file has the path `/Users/john/workspace/any-project/.eslintrc.js` and the file you want to lint has the path `/Users/john/workspace/any-project/lib/util.js`, then the pattern provided in `.eslintrc.js` will be executed against the relative path `lib/util.js`. +* Glob pattern overrides have higher precedence than the regular configuration in the same config file. Multiple overrides within the same config are applied in order. That is, the last override block in a config file always has the highest precedence. +* A glob specific configuration works almost the same as any other ESLint config. Override blocks can contain any configuration options that are valid in a regular config, with the exception of `root` and `ignorePatterns`. + * A glob specific configuration can have an `extends` setting, but the `root` property in the extended configs is ignored. The `ignorePatterns` property in the extended configs is used only for the files the glob specific configuration matched. + * Nested `overrides` setting will be applied only if the glob patterns of both of the parent config and the child config matched. This is the same when the extended configs have an `overrides` setting. +* Multiple glob patterns can be provided within a single override block. A file must match at least one of the supplied patterns for the configuration to apply. +* Override blocks can also specify patterns to exclude from matches. If a file matches any of the excluded patterns, the configuration won't apply. + +### Relative glob patterns + +``` +project-root +├── app +│ ├── lib +│ │ ├── foo.js +│ │ ├── fooSpec.js +│ ├── components +│ │ ├── bar.js +│ │ ├── barSpec.js +│ ├── .eslintrc.json +├── server +│ ├── server.js +│ ├── serverSpec.js +├── .eslintrc.json +``` + +The config in `app/.eslintrc.json` defines the glob pattern `**/*Spec.js`. This pattern is relative to the base directory of `app/.eslintrc.json`. So, this pattern would match `app/lib/fooSpec.js` and `app/components/barSpec.js` but **NOT** `server/serverSpec.js`. If you defined the same pattern in the `.eslintrc.json` file within in the `project-root` folder, it would match all three of the `*Spec` files. + +If a config is provided via the `--config` CLI option, the glob patterns in the config are relative to the current working directory rather than the base directory of the given config. For example, if `--config configs/.eslintrc.json` is present, the glob patterns in the config are relative to `.` rather than `./configs`. + +### Specifying target files to lint + +If you specified directories with CLI (e.g., `eslint lib`), ESLint searches target files in the directory to lint. The target files are `*.js` or the files that match any of `overrides` entries (but exclude entries that are any of `files` end with `*`). + +If you specified the [`--ext`](https://eslint.org/docs/user-guide/command-line-interface#ext) command line option along with directories, the target files are only the files that have specified file extensions regardless of `overrides` entries. + +## Personal Configuration Files (deprecated) + +⚠️ **This feature has been deprecated**. This feature will be removed in the 8.0.0 release. If you want to continue to use personal configuration files, please use the [`--config` CLI option](https://eslint.org/docs/user-guide/command-line-interface#-c---config). For more information regarding this decision, please see [RFC 28](https://github.com/eslint/rfcs/pull/28) and [RFC 32](https://github.com/eslint/rfcs/pull/32). + +`~/` refers to [the home directory of the current user on your preferred operating system](https://nodejs.org/api/os.html#os_os_homedir). The personal configuration file being referred to here is `~/.eslintrc.*` file, which is currently handled differently than other configuration files. + +### How does ESLint find personal configuration files? + +If `eslint` could not find any configuration file in the project, `eslint` loads `~/.eslintrc.*` file. + +If `eslint` could find configuration files in the project, `eslint` ignores `~/.eslintrc.*` file even if it's in an ancestor directory of the project directory. + +### How do personal configuration files behave? + +`~/.eslintrc.*` files behave similarly to regular configuration files, with some exceptions: + +`~/.eslintrc.*` files load shareable configs and custom parsers from `~/node_modules/` – similarly to `require()` – in the user's home directory. Please note that it doesn't load global-installed packages. + +`~/.eslintrc.*` files load plugins from `$CWD/node_modules` by default in order to identify plugins uniquely. If you want to use plugins with `~/.eslintrc.*` files, plugins must be installed locally per project. Alternatively, you can use the [`--resolve-plugins-relative-to` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--resolve-plugins-relative-to) to change the location from which ESLint loads plugins. diff --git a/docs/user-guide/configuring/ignoring-code.md b/docs/user-guide/configuring/ignoring-code.md new file mode 100644 index 000000000000..d7b3cfd27c8f --- /dev/null +++ b/docs/user-guide/configuring/ignoring-code.md @@ -0,0 +1,155 @@ +# Ignoring Code + + +* [`ignorePatterns` in Config Files](#ignorepatterns-in-config-files) +* [The `.eslintignore` File](#the-eslintignore-file) +* [Using an Alternate File](#using-an-alternate-file) +* [Using eslintIgnore in package.json](#using-eslintignore-in-packagejson) +* [Ignored File Warnings](#ignored-file-warnings) + +## `ignorePatterns` in Config Files + +You can tell ESLint to ignore specific files and directories using `ignorePatterns` in your config files. `ignorePatterns` patterns follow the same rules as `.eslintignore`. Please see the [the `.eslintignore` file documentation](./ignoring-code.md#the-eslintignore-file) to learn more. + +```json +{ + "ignorePatterns": ["temp.js", "**/vendor/*.js"], + "rules": { + //... + } +} +``` + +* Glob patterns in `ignorePatterns` are relative to the directory that the config file is placed in. +* You cannot write `ignorePatterns` property under `overrides` property. +* Patterns defined in `.eslintignore` take precedence over the `ignorePatterns` property of config files. + +If a glob pattern starts with `/`, the pattern is relative to the base directory of the config file. For example, `/foo.js` in `lib/.eslintrc.json` matches to `lib/foo.js` but not `lib/subdir/foo.js`. + +If a config is provided via the `--config` CLI option, the ignore patterns that start with `/` in the config are relative to the current working directory rather than the base directory of the given config. For example, if `--config configs/.eslintrc.json` is present, the ignore patterns in the config are relative to `.` rather than `./configs`. + +## The `.eslintignore` File + +You can tell ESLint to ignore specific files and directories by creating an `.eslintignore` file in your project's root directory. The `.eslintignore` file is a plain text file where each line is a glob pattern indicating which paths should be omitted from linting. For example, the following will omit all JavaScript files: + +```text +**/*.js +``` + +When ESLint is run, it looks in the current working directory to find an `.eslintignore` file before determining which files to lint. If this file is found, then those preferences are applied when traversing directories. Only one `.eslintignore` file can be used at a time, so `.eslintignore` files other than the one in the current working directory will not be used. + +Globs are matched using [node-ignore](https://github.com/kaelzhang/node-ignore), so a number of features are available: + +* Lines beginning with `#` are treated as comments and do not affect the ignore patterns. +* Paths are relative to the current working directory. This is also true of paths passed in via the `--ignore-pattern` [command](https://eslint.org/docs/user-guide/command-line-interface#--ignore-pattern). +* Lines preceded by `!` are negated patterns that re-include a pattern that was ignored by an earlier pattern. +* Ignore patterns behave according to the `.gitignore` [specification](https://git-scm.com/docs/gitignore). + +Of particular note is that like `.gitignore` files, all paths used as patterns for both `.eslintignore` and `--ignore-pattern` must use forward slashes as their path separators. + +```text +# Valid +/root/src/*.js + +# Invalid +\root\src\*.js +``` + +Please see [`.gitignore`](https://git-scm.com/docs/gitignore)'s specification for further examples of valid syntax. + +In addition to any patterns in the `.eslintignore` file, ESLint always follows a couple of implicit ignore rules even if the `--no-ignore` flag is passed. The implicit rules are as follows: + +* `node_modules/` is ignored. +* dot-files (except for `.eslintrc.*`), as well as dot-folders and their contents, are ignored. + +There are also some exceptions to these rules: + +* If the path to lint is a glob pattern or directory path and contains a dot-folder, all dot-files and dot-folders will be linted. This includes dot-files and dot-folders that are buried deeper in the directory structure. + + For example, `eslint .config/` will lint all dot-folders and dot-files in the `.config` directory, including immediate children as well as children that are deeper in the directory structure. + +* If the path to lint is a specific file path and the `--no-ignore` flag has been passed, ESLint will lint the file regardless of the implicit ignore rules. + + For example, `eslint .config/my-config-file.js --no-ignore` will cause `my-config-file.js` to be linted. It should be noted that the same command without the `--no-ignore` line will not lint the `my-config-file.js` file. + +* Allowlist and denylist rules specified via `--ignore-pattern` or `.eslintignore` are prioritized above implicit ignore rules. + + For example, in this scenario, `.build/test.js` is the desired file to allowlist. Because all dot-folders and their children are ignored by default, `.build` must first be allowlisted so that eslint becomes aware of its children. Then, `.build/test.js` must be explicitly allowlisted, while the rest of the content is denylisted. This is done with the following `.eslintignore` file: + + ```text + # Allowlist 'test.js' in the '.build' folder + # But do not allow anything else in the '.build' folder to be linted + !.build + .build/* + !.build/test.js + ``` + + The following `--ignore-pattern` is also equivalent: + + eslint --ignore-pattern '!.build' --ignore-pattern '.build/*' --ignore-pattern '!.build/test.js' parent-folder/ + +## Using an Alternate File + +If you'd prefer to use a different file than the `.eslintignore` in the current working directory, you can specify it on the command line using the `--ignore-path` option. For example, you can use `.jshintignore` file because it has the same format: + + eslint --ignore-path .jshintignore file.js + +You can also use your `.gitignore` file: + + eslint --ignore-path .gitignore file.js + +Any file that follows the standard ignore file format can be used. Keep in mind that specifying `--ignore-path` means that any existing `.eslintignore` file will not be used. Note that globbing rules in `.eslintignore` follow those of `.gitignore`. + +## Using eslintIgnore in package.json + +If an `.eslintignore` file is not found and an alternate file is not specified, ESLint will look in package.json for an `eslintIgnore` key to check for files to ignore. + + { + "name": "mypackage", + "version": "0.0.1", + "eslintConfig": { + "env": { + "browser": true, + "node": true + } + }, + "eslintIgnore": ["hello.js", "world.js"] + } + +## Ignored File Warnings + +When you pass directories to ESLint, files and directories are silently ignored. If you pass a specific file to ESLint, then you will see a warning indicating that the file was skipped. For example, suppose you have an `.eslintignore` file that looks like this: + +```text +foo.js +``` + +And then you run: + + eslint foo.js + +You'll see this warning: + +```text +foo.js + 0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override. + +✖ 1 problem (0 errors, 1 warning) +``` + +This message occurs because ESLint is unsure if you wanted to actually lint the file or not. As the message indicates, you can use `--no-ignore` to omit using the ignore rules. + +Consider another scenario where you may want to run ESLint on a specific dot-file or dot-folder, but have forgotten to specifically allow those files in your `.eslintignore` file. You would run something like this: + + eslint .config/foo.js + +You would see this warning: + +```text +.config/foo.js + 0:0 warning File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!'") to override + +✖ 1 problem (0 errors, 1 warning) +``` + +This message occurs because, normally, this file would be ignored by ESLint's implicit ignore rules (as mentioned above). A negated ignore rule in your `.eslintignore` file would override the implicit rule and reinclude this file for linting. Additionally, in this specific case, `--no-ignore` could be used to lint the file as well. diff --git a/docs/user-guide/configuring/language-options.md b/docs/user-guide/configuring/language-options.md new file mode 100644 index 000000000000..eb3fe8a0afe6 --- /dev/null +++ b/docs/user-guide/configuring/language-options.md @@ -0,0 +1,214 @@ +# Language Options + + +* [Specifying Environments](#specifying-environments) +* [Specifying Globals](#specifying-globals) +* [Specifying Parser Options](#specifying-parser-options) + +## Specifying Environments + +An environment provides predefined global variables. The available environments are: + +* `browser` - browser global variables. +* `node` - Node.js global variables and Node.js scoping. +* `commonjs` - CommonJS global variables and CommonJS scoping (use this for browser-only code that uses Browserify/WebPack). +* `shared-node-browser` - Globals common to both Node.js and Browser. +* `es6` - enable all ECMAScript 6 features except for modules (this automatically sets the `ecmaVersion` parser option to 6). +* `es2017` - adds all ECMAScript 2017 globals and automatically sets the `ecmaVersion` parser option to 8. +* `es2020` - adds all ECMAScript 2020 globals and automatically sets the `ecmaVersion` parser option to 11. +* `es2021` - adds all ECMAScript 2021 globals and automatically sets the `ecmaVersion` parser option to 12. +* `worker` - web workers global variables. +* `amd` - defines `require()` and `define()` as global variables as per the [amd](https://github.com/amdjs/amdjs-api/wiki/AMD) spec. +* `mocha` - adds all of the Mocha testing global variables. +* `jasmine` - adds all of the Jasmine testing global variables for version 1.3 and 2.0. +* `jest` - Jest global variables. +* `phantomjs` - PhantomJS global variables. +* `protractor` - Protractor global variables. +* `qunit` - QUnit global variables. +* `jquery` - jQuery global variables. +* `prototypejs` - Prototype.js global variables. +* `shelljs` - ShellJS global variables. +* `meteor` - Meteor global variables. +* `mongo` - MongoDB global variables. +* `applescript` - AppleScript global variables. +* `nashorn` - Java 8 Nashorn global variables. +* `serviceworker` - Service Worker global variables. +* `atomtest` - Atom test helper globals. +* `embertest` - Ember test helper globals. +* `webextensions` - WebExtensions globals. +* `greasemonkey` - GreaseMonkey globals. + +These environments are not mutually exclusive, so you can define more than one at a time. + +Environments can be specified inside of a file, in configuration files or using the `--env` [command line](https://eslint.org/docs/user-guide/command-line-interface) flag. + +### Using configuration comments + +To specify environments using a comment inside of your JavaScript file, use the following format: + +```js +/* eslint-env node, mocha */ +``` + +This enables Node.js and Mocha environments. + +### Using configuration files + +To specify environments in a configuration file, use the `env` key and specify which environments you want to enable by setting each to `true`. For example, the following enables the browser and Node.js environments: + +```json +{ + "env": { + "browser": true, + "node": true + } +} +``` + +Or in a `package.json` file + +```json +{ + "name": "mypackage", + "version": "0.0.1", + "eslintConfig": { + "env": { + "browser": true, + "node": true + } + } +} +``` + +And in YAML: + +```yaml +--- + env: + browser: true + node: true +``` + +### Using a plugin + +If you want to use an environment from a plugin, be sure to specify the plugin name in the `plugins` array and then use the unprefixed plugin name, followed by a slash, followed by the environment name. For example: + +```json +{ + "plugins": ["example"], + "env": { + "example/custom": true + } +} +``` + +Or in a `package.json` file + +```json +{ + "name": "mypackage", + "version": "0.0.1", + "eslintConfig": { + "plugins": ["example"], + "env": { + "example/custom": true + } + } +} +``` + +## Specifying Globals + +Some of ESLint's core rules rely on knowledge of the global variables available to your code at runtime. Since these can vary greatly between different environments as well as be modified at runtime, ESLint makes no assumptions about what global variables exist in your execution environment. If you would like to use rules that require knowledge of what global variables are available, you can define global variables in your configuration file or by using configuration comments in your source code. + +### Using configuration comments + +To specify globals using a comment inside of your JavaScript file, use the following format: + +```js +/* global var1, var2 */ +``` + +This defines two global variables, `var1` and `var2`. If you want to optionally specify that these global variables can be written to (rather than only being read), then you can set each with a `"writable"` flag: + +```js +/* global var1:writable, var2:writable */ +``` + +### Using configuration files + +To configure global variables inside of a configuration file, set the `globals` configuration property to an object containing keys named for each of the global variables you want to use. For each global variable key, set the corresponding value equal to `"writable"` to allow the variable to be overwritten or `"readonly"` to disallow overwriting. For example: + +```json +{ + "globals": { + "var1": "writable", + "var2": "readonly" + } +} +``` + +And in YAML: + +```yaml +--- + globals: + var1: writable + var2: readonly +``` + +These examples allow `var1` to be overwritten in your code, but disallow it for `var2`. + +Globals can be disabled with the string `"off"`. For example, in an environment where most ES2015 globals are available but `Promise` is unavailable, you might use this config: + +```json +{ + "env": { + "es6": true + }, + "globals": { + "Promise": "off" + } +} +``` + +For historical reasons, the boolean value `false` and the string value `"readable"` are equivalent to `"readonly"`. Similarly, the boolean value `true` and the string value `"writeable"` are equivalent to `"writable"`. However, the use of older values is deprecated. + + +## Specifying Parser Options + +ESLint allows you to specify the JavaScript language options you want to support. By default, ESLint expects ECMAScript 5 syntax. You can override that setting to enable support for other ECMAScript versions as well as JSX by using parser options. + +Please note that supporting JSX syntax is not the same as supporting React. React applies specific semantics to JSX syntax that ESLint doesn't recognize. We recommend using [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) if you are using React and want React semantics. +By the same token, supporting ES6 syntax is not the same as supporting new ES6 globals (e.g., new types such as +`Set`). +For ES6 syntax, use `{ "parserOptions": { "ecmaVersion": 6 } }`; for new ES6 global variables, use `{ "env": +{ "es6": true } }`. `{ "env": { "es6": true } }` enables ES6 syntax automatically, but `{ "parserOptions": { "ecmaVersion": 6 } }` does not enable ES6 globals automatically. + +Parser options are set in your `.eslintrc.*` file by using the `parserOptions` property. The available options are: + +* `ecmaVersion` - set to 3, 5 (default), 6, 7, 8, 9, 10, 11, or 12 to specify the version of ECMAScript syntax you want to use. You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), or 2021 (same as 12) to use the year-based naming. +* `sourceType` - set to `"script"` (default) or `"module"` if your code is in ECMAScript modules. +* `ecmaFeatures` - an object indicating which additional language features you'd like to use: + * `globalReturn` - allow `return` statements in the global scope + * `impliedStrict` - enable global [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) (if `ecmaVersion` is 5 or greater) + * `jsx` - enable [JSX](https://facebook.github.io/jsx/) + +Here's an example `.eslintrc.json` file: + +```json +{ + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module", + "ecmaFeatures": { + "jsx": true + } + }, + "rules": { + "semi": "error" + } +} +``` + +Setting parser options helps ESLint determine what is a parsing error. All language options are `false` by default. diff --git a/docs/user-guide/configuring/plugins.md b/docs/user-guide/configuring/plugins.md new file mode 100644 index 000000000000..0235586c9808 --- /dev/null +++ b/docs/user-guide/configuring/plugins.md @@ -0,0 +1,177 @@ +# Plugins + + +* [Specifying Parser](#specifying-parser) +* [Specifying Processor](#specifying-processor) +* [Configuring Plugins](#configuring-plugins) + +## Specifying Parser + +By default, ESLint uses [Espree](https://github.com/eslint/espree) as its parser. You can optionally specify that a different parser should be used in your configuration file so long as the parser meets the following requirements: + +1. It must be a Node module loadable from the config file where the parser is used. Usually, this means you should install the parser package separately using npm. +1. It must conform to the [parser interface](https://eslint.org/docs/developer-guide/working-with-custom-parsers). + +Note that even with these compatibilities, there are no guarantees that an external parser will work correctly with ESLint and ESLint will not fix bugs related to incompatibilities with other parsers. + +To indicate the npm module to use as your parser, specify it using the `parser` option in your `.eslintrc` file. For example, the following specifies to use Esprima instead of Espree: + +```json +{ + "parser": "esprima", + "rules": { + "semi": "error" + } +} +``` + +The following parsers are compatible with ESLint: + +* [Esprima](https://www.npmjs.com/package/esprima) +* [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser) - A wrapper around the [Babel](https://babeljs.io) parser that makes it compatible with ESLint. +* [@typescript-eslint/parser](https://www.npmjs.com/package/@typescript-eslint/parser) - A parser that converts TypeScript into an ESTree-compatible form so it can be used in ESLint. + +Note when using a custom parser, the `parserOptions` configuration property is still required for ESLint to work properly with features not in ECMAScript 5 by default. Parsers are all passed `parserOptions` and may or may not use them to determine which features to enable. + +## Specifying Processor + +Plugins may provide processors. Processors can extract JavaScript code from other kinds of files, then let ESLint lint the JavaScript code or processors can convert JavaScript code in preprocessing for some purpose. + +To specify processors in a configuration file, use the `processor` key with the concatenated string of a plugin name and a processor name by a slash. For example, the following enables the processor `a-processor` that the plugin `a-plugin` provided: + +```json +{ + "plugins": ["a-plugin"], + "processor": "a-plugin/a-processor" +} +``` + +To specify processors for specific kinds of files, use the combination of the `overrides` key and the `processor` key. For example, the following uses the processor `a-plugin/markdown` for `*.md` files. + +```json +{ + "plugins": ["a-plugin"], + "overrides": [ + { + "files": ["*.md"], + "processor": "a-plugin/markdown" + } + ] +} +``` + +Processors may make named code blocks such as `0.js` and `1.js`. ESLint handles such a named code block as a child file of the original file. You can specify additional configurations for named code blocks in the `overrides` section of the config. For example, the following disables the `strict` rule for the named code blocks which end with `.js` in markdown files. + +```json +{ + "plugins": ["a-plugin"], + "overrides": [ + { + "files": ["*.md"], + "processor": "a-plugin/markdown" + }, + { + "files": ["**/*.md/*.js"], + "rules": { + "strict": "off" + } + } + ] +} +``` + +ESLint checks the file path of named code blocks then ignores those if any `overrides` entry didn't match the file path. Be sure to add an `overrides` entry if you want to lint named code blocks other than `*.js`. + +## Configuring Plugins + +ESLint supports the use of third-party plugins. Before using the plugin, you have to install it using npm. + +To configure plugins inside of a configuration file, use the `plugins` key, which contains a list of plugin names. The `eslint-plugin-` prefix can be omitted from the plugin name. + +```json +{ + "plugins": [ + "plugin1", + "eslint-plugin-plugin2" + ] +} +``` + +And in YAML: + +```yaml +--- + plugins: + - plugin1 + - eslint-plugin-plugin2 +``` + +**Notes:** + +1. Plugins are resolved relative to the config file. In other words, ESLint will load the plugin as a user would obtain by running `require('eslint-plugin-pluginname')` in the config file. +2. Plugins in the base configuration (loaded by `extends` setting) are relative to the derived config file. For example, if `./.eslintrc` has `extends: ["foo"]` and the `eslint-config-foo` has `plugins: ["bar"]`, ESLint finds the `eslint-plugin-bar` from `./node_modules/` (rather than `./node_modules/eslint-config-foo/node_modules/`) or ancestor directories. Thus every plugin in the config file and base configurations is resolved uniquely. + +### Naming convention + +#### Include a plugin + +The `eslint-plugin-` prefix can be omitted for non-scoped packages + +```js +{ + // ... + "plugins": [ + "jquery", // means eslint-plugin-jquery + ] + // ... +} +``` + +The same rule does apply to scoped packages: + +```js +{ + // ... + "plugins": [ + "@jquery/jquery", // means @jquery/eslint-plugin-jquery + "@foobar" // means @foobar/eslint-plugin + ] + // ... +} +``` + +#### Use a plugin + +When using rules, environments or configs defined by plugins, they must be referenced following the convention: + +* `eslint-plugin-foo` → `foo/a-rule` +* `@foo/eslint-plugin` → `@foo/a-config` +* `@foo/eslint-plugin-bar` → `@foo/bar/a-environment` + +For example: + +```js +{ + // ... + "plugins": [ + "jquery", // eslint-plugin-jquery + "@foo/foo", // @foo/eslint-plugin-foo + "@bar" // @bar/eslint-plugin + ], + "extends": [ + "plugin:@foo/foo/recommended", + "plugin:@bar/recommended" + ], + "rules": { + "jquery/a-rule": "error", + "@foo/foo/some-rule": "error", + "@bar/another-rule": "error" + }, + "env": { + "jquery/jquery": true, + "@foo/foo/env-foo": true, + "@bar/env-bar": true, + } + // ... +} +``` diff --git a/docs/user-guide/configuring/rules.md b/docs/user-guide/configuring/rules.md new file mode 100644 index 000000000000..2274b98ed022 --- /dev/null +++ b/docs/user-guide/configuring/rules.md @@ -0,0 +1,264 @@ +# Rules + + +* [Configuring Rules](#configuring-rules) +* [Disabling Rules](#disabling-rules) + +## Configuring Rules + +ESLint comes with a large number of built-in rules and you can add more rules through plugins. You can modify which rules your project uses either using configuration comments or configuration files. To change a rule setting, you must set the rule ID equal to one of these values: + +* `"off"` or `0` - turn the rule off +* `"warn"` or `1` - turn the rule on as a warning (doesn't affect exit code) +* `"error"` or `2` - turn the rule on as an error (exit code is 1 when triggered) + +### Using configuration comments + +To configure rules inside of a file using configuration comments, use a comment in the following format: + +```js +/* eslint eqeqeq: "off", curly: "error" */ +``` + +In this example, [`eqeqeq`](https://eslint.org/docs/rules/eqeqeq) is turned off and [`curly`](.https://eslint.org/docs/rules/curly) is turned on as an error. You can also use the numeric equivalent for the rule severity: + +```js +/* eslint eqeqeq: 0, curly: 2 */ +``` + +This example is the same as the last example, only it uses the numeric codes instead of the string values. The `eqeqeq` rule is off and the `curly` rule is set to be an error. + +If a rule has additional options, you can specify them using array literal syntax, such as: + +```js +/* eslint quotes: ["error", "double"], curly: 2 */ +``` + +This comment specifies the "double" option for the [`quotes`](https://eslint.org/docs/rules/quotes) rule. The first item in the array is always the rule severity (number or string). + +Configuration comments can include descriptions to explain why the comment is necessary. The description must occur after the configuration and is separated from the configuration by two or more consecutive `-` characters. For example: + +```js +/* eslint eqeqeq: "off", curly: "error" -- Here's a description about why this configuration is necessary. */ +``` + +```js +/* eslint eqeqeq: "off", curly: "error" + -------- + Here's a description about why this configuration is necessary. */ +``` + +```js +/* eslint eqeqeq: "off", curly: "error" + * -------- + * This will not work due to the line above starting with a '*' character. + */ +``` + +### Using configuration files + +To configure rules inside of a configuration file, use the `rules` key along with an error level and any options you want to use. For example: + +```json +{ + "rules": { + "eqeqeq": "off", + "curly": "error", + "quotes": ["error", "double"] + } +} +``` + +And in YAML: + +```yaml +--- +rules: + eqeqeq: off + curly: error + quotes: + - error + - double +``` + +To configure a rule which is defined within a plugin you have to prefix the rule ID with the plugin name and a `/`. For example: + +```json +{ + "plugins": [ + "plugin1" + ], + "rules": { + "eqeqeq": "off", + "curly": "error", + "quotes": ["error", "double"], + "plugin1/rule1": "error" + } +} +``` + +And in YAML: + +```yaml +--- +plugins: + - plugin1 +rules: + eqeqeq: 0 + curly: error + quotes: + - error + - "double" + plugin1/rule1: error +``` + +In these configuration files, the rule `plugin1/rule1` comes from the plugin named `plugin1`. You can also use this format with configuration comments, such as: + +```js +/* eslint "plugin1/rule1": "error" */ +``` + +**Note:** When specifying rules from plugins, make sure to omit `eslint-plugin-`. ESLint uses only the unprefixed name internally to locate rules. + +## Disabling Rules + +### Using configuration comments + +To temporarily disable rule warnings in your file, use block comments in the following format: + +```js +/* eslint-disable */ + +alert('foo'); + +/* eslint-enable */ +``` + +You can also disable or enable warnings for specific rules: + +```js +/* eslint-disable no-alert, no-console */ + +alert('foo'); +console.log('bar'); + +/* eslint-enable no-alert, no-console */ +``` + +To disable rule warnings in an entire file, put a `/* eslint-disable */` block comment at the top of the file: + +```js +/* eslint-disable */ + +alert('foo'); +``` + +You can also disable or enable specific rules for an entire file: + +```js +/* eslint-disable no-alert */ + +alert('foo'); +``` + +To disable all rules on a specific line, use a line or block comment in one of the following formats: + +```js +alert('foo'); // eslint-disable-line + +// eslint-disable-next-line +alert('foo'); + +/* eslint-disable-next-line */ +alert('foo'); + +alert('foo'); /* eslint-disable-line */ +``` + +To disable a specific rule on a specific line: + +```js +alert('foo'); // eslint-disable-line no-alert + +// eslint-disable-next-line no-alert +alert('foo'); + +alert('foo'); /* eslint-disable-line no-alert */ + +/* eslint-disable-next-line no-alert */ +alert('foo'); +``` + +To disable multiple rules on a specific line: + +```js +alert('foo'); // eslint-disable-line no-alert, quotes, semi + +// eslint-disable-next-line no-alert, quotes, semi +alert('foo'); + +alert('foo'); /* eslint-disable-line no-alert, quotes, semi */ + +/* eslint-disable-next-line no-alert, quotes, semi */ +alert('foo'); +``` + +All of the above methods also work for plugin rules. For example, to disable `eslint-plugin-example`'s `rule-name` rule, combine the plugin's name (`example`) and the rule's name (`rule-name`) into `example/rule-name`: + +```js +foo(); // eslint-disable-line example/rule-name +foo(); /* eslint-disable-line example/rule-name */ +``` + +Configuration comments can include descriptions to explain why the comment is necessary. The description must come after the configuration and needs to be separated from the configuration by two or more consecutive `-` characters. For example: + +```js +// eslint-disable-next-line no-console -- Here's a description about why this configuration is necessary. +console.log('hello'); +``` + +**Note:** Comments that disable warnings for a portion of a file tell ESLint not to report rule violations for the disabled code. ESLint still parses the entire file, however, so disabled code still needs to be syntactically valid JavaScript. + +### Using configuration files + +To disable rules inside of a configuration file for a group of files, use the `overrides` key along with a `files` key. For example: + +```json +{ + "rules": {...}, + "overrides": [ + { + "files": ["*-test.js","*.spec.js"], + "rules": { + "no-unused-expressions": "off" + } + } + ] +} +``` + +### Disabling Inline Comments + +To disable all inline config comments, use the `noInlineConfig` setting. For example: + +```json +{ + "rules": {...}, + "noInlineConfig": true +} +``` + +This setting is similar to [--no-inline-config](https://eslint.org/docs/user-guide/command-line-interface#--no-inline-config) CLI option. + +#### Report unused `eslint-disable` comments + +To report unused `eslint-disable` comments, use the `reportUnusedDisableDirectives` setting. For example: + +```json +{ + "rules": {...}, + "reportUnusedDisableDirectives": true +} +``` + +This setting is similar to [--report-unused-disable-directives](https://eslint.org/docs/user-guide/command-line-interface#--report-unused-disable-directives) CLI option, but doesn't fail linting (reports as `"warn"` severity). From 1c309ebca4a81a0faf397103dbc621019dea8c9c Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Tue, 26 Jan 2021 02:57:57 +0100 Subject: [PATCH 24/28] Update: fix no-invalid-regexp false negatives with no flags specified (#14018) --- lib/rules/no-invalid-regexp.js | 43 +++++++++++++++++---- tests/lib/rules/no-invalid-regexp.js | 56 ++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 8 deletions(-) diff --git a/lib/rules/no-invalid-regexp.js b/lib/rules/no-invalid-regexp.js index 6136ebb9e0be..94ad5ba6d5c2 100644 --- a/lib/rules/no-invalid-regexp.js +++ b/lib/rules/no-invalid-regexp.js @@ -69,6 +69,28 @@ module.exports = { return node && node.type === "Literal" && typeof node.value === "string"; } + /** + * Gets flags of a regular expression created by the given `RegExp()` or `new RegExp()` call + * Examples: + * new RegExp(".") // => "" + * new RegExp(".", "gu") // => "gu" + * new RegExp(".", flags) // => null + * @param {ASTNode} node `CallExpression` or `NewExpression` node + * @returns {string|null} flags if they can be determined, `null` otherwise + * @private + */ + function getFlags(node) { + if (node.arguments.length < 2) { + return ""; + } + + if (isString(node.arguments[1])) { + return node.arguments[1].value; + } + + return null; + } + /** * Check syntax error in a given pattern. * @param {string} pattern The RegExp pattern to validate. @@ -104,18 +126,23 @@ module.exports = { return; } const pattern = node.arguments[0].value; - let flags = isString(node.arguments[1]) ? node.arguments[1].value : ""; + let flags = getFlags(node); - if (allowedFlags) { + if (flags && allowedFlags) { flags = flags.replace(allowedFlags, ""); } - // If flags are unknown, check both are errored or not. - const message = validateRegExpFlags(flags) || ( - flags - ? validateRegExpPattern(pattern, flags.indexOf("u") !== -1) - : validateRegExpPattern(pattern, true) && validateRegExpPattern(pattern, false) - ); + const message = + ( + flags && validateRegExpFlags(flags) + ) || + ( + + // If flags are unknown, report the regex only if its pattern is invalid both with and without the "u" flag + flags === null + ? validateRegExpPattern(pattern, true) && validateRegExpPattern(pattern, false) + : validateRegExpPattern(pattern, flags.includes("u")) + ); if (message) { context.report({ diff --git a/tests/lib/rules/no-invalid-regexp.js b/tests/lib/rules/no-invalid-regexp.js index 485ce1e41fd3..6484db816db5 100644 --- a/tests/lib/rules/no-invalid-regexp.js +++ b/tests/lib/rules/no-invalid-regexp.js @@ -39,6 +39,20 @@ ruleTester.run("no-invalid-regexp", rule, { "new RegExp('(?b)\\k', 'u')", "new RegExp('\\\\p{Letter}', 'u')", + // unknown flags + "RegExp('{', flags)", // valid without the "u" flag + "new RegExp('{', flags)", // valid without the "u" flag + "RegExp('\\\\u{0}*', flags)", // valid with the "u" flag + "new RegExp('\\\\u{0}*', flags)", // valid with the "u" flag + { + code: "RegExp('{', flags)", // valid without the "u" flag + options: [{ allowConstructorFlags: ["u"] }] + }, + { + code: "RegExp('\\\\u{0}*', flags)", // valid with the "u" flag + options: [{ allowConstructorFlags: ["a"] }] + }, + // ES2020 "new RegExp('(?<\\\\ud835\\\\udc9c>.)', 'g')", "new RegExp('(?<\\\\u{1d49c}>.)', 'g')", @@ -165,6 +179,48 @@ ruleTester.run("no-invalid-regexp", rule, { type: "NewExpression" }] }, + { + code: String.raw`RegExp('\\u{0}*');`, + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid regular expression: /\\u{0}*/: Nothing to repeat" }, + type: "CallExpression" + }] + }, + { + code: String.raw`new RegExp('\\u{0}*');`, + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid regular expression: /\\u{0}*/: Nothing to repeat" }, + type: "NewExpression" + }] + }, + { + code: String.raw`new RegExp('\\u{0}*', '');`, + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid regular expression: /\\u{0}*/: Nothing to repeat" }, + type: "NewExpression" + }] + }, + { + code: String.raw`new RegExp('\\u{0}*', 'a');`, + options: [{ allowConstructorFlags: ["a"] }], + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid regular expression: /\\u{0}*/: Nothing to repeat" }, + type: "NewExpression" + }] + }, + { + code: String.raw`RegExp('\\u{0}*');`, + options: [{ allowConstructorFlags: ["a"] }], + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid regular expression: /\\u{0}*/: Nothing to repeat" }, + type: "CallExpression" + }] + }, // https://github.com/eslint/eslint/issues/10861 { From 8561c2116ef89e53ebffb750066f1b00a4acdb76 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Wed, 27 Jan 2021 17:29:23 +0100 Subject: [PATCH 25/28] Docs: fix broken links in configuring/README.md (#14046) --- docs/user-guide/configuring/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/user-guide/configuring/README.md b/docs/user-guide/configuring/README.md index 0aeaffdd28c8..2d22421e0c38 100644 --- a/docs/user-guide/configuring/README.md +++ b/docs/user-guide/configuring/README.md @@ -3,7 +3,7 @@ ESLint is designed to be flexible and configurable for your use case. You can turn off every rule and run only with basic syntax validation or mix and match the bundled rules and your custom rules to fit the needs of your project. There are two primary ways to configure ESLint: 1. **Configuration Comments** - use JavaScript comments to embed configuration information directly into a file. -1. **Configuration Files** - use a JavaScript, JSON, or YAML file to specify configuration information for an entire directory and all of its subdirectories. This can be in the form of an [`.eslintrc.*`](./configuring-files#configuration-file-formats) file or an `eslintConfig` field in a [`package.json`](https://docs.npmjs.com/files/package.json) file, both of which ESLint will look for and read automatically, or you can specify a configuration file on the [command line](https://eslint.org/docs/user-guide/command-line-interface). +1. **Configuration Files** - use a JavaScript, JSON, or YAML file to specify configuration information for an entire directory and all of its subdirectories. This can be in the form of an [`.eslintrc.*`](./configuration-files.md#configuration-file-formats) file or an `eslintConfig` field in a [`package.json`](https://docs.npmjs.com/files/package.json) file, both of which ESLint will look for and read automatically, or you can specify a configuration file on the [command line](https://eslint.org/docs/user-guide/command-line-interface). Here are some of the options that you can configure in ESLint: @@ -22,9 +22,9 @@ All of these options give you fine-grained control over how ESLint treats your c * [Using Configuration Files](./configuration-files.md#using-configuration-files) * [Adding Shared Settings](./configuration-files.md#adding-shared-settings) * [Cascading and Hierarchy](./configuration-files.md#cascading-and-hierarchy) -* [Extending Configuration Files](./configuring-files.md#extending-configuration-files) -* [Configuration Based on Glob Patterns](./configuration-files.md#configuration-based-on-glon-patterns) -* [Personal Configuration Files](./configuration-files.md#personal-configuration-files) +* [Extending Configuration Files](./configuration-files.md#extending-configuration-files) +* [Configuration Based on Glob Patterns](./configuration-files.md#configuration-based-on-glob-patterns) +* [Personal Configuration Files](./configuration-files.md#personal-configuration-files-deprecated) [**Language Options**](language-options.md) @@ -48,5 +48,5 @@ All of these options give you fine-grained control over how ESLint treats your c * [`ignorePatterns` in Config Files](./ignoring-code.md#ignorepatterns-in-config-files) * [The `.eslintignore` File](./ignoring-code.md#the-eslintignore-file) * [Using an Alternate File](./ignoring-code.md#using-an-alternate-file) -* [Using eslintIgnore in package.json](./ignoring-code.md#using-eslintignore-in-package.json) +* [Using eslintIgnore in package.json](./ignoring-code.md#using-eslintignore-in-packagejson) * [Ignored File Warnings](./ignoring-code.md#ignored-file-warnings) From 3fc4fa485ca9ccd5e16dbc7e53ba31452d22dc4a Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Wed, 27 Jan 2021 17:30:01 +0100 Subject: [PATCH 26/28] Docs: update configuring links (#14038) * Docs: update configuring links * fix link * update link in CLI --env docs --- docs/developer-guide/working-with-plugins.md | 4 ++-- .../developer-guide/working-with-rules-deprecated.md | 8 ++++---- docs/developer-guide/working-with-rules.md | 12 ++++++------ docs/rules/no-undef.md | 2 +- docs/rules/strict.md | 8 ++++---- docs/rules/yield-star-spacing.md | 3 --- docs/user-guide/README.md | 2 +- docs/user-guide/command-line-interface.md | 6 +++--- docs/user-guide/getting-started.md | 4 ++-- 9 files changed, 23 insertions(+), 26 deletions(-) diff --git a/docs/developer-guide/working-with-plugins.md b/docs/developer-guide/working-with-plugins.md index 521b9eb5aacf..3809e3700d07 100644 --- a/docs/developer-guide/working-with-plugins.md +++ b/docs/developer-guide/working-with-plugins.md @@ -136,7 +136,7 @@ overrides: processor: a-plugin/markdown ``` -See [Specifying Processor](../user-guide/configuring.md#specifying-processor) for details. +See [Specifying Processor](../user-guide/configuring/plugins.md#specifying-processor) for details. #### File Extension-named Processor @@ -197,7 +197,7 @@ If the example plugin above were called `eslint-plugin-myPlugin`, the `myConfig` ``` -**Note:** Please note that configuration will not enable any of the plugin's rules by default, and instead should be treated as a standalone config. This means that you must specify your plugin name in the `plugins` array as well as any rules you want to enable that are part of the plugin. Any plugin rules must be prefixed with the short or long plugin name. See [Configuring Plugins](../user-guide/configuring.md#configuring-plugins) for more information. +**Note:** Please note that configuration will not enable any of the plugin's rules by default, and instead should be treated as a standalone config. This means that you must specify your plugin name in the `plugins` array as well as any rules you want to enable that are part of the plugin. Any plugin rules must be prefixed with the short or long plugin name. See [Configuring Plugins](../user-guide/configuring/plugins.md#configuring-plugins) for more information. ### Peer Dependency diff --git a/docs/developer-guide/working-with-rules-deprecated.md b/docs/developer-guide/working-with-rules-deprecated.md index a80f3316405b..fdd4f9d3e141 100644 --- a/docs/developer-guide/working-with-rules-deprecated.md +++ b/docs/developer-guide/working-with-rules-deprecated.md @@ -32,7 +32,7 @@ module.exports.schema = []; // no options ## Rule Basics -`schema` (array) specifies the [options](#options-schemas) so ESLint can prevent invalid [rule configurations](../user-guide/configuring.md#configuring-rules) +`schema` (array) specifies the [options](#options-schemas) so ESLint can prevent invalid [rule configurations](../user-guide/configuring/rules.md#configuring-rules) `create` (function) returns an object with methods that ESLint calls to "visit" nodes while traversing the abstract syntax tree (AST as defined by [ESTree](https://github.com/estree/estree)) of JavaScript code: @@ -72,7 +72,7 @@ module.exports = function(context) { The `context` object contains additional functionality that is helpful for rules to do their jobs. As the name implies, the `context` object contains information that is relevant to the context of the rule. The `context` object has the following properties: -* `parserOptions` - the parser options configured for this run (more details [here](../user-guide/configuring.md#specifying-parser-options)). +* `parserOptions` - the parser options configured for this run (more details [here](../user-guide/configuring/language-options.md#specifying-parser-options)). * `id` - the rule ID. * `options` - an array of rule options. * `settings` - the `settings` from configuration. @@ -476,7 +476,7 @@ valid: [ ] ``` -The options available and the expected syntax for `parserOptions` is the same as those used in [configuration](../user-guide/configuring.md#specifying-parser-options). +The options available and the expected syntax for `parserOptions` is the same as those used in [configuration](../user-guide/configuring/language-options.md#specifying-parser-options). ### Write Several Tests @@ -571,5 +571,5 @@ The thing that makes ESLint different from other linters is the ability to defin Runtime rules are written in the same format as all other rules. Create your rule as you would any other and then follow these steps: 1. Place all of your runtime rules in the same directory (i.e., `eslint_rules`). -2. Create a [configuration file](../user-guide/configuring.md) and specify your rule ID error level under the `rules` key. Your rule will not run unless it has a value of `1` or `2` in the configuration file. +2. Create a [configuration file](../user-guide/configuring/) and specify your rule ID error level under the `rules` key. Your rule will not run unless it has a value of `1` or `2` in the configuration file. 3. Run the [command line interface](../user-guide/command-line-interface.md) using the `--rulesdir` option to specify the location of your runtime rules. diff --git a/docs/developer-guide/working-with-rules.md b/docs/developer-guide/working-with-rules.md index 62e91ebae914..95ff18ea6471 100644 --- a/docs/developer-guide/working-with-rules.md +++ b/docs/developer-guide/working-with-rules.md @@ -60,7 +60,7 @@ The source file for a rule exports an object with the following properties. * `description` (string) provides the short description of the rule in the [rules index](../rules/) * `category` (string) specifies the heading under which the rule is listed in the [rules index](../rules/) - * `recommended` (boolean) is whether the `"extends": "eslint:recommended"` property in a [configuration file](../user-guide/configuring.md#extending-configuration-files) enables the rule + * `recommended` (boolean) is whether the `"extends": "eslint:recommended"` property in a [configuration file](../user-guide/configuring/configuration-files.md#extending-configuration-files) enables the rule * `url` (string) specifies the URL at which the full documentation can be accessed * `suggestion` (boolean) specifies whether rules can return suggestions (defaults to false if omitted) @@ -70,7 +70,7 @@ The source file for a rule exports an object with the following properties. **Important:** the `fixable` property is mandatory for fixable rules. If this property isn't specified, ESLint will throw an error whenever the rule attempts to produce a fix. Omit the `fixable` property if the rule is not fixable. -* `schema` (array) specifies the [options](#options-schemas) so ESLint can prevent invalid [rule configurations](../user-guide/configuring.md#configuring-rules) +* `schema` (array) specifies the [options](#options-schemas) so ESLint can prevent invalid [rule configurations](../user-guide/configuring/rules.md#configuring-rules) * `deprecated` (boolean) indicates whether the rule has been deprecated. You may omit the `deprecated` property if the rule has not been deprecated. @@ -117,10 +117,10 @@ module.exports = { The `context` object contains additional functionality that is helpful for rules to do their jobs. As the name implies, the `context` object contains information that is relevant to the context of the rule. The `context` object has the following properties: -* `parserOptions` - the parser options configured for this run (more details [here](../user-guide/configuring.md#specifying-parser-options)). +* `parserOptions` - the parser options configured for this run (more details [here](../user-guide/configuring/language-options.md#specifying-parser-options)). * `id` - the rule ID. -* `options` - an array of the [configured options](/docs/user-guide/configuring.md#configuring-rules) for this rule. This array does not include the rule severity. For more information, see [here](#contextoptions). -* `settings` - the [shared settings](/docs/user-guide/configuring.md#adding-shared-settings) from configuration. +* `options` - an array of the [configured options](/docs/user-guide/configuring/rules.md#configuring-rules) for this rule. This array does not include the rule severity. For more information, see [here](#contextoptions). +* `settings` - the [shared settings](/docs/user-guide/configuring/configuration-files.md#adding-shared-settings) from configuration. * `parserPath` - the name of the `parser` from configuration. * `parserServices` - an object containing parser-provided services for rules. The default parser does not provide any services. However, if a rule is intended to be used with a custom parser, it could use `parserServices` to access anything provided by that parser. (For example, a TypeScript parser could provide the ability to get the computed type of a given node.) @@ -737,5 +737,5 @@ The thing that makes ESLint different from other linters is the ability to defin Runtime rules are written in the same format as all other rules. Create your rule as you would any other and then follow these steps: 1. Place all of your runtime rules in the same directory (e.g., `eslint_rules`). -2. Create a [configuration file](../user-guide/configuring.md) and specify your rule ID error level under the `rules` key. Your rule will not run unless it has a value of `"warn"` or `"error"` in the configuration file. +2. Create a [configuration file](../user-guide/configuring/) and specify your rule ID error level under the `rules` key. Your rule will not run unless it has a value of `"warn"` or `"error"` in the configuration file. 3. Run the [command line interface](../user-guide/command-line-interface.md) using the `--rulesdir` option to specify the location of your runtime rules. diff --git a/docs/rules/no-undef.md b/docs/rules/no-undef.md index faaf978cc8dc..a7de8052357d 100644 --- a/docs/rules/no-undef.md +++ b/docs/rules/no-undef.md @@ -68,7 +68,7 @@ if(typeof a === "string"){} ## Environments -For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in [Specifying Environments](../user-guide/configuring.md#specifying-environments). A few examples are given below. +For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in [Specifying Environments](../user-guide/configuring/language-options.md#specifying-environments). A few examples are given below. ### browser diff --git a/docs/rules/strict.md b/docs/rules/strict.md index 9df292b6e0de..a6d87c20ac1e 100644 --- a/docs/rules/strict.md +++ b/docs/rules/strict.md @@ -42,7 +42,7 @@ In **ECMAScript** modules, which always have strict mode semantics, the directiv This rule requires or disallows strict mode directives. -This rule disallows strict mode directives, no matter which option is specified, if ESLint configuration specifies either of the following as [parser options](/docs/user-guide/configuring.md#specifying-parser-options): +This rule disallows strict mode directives, no matter which option is specified, if ESLint configuration specifies either of the following as [parser options](/docs/user-guide/configuring/language-options.md#specifying-parser-options): * `"sourceType": "module"` that is, files are **ECMAScript** modules * `"impliedStrict": true` property in the `ecmaFeatures` object @@ -66,8 +66,8 @@ This rule has a string option: The `"safe"` option corresponds to the `"global"` option if ESLint considers a file to be a **Node.js** or **CommonJS** module because the configuration specifies either of the following: -* `node` or `commonjs` [environments](/docs/user-guide/configuring.md#specifying-environments) -* `"globalReturn": true` property in the `ecmaFeatures` object of [parser options](/docs/user-guide/configuring.md#specifying-parser-options) +* `node` or `commonjs` [environments](/docs/user-guide/configuring/language-options.md#specifying-environments) +* `"globalReturn": true` property in the `ecmaFeatures` object of [parser options](/docs/user-guide/configuring/language-options.md#specifying-parser-options) Otherwise the `"safe"` option corresponds to the `"function"` option. Note that if `"globalReturn": false` is explicitly specified in the configuration, the `"safe"` option will correspond to the `"function"` option regardless of the specified environment. @@ -269,4 +269,4 @@ function foo() { ## When Not To Use It -In a codebase that has both strict and non-strict code, either turn this rule off, or [selectively disable it](/docs/user-guide/configuring.md) where necessary. For example, functions referencing `arguments.callee` are invalid in strict mode. A [full list of strict mode differences](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode/Transitioning_to_strict_mode#Differences_from_non-strict_to_strict) is available on MDN. +In a codebase that has both strict and non-strict code, either turn this rule off, or [selectively disable it](/docs/user-guide/configuring/rules.md#disabling-rules) where necessary. For example, functions referencing `arguments.callee` are invalid in strict mode. A [full list of strict mode differences](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode/Transitioning_to_strict_mode#Differences_from_non-strict_to_strict) is available on MDN. diff --git a/docs/rules/yield-star-spacing.md b/docs/rules/yield-star-spacing.md index 8868e99fdb73..f8c27e6feba4 100644 --- a/docs/rules/yield-star-spacing.md +++ b/docs/rules/yield-star-spacing.md @@ -4,9 +4,6 @@ This rule enforces spacing around the `*` in `yield*` expressions. -To use this rule you either need to [use the `es6` environment](../user-guide/configuring.md#specifying-environments) or -[set `ecmaVersion` to `6` in `parserOptions`](../user-guide/configuring.md#specifying-parser-options). - ## Options The rule takes one option, an object, which has two keys `before` and `after` having boolean values `true` or `false`. diff --git a/docs/user-guide/README.md b/docs/user-guide/README.md index 7339bfe08d1a..1fcb0dfc12e4 100644 --- a/docs/user-guide/README.md +++ b/docs/user-guide/README.md @@ -10,7 +10,7 @@ Want to skip ahead and just start using ESLint? This section gives a high-level ESLint has a lot of rules that you can configure to fine-tune it to your project. This section is an exhaustive list of every rule and link to each rule's documentation. -## [Configuring](configuring.md) +## [Configuring](configuring/) Once you've got ESLint running, you'll probably want to adjust the configuration to better suit your project. This section explains all the different ways you can configure ESLint. diff --git a/docs/user-guide/command-line-interface.md b/docs/user-guide/command-line-interface.md index b8f10497a364..64afa0b01db6 100644 --- a/docs/user-guide/command-line-interface.md +++ b/docs/user-guide/command-line-interface.md @@ -118,7 +118,7 @@ If `.eslintrc.*` and/or `package.json` files are also used for configuration (i. #### `--env` -This option enables specific environments. Details about the global variables defined by each environment are available on the [configuration](configuring.md) documentation. This option only enables environments; it does not disable environments set in other configuration files. To specify multiple environments, separate them using commas, or use the option multiple times. +This option enables specific environments. Details about the global variables defined by each environment are available on the [Specifying Environments](configuring/language-options.md#specifying-environments) documentation. This option only enables environments; it does not disable environments set in other configuration files. To specify multiple environments, separate them using commas, or use the option multiple times. Examples: @@ -275,7 +275,7 @@ Example: #### `--ignore-pattern` -This option allows you to specify patterns of files to ignore (in addition to those in `.eslintignore`). You can repeat the option to provide multiple patterns. The supported syntax is the same as for `.eslintignore` [files](./configuring.md#.eslintignore), which use the same patterns as the `.gitignore` [specification](https://git-scm.com/docs/gitignore). You should quote your patterns in order to avoid shell interpretation of glob patterns. +This option allows you to specify patterns of files to ignore (in addition to those in `.eslintignore`). You can repeat the option to provide multiple patterns. The supported syntax is the same as for `.eslintignore` [files](configuring/ignoring-code.md#the-eslintignore-file), which use the same patterns as the `.gitignore` [specification](https://git-scm.com/docs/gitignore). You should quote your patterns in order to avoid shell interpretation of glob patterns. Example: @@ -483,7 +483,7 @@ ESLint supports `.eslintignore` files to exclude files from the linting process temp.js **/vendor/*.js -A more detailed breakdown of supported patterns and directories ESLint ignores by default can be found in [Configuring ESLint](configuring.md#ignoring-files-and-directories). +A more detailed breakdown of supported patterns and directories ESLint ignores by default can be found in [Ignoring Code](configuring/ignoring-code.md). ## Exit codes diff --git a/docs/user-guide/getting-started.md b/docs/user-guide/getting-started.md index 93fef31e0611..3b28a91a2f6e 100644 --- a/docs/user-guide/getting-started.md +++ b/docs/user-guide/getting-started.md @@ -65,7 +65,7 @@ The names `"semi"` and `"quotes"` are the names of [rules](/docs/rules) in ESLin * `"warn"` or `1` - turn the rule on as a warning (doesn't affect exit code) * `"error"` or `2` - turn the rule on as an error (exit code will be 1) -The three error levels allow you fine-grained control over how ESLint applies rules (for more configuration options and details, see the [configuration docs](configuring.md)). +The three error levels allow you fine-grained control over how ESLint applies rules (for more configuration options and details, see the [configuration docs](configuring/)). Your `.eslintrc.{js,yml,json}` configuration file will also include the line: @@ -81,7 +81,7 @@ Because of this line, all of the rules marked "(recommended)" on the [rules page ## Next Steps -* Learn about [advanced configuration](configuring.md) of ESLint. +* Learn about [advanced configuration](configuring/) of ESLint. * Get familiar with the [command line options](command-line-interface.md). * Explore [ESLint integrations](integrations.md) into other tools like editors, build systems, and more. * Can't find just the right rule? Make your own [custom rule](/docs/developer-guide/working-with-rules.md). From 46e836d46442d2ec756038a2e12ba19b74394dbd Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Wed, 27 Jan 2021 13:11:49 -0500 Subject: [PATCH 27/28] Sponsors: Sync README with website --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b998a63a6868..aab94acb7fe6 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,7 @@ The following companies, organizations, and individuals support ESLint's ongoing

Platinum Sponsors

Automattic

Gold Sponsors

Chrome's Web Framework & Tools Performance Fund Shopify Salesforce Airbnb Microsoft FOSS Fund Sponsorships

Silver Sponsors

-

Liftoff AMP Project

Bronze Sponsors

+

Retool Liftoff AMP Project

Bronze Sponsors

Streamat The Standard Daily Writers Per Hour February 2021 calendar Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

From e0b05c704f3ce6f549d14718236d22fe49fcb611 Mon Sep 17 00:00:00 2001 From: armin yahya Date: Fri, 29 Jan 2021 16:24:49 +0330 Subject: [PATCH 28/28] Docs: add a correct example to no-unsafe-optional-chaining (refs #14029) (#14050) --- docs/rules/no-unsafe-optional-chaining.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/rules/no-unsafe-optional-chaining.md b/docs/rules/no-unsafe-optional-chaining.md index 48296aac2be9..49fa415e0c0e 100644 --- a/docs/rules/no-unsafe-optional-chaining.md +++ b/docs/rules/no-unsafe-optional-chaining.md @@ -92,6 +92,8 @@ obj?.foo(); obj?.foo.bar; +obj.foo?.bar; + foo?.()?.bar; (obj?.foo ?? bar)`template`;