From c5f3d7dab303468ae33ccfec61bba75a816f832c Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Thu, 19 Dec 2024 08:08:59 +0000 Subject: [PATCH 01/51] docs: Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 326c6121e810..9c5c60e93ef5 100644 --- a/README.md +++ b/README.md @@ -299,8 +299,8 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).

Platinum Sponsors

Automattic Airbnb

Gold Sponsors

trunk.io

Silver Sponsors

-

SERP Triumph JetBrains Liftoff American Express Workleap

Bronze Sponsors

-

Cybozu Syntax WordHint Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

+

SERP Triumph JetBrains Liftoff American Express Workleap

Bronze Sponsors

+

Cybozu Syntax WordHint Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

Technology Sponsors

Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.

Netlify Algolia 1Password

From f76d05da6e745adbea574c32b334638c7ba3c0c8 Mon Sep 17 00:00:00 2001 From: Amaresh S M Date: Fri, 20 Dec 2024 11:55:12 +0530 Subject: [PATCH 02/51] docs: Refactor search result handling with better event listener cleanup (#19252) --- docs/src/assets/js/search.js | 82 ++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 18 deletions(-) diff --git a/docs/src/assets/js/search.js b/docs/src/assets/js/search.js index a4668efc3ddf..a7d0225c3011 100644 --- a/docs/src/assets/js/search.js +++ b/docs/src/assets/js/search.js @@ -41,13 +41,36 @@ function fetchSearchResults(query) { } /** - * Removes any current search results from the display. - * @returns {void} + * Clears the search results from the display. + * If the removeEventListener flag is true, removes the click event listener from the document. + * @param {boolean} [removeEventListener=false] - Optional flag to indicate if the click event listener should be removed. Default is false. + * @returns {void} - This function doesn't return anything. */ -function clearSearchResults() { - while (resultsElement.firstChild) { - resultsElement.removeChild(resultsElement.firstChild); +function clearSearchResults(removeEventListener = false) { + resultsElement.innerHTML = ""; + if (removeEventListener && document.clickEventAdded) { + document.removeEventListener('click', handleDocumentClick); + document.clickEventAdded = false; } +} + +/** + * Displays a "No results found" message in both the live region and results display area. + * This is typically used when no matching results are found in the search. + * @returns {void} - This function doesn't return anything. + */ +function showNoResults() { + resultsLiveRegion.innerHTML = "No results found."; + resultsElement.innerHTML = "No results found."; + resultsElement.setAttribute('data-results', 'false'); +} + +/** + * Clears any "No results found" message from the live region and results display area. + * @returns {void} - This function doesn't return anything. + */ +function clearNoResults() { + resultsLiveRegion.innerHTML = ""; resultsElement.innerHTML = ""; } @@ -81,9 +104,7 @@ function displaySearchResults(results) { } } else { - resultsLiveRegion.innerHTML = "No results found."; - resultsElement.innerHTML = "No results found."; - resultsElement.setAttribute('data-results', 'false'); + showNoResults(); } } @@ -125,12 +146,33 @@ function debounce(callback, delay) { } } +/** + * Debounced function to fetch search results after 300ms of inactivity. + * Calls `fetchSearchResults` to retrieve data and `displaySearchResults` to show them. + * If an error occurs, clears the search results. + * @param {string} query - The search query. + * @returns {void} - No return value. + * @see debounce - Limits the number of requests during rapid typing. + */ const debouncedFetchSearchResults = debounce((query) => { fetchSearchResults(query) .then(displaySearchResults) - .catch(clearSearchResults); + .catch(() => { clearSearchResults(true) }); }, 300); + +/** + * Handles the document click event to clear search results if the user clicks outside of the search input or results element. + * @param {MouseEvent} e - The event object representing the click event. + * @returns {void} - This function does not return any value. It directly interacts with the UI by clearing search results. + */ +const handleDocumentClick = (e) => { + if (e.target !== resultsElement && e.target !== searchInput) { + clearSearchResults(true); + } +} + + //----------------------------------------------------------------------------- // Event Handlers //----------------------------------------------------------------------------- @@ -146,14 +188,13 @@ if (searchInput) else searchClearBtn.setAttribute('hidden', ''); if (query.length > 2) { - debouncedFetchSearchResults(query); - - document.addEventListener('click', function (e) { - if (e.target !== resultsElement) clearSearchResults(); - }); + if (!document.clickEventAdded) { + document.addEventListener('click', handleDocumentClick); + document.clickEventAdded = true; + } } else { - clearSearchResults(); + clearSearchResults(true); } searchQuery = query @@ -165,7 +206,7 @@ if (searchClearBtn) searchClearBtn.addEventListener('click', function (e) { searchInput.value = ''; searchInput.focus(); - clearSearchResults(); + clearSearchResults(true); searchClearBtn.setAttribute('hidden', ''); }); @@ -173,11 +214,16 @@ document.addEventListener('keydown', function (e) { const searchResults = Array.from(document.querySelectorAll('.search-results__item')); - if (e.key === 'Escape') { + if (e.key === "Escape") { e.preventDefault(); if (searchResults.length) { - clearSearchResults(); + clearSearchResults(true); searchInput.focus(); + } else if ( + document.activeElement === searchInput + ) { + clearNoResults(); + searchInput.blur(); } } From 995b49231a3f0ccddb941663175ce4fead9c9432 Mon Sep 17 00:00:00 2001 From: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:24:06 +0530 Subject: [PATCH 03/51] docs: fix inconsistent divider in rule categories box (#19249) * docs: fix inconsistent divider in rule categories * fix styling errors --------- Co-authored-by: Nitin Kumar --- docs/src/assets/scss/components/rules.scss | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/src/assets/scss/components/rules.scss b/docs/src/assets/scss/components/rules.scss index 55c983520089..55ba6995bbac 100644 --- a/docs/src/assets/scss/components/rules.scss +++ b/docs/src/assets/scss/components/rules.scss @@ -17,20 +17,19 @@ &:not(:first-child)::after { content: ""; display: block; - padding: 1px; border-left: 1px solid var(--divider-color); left: 0; } } - @media screen and (min-width: 768px) and (max-width: 1023px), screen and (min-width: 1440px) { + @media screen and (min-width: 768px) and (max-width: 799px), screen and (min-width: 854px) and (max-width: 1023px), screen and (min-width: 1256px) { &:not(:first-child)::after { height: 70%; position: absolute; } } - @media screen and (min-width: 1024px) and (max-width: 1439px) { + @media screen and (min-width: 800px) and (max-width: 853px), screen and (min-width: 1024px) and (max-width: 1255px) { &:nth-child(2)::after { height: 70%; position: absolute; From bbb9b46c20662019e98df85dedde9b68719afa1f Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Fri, 20 Dec 2024 08:08:56 +0000 Subject: [PATCH 04/51] docs: Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c5c60e93ef5..451895aac545 100644 --- a/README.md +++ b/README.md @@ -299,8 +299,8 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).

Platinum Sponsors

Automattic Airbnb

Gold Sponsors

trunk.io

Silver Sponsors

-

SERP Triumph JetBrains Liftoff American Express Workleap

Bronze Sponsors

-

Cybozu Syntax WordHint Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

+

SERP Triumph JetBrains Liftoff American Express Workleap

Bronze Sponsors

+

Cybozu Syntax WordHint Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

Technology Sponsors

Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.

Netlify Algolia 1Password

From 6fe0e7244a7e88458ea7fdcebc43794c03793c4b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 20 Dec 2024 19:42:08 +0100 Subject: [PATCH 05/51] chore: update dependency @eslint/json to ^0.9.0 (#19263) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c4d3058a9c34..bfc38a42c667 100644 --- a/package.json +++ b/package.json @@ -136,7 +136,7 @@ "@arethetypeswrong/cli": "^0.17.0", "@babel/core": "^7.4.3", "@babel/preset-env": "^7.4.3", - "@eslint/json": "^0.8.0", + "@eslint/json": "^0.9.0", "@trunkio/launcher": "^1.3.0", "@types/node": "^20.11.5", "@typescript-eslint/parser": "^8.4.0", From ac8b3c4ca9f7b84f84356137cf23a1ba6dfecf11 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Sat, 21 Dec 2024 04:04:39 +0100 Subject: [PATCH 06/51] docs: fix description of `overrideConfigFile` option (#19262) --- docs/src/integrate/nodejs-api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/integrate/nodejs-api.md b/docs/src/integrate/nodejs-api.md index 8f819a3c5c02..b645ac7daaac 100644 --- a/docs/src/integrate/nodejs-api.md +++ b/docs/src/integrate/nodejs-api.md @@ -144,8 +144,8 @@ The `ESLint` constructor takes an `options` object. If you omit the `options` ob Default is `null`. [Configuration object], extended by all configurations used with this instance. You can use this option to define the default settings that will be used if your configuration files don't configure it. * `options.overrideConfig` (`ConfigData | ConfigData[] | null`)
Default is `null`. [Configuration object], overrides all configurations used with this instance. You can use this option to define the settings that will be used even if your configuration files configure it. -* `options.overrideConfigFile` (`string | boolean`)
- Default is `false`. The path to a configuration file, overrides all configurations used with this instance. The `options.overrideConfig` option is applied after this option is applied. +* `options.overrideConfigFile` (`null | true | string`)
+ Default is `null`. By default, ESLint searches for a configuration file. When this option is set to `true`, ESLint does not search for a configuration file. When this option is set to a `string` value, ESLint does not search for a configuration file, and uses the provided value as the path to the configuration file. * `options.plugins` (`Record | null`)
Default is `null`. The plugin implementations that ESLint uses for the `plugins` setting of your configuration. This is a map-like object. Those keys are plugin IDs and each value is implementation. * `options.ruleFilter` (`({ruleId: string, severity: number}) => boolean`)
From 43172ecbd449c13a503cb39539e31106179f5d80 Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Sat, 21 Dec 2024 08:07:41 +0000 Subject: [PATCH 07/51] docs: Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 451895aac545..326c6121e810 100644 --- a/README.md +++ b/README.md @@ -299,8 +299,8 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).

Platinum Sponsors

Automattic Airbnb

Gold Sponsors

trunk.io

Silver Sponsors

-

SERP Triumph JetBrains Liftoff American Express Workleap

Bronze Sponsors

-

Cybozu Syntax WordHint Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

+

SERP Triumph JetBrains Liftoff American Express Workleap

Bronze Sponsors

+

Cybozu Syntax WordHint Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

Technology Sponsors

Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.

Netlify Algolia 1Password

From 613c06a2c341758739473409a2331074884ec7f8 Mon Sep 17 00:00:00 2001 From: Amaresh S M Date: Sat, 21 Dec 2024 16:40:41 +0530 Subject: [PATCH 08/51] =?UTF-8?q?docs:=20mark=20rules=20that=20are=20froze?= =?UTF-8?q?n=20with=20=E2=9D=84=EF=B8=8F=20(#19231)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * docs: mark rules that are frozen with ❄️ * mark no-undefined as frozen * update frozen icon * Update rules.scss --- Makefile.js | 1 + docs/src/_data/rules.json | 197 ++++++++++++++++++ docs/src/_data/rules_meta.json | 53 +++++ .../components/rule-categories.macro.html | 28 ++- docs/src/_includes/components/rule.macro.html | 5 + docs/src/_includes/layouts/doc.html | 1 + docs/src/assets/scss/components/rules.scss | 10 + docs/src/pages/rules.md | 3 + lib/rules/arrow-body-style.js | 1 + lib/rules/camelcase.js | 1 + lib/rules/capitalized-comments.js | 1 + lib/rules/consistent-this.js | 1 + lib/rules/curly.js | 1 + lib/rules/default-param-last.js | 1 + lib/rules/dot-notation.js | 1 + lib/rules/func-name-matching.js | 1 + lib/rules/func-style.js | 1 + lib/rules/id-denylist.js | 1 + lib/rules/id-length.js | 1 + lib/rules/id-match.js | 1 + lib/rules/init-declarations.js | 1 + lib/rules/logical-assignment-operators.js | 1 + lib/rules/no-continue.js | 1 + lib/rules/no-div-regex.js | 1 + lib/rules/no-else-return.js | 1 + lib/rules/no-extra-boolean-cast.js | 1 + lib/rules/no-extra-label.js | 1 + lib/rules/no-implicit-coercion.js | 1 + lib/rules/no-inline-comments.js | 1 + lib/rules/no-label-var.js | 1 + lib/rules/no-labels.js | 1 + lib/rules/no-lonely-if.js | 1 + lib/rules/no-magic-numbers.js | 1 + lib/rules/no-multi-str.js | 1 + lib/rules/no-negated-condition.js | 1 + lib/rules/no-nested-ternary.js | 1 + lib/rules/no-plusplus.js | 1 + lib/rules/no-ternary.js | 1 + lib/rules/no-undef-init.js | 1 + lib/rules/no-undefined.js | 1 + lib/rules/no-underscore-dangle.js | 1 + lib/rules/no-unneeded-ternary.js | 1 + lib/rules/no-useless-computed-key.js | 1 + lib/rules/no-useless-concat.js | 1 + lib/rules/no-void.js | 1 + lib/rules/no-warning-comments.js | 1 + lib/rules/object-shorthand.js | 1 + lib/rules/one-var.js | 1 + lib/rules/operator-assignment.js | 1 + lib/rules/prefer-arrow-callback.js | 1 + lib/rules/prefer-destructuring.js | 1 + lib/rules/prefer-exponentiation-operator.js | 1 + lib/rules/prefer-numeric-literals.js | 1 + lib/rules/prefer-object-spread.js | 1 + lib/rules/prefer-spread.js | 1 + lib/rules/prefer-template.js | 1 + lib/rules/sort-imports.js | 1 + lib/rules/sort-keys.js | 1 + lib/rules/sort-vars.js | 1 + lib/rules/vars-on-top.js | 1 + lib/rules/yoda.js | 1 + 61 files changed, 347 insertions(+), 4 deletions(-) diff --git a/Makefile.js b/Makefile.js index eb0ca4561b17..dd1de510f556 100644 --- a/Makefile.js +++ b/Makefile.js @@ -209,6 +209,7 @@ function generateRuleIndexPage() { description: rule.meta.docs.description, recommended: rule.meta.docs.recommended || false, fixable: !!rule.meta.fixable, + frozen: !!rule.meta.docs.frozen, hasSuggestions: !!rule.meta.hasSuggestions }, ruleType = ruleTypesData.types[rule.meta.type]; diff --git a/docs/src/_data/rules.json b/docs/src/_data/rules.json index f1a29164d6ee..81bd9165d7b0 100644 --- a/docs/src/_data/rules.json +++ b/docs/src/_data/rules.json @@ -6,6 +6,7 @@ "description": "Enforce `return` statements in callbacks of array methods", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -13,6 +14,7 @@ "description": "Require `super()` calls in constructors", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -20,6 +22,7 @@ "description": "Enforce `for` loop update clause moving the counter in the right direction", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -27,6 +30,7 @@ "description": "Enforce `return` statements in getters", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -34,6 +38,7 @@ "description": "Disallow using an async function as a Promise executor", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -41,6 +46,7 @@ "description": "Disallow `await` inside of loops", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -48,6 +54,7 @@ "description": "Disallow reassigning class members", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -55,6 +62,7 @@ "description": "Disallow comparing against `-0`", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -62,6 +70,7 @@ "description": "Disallow assignment operators in conditional expressions", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -69,6 +78,7 @@ "description": "Disallow reassigning `const` variables", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -76,6 +86,7 @@ "description": "Disallow expressions where the operation doesn't affect the value", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -83,6 +94,7 @@ "description": "Disallow constant expressions in conditions", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -90,6 +102,7 @@ "description": "Disallow returning value from constructor", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -97,6 +110,7 @@ "description": "Disallow control characters in regular expressions", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -104,6 +118,7 @@ "description": "Disallow the use of `debugger`", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -111,6 +126,7 @@ "description": "Disallow duplicate arguments in `function` definitions", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -118,6 +134,7 @@ "description": "Disallow duplicate class members", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -125,6 +142,7 @@ "description": "Disallow duplicate conditions in if-else-if chains", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -132,6 +150,7 @@ "description": "Disallow duplicate keys in object literals", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -139,6 +158,7 @@ "description": "Disallow duplicate case labels", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -146,6 +166,7 @@ "description": "Disallow duplicate module imports", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -153,6 +174,7 @@ "description": "Disallow empty character classes in regular expressions", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -160,6 +182,7 @@ "description": "Disallow empty destructuring patterns", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -167,6 +190,7 @@ "description": "Disallow reassigning exceptions in `catch` clauses", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -174,6 +198,7 @@ "description": "Disallow fallthrough of `case` statements", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -181,6 +206,7 @@ "description": "Disallow reassigning `function` declarations", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -188,6 +214,7 @@ "description": "Disallow assigning to imported bindings", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -195,6 +222,7 @@ "description": "Disallow variable or `function` declarations in nested blocks", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -202,6 +230,7 @@ "description": "Disallow invalid regular expression strings in `RegExp` constructors", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -209,6 +238,7 @@ "description": "Disallow irregular whitespace", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -216,6 +246,7 @@ "description": "Disallow literal numbers that lose precision", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -223,6 +254,7 @@ "description": "Disallow characters which are made with multiple code points in character class syntax", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -230,6 +262,7 @@ "description": "Disallow `new` operators with global non-constructor functions", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -237,6 +270,7 @@ "description": "Disallow calling global object properties as functions", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -244,6 +278,7 @@ "description": "Disallow returning values from Promise executor functions", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -251,6 +286,7 @@ "description": "Disallow calling some `Object.prototype` methods directly on objects", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -258,6 +294,7 @@ "description": "Disallow assignments where both sides are exactly the same", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -265,6 +302,7 @@ "description": "Disallow comparisons where both sides are exactly the same", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -272,6 +310,7 @@ "description": "Disallow returning values from setters", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -279,6 +318,7 @@ "description": "Disallow sparse arrays", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -286,6 +326,7 @@ "description": "Disallow template literal placeholder syntax in regular strings", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -293,6 +334,7 @@ "description": "Disallow `this`/`super` before calling `super()` in constructors", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -300,6 +342,7 @@ "description": "Disallow the use of undeclared variables unless mentioned in `/*global */` comments", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -307,6 +350,7 @@ "description": "Disallow confusing multiline expressions", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -314,6 +358,7 @@ "description": "Disallow unmodified loop conditions", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -321,6 +366,7 @@ "description": "Disallow unreachable code after `return`, `throw`, `continue`, and `break` statements", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -328,6 +374,7 @@ "description": "Disallow loops with a body that allows only one iteration", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -335,6 +382,7 @@ "description": "Disallow control flow statements in `finally` blocks", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -342,6 +390,7 @@ "description": "Disallow negating the left operand of relational operators", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -349,6 +398,7 @@ "description": "Disallow use of optional chaining in contexts where the `undefined` value is not allowed", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -356,6 +406,7 @@ "description": "Disallow unused private class members", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -363,6 +414,7 @@ "description": "Disallow unused variables", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -370,6 +422,7 @@ "description": "Disallow the use of variables before they are defined", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -377,6 +430,7 @@ "description": "Disallow variable assignments when the value is not used", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -384,6 +438,7 @@ "description": "Disallow useless backreferences in regular expressions", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -391,6 +446,7 @@ "description": "Disallow assignments that can lead to race conditions due to usage of `await` or `yield`", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -398,6 +454,7 @@ "description": "Require calls to `isNaN()` when checking for `NaN`", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -405,6 +462,7 @@ "description": "Enforce comparing `typeof` expressions against valid strings", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": true } ], @@ -414,6 +472,7 @@ "description": "Enforce getter and setter pairs in objects and classes", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -421,6 +480,7 @@ "description": "Require braces around arrow function bodies", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -428,6 +488,7 @@ "description": "Enforce the use of variables within the scope they are defined", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -435,6 +496,7 @@ "description": "Enforce camelcase naming convention", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -442,6 +504,7 @@ "description": "Enforce or disallow capitalization of the first letter of a comment", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -449,6 +512,7 @@ "description": "Enforce that class methods utilize `this`", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -456,6 +520,7 @@ "description": "Enforce a maximum cyclomatic complexity allowed in a program", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -463,6 +528,7 @@ "description": "Require `return` statements to either always or never specify values", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -470,6 +536,7 @@ "description": "Enforce consistent naming when capturing the current execution context", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -477,6 +544,7 @@ "description": "Enforce consistent brace style for all control statements", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -484,6 +552,7 @@ "description": "Require `default` cases in `switch` statements", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -491,6 +560,7 @@ "description": "Enforce `default` clauses in switch statements to be last", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -498,6 +568,7 @@ "description": "Enforce default parameters to be last", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -505,6 +576,7 @@ "description": "Enforce dot notation whenever possible", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -512,6 +584,7 @@ "description": "Require the use of `===` and `!==`", "recommended": false, "fixable": true, + "frozen": false, "hasSuggestions": false }, { @@ -519,6 +592,7 @@ "description": "Require function names to match the name of the variable or property to which they are assigned", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -526,6 +600,7 @@ "description": "Require or disallow named `function` expressions", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -533,6 +608,7 @@ "description": "Enforce the consistent use of either `function` declarations or expressions assigned to variables", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -540,6 +616,7 @@ "description": "Require grouped accessor pairs in object literals and classes", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -547,6 +624,7 @@ "description": "Require `for-in` loops to include an `if` statement", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -554,6 +632,7 @@ "description": "Disallow specified identifiers", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -561,6 +640,7 @@ "description": "Enforce minimum and maximum identifier lengths", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -568,6 +648,7 @@ "description": "Require identifiers to match a specified regular expression", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -575,6 +656,7 @@ "description": "Require or disallow initialization in variable declarations", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -582,6 +664,7 @@ "description": "Require or disallow logical assignment operator shorthand", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": true }, { @@ -589,6 +672,7 @@ "description": "Enforce a maximum number of classes per file", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -596,6 +680,7 @@ "description": "Enforce a maximum depth that blocks can be nested", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -603,6 +688,7 @@ "description": "Enforce a maximum number of lines per file", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -610,6 +696,7 @@ "description": "Enforce a maximum number of lines of code in a function", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -617,6 +704,7 @@ "description": "Enforce a maximum depth that callbacks can be nested", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -624,6 +712,7 @@ "description": "Enforce a maximum number of parameters in function definitions", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -631,6 +720,7 @@ "description": "Enforce a maximum number of statements allowed in function blocks", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -638,6 +728,7 @@ "description": "Require constructor names to begin with a capital letter", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -645,6 +736,7 @@ "description": "Disallow the use of `alert`, `confirm`, and `prompt`", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -652,6 +744,7 @@ "description": "Disallow `Array` constructors", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -659,6 +752,7 @@ "description": "Disallow bitwise operators", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -666,6 +760,7 @@ "description": "Disallow the use of `arguments.caller` or `arguments.callee`", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -673,6 +768,7 @@ "description": "Disallow lexical declarations in case clauses", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -680,6 +776,7 @@ "description": "Disallow the use of `console`", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -687,6 +784,7 @@ "description": "Disallow `continue` statements", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -694,6 +792,7 @@ "description": "Disallow deleting variables", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -701,6 +800,7 @@ "description": "Disallow equal signs explicitly at the beginning of regular expressions", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -708,6 +808,7 @@ "description": "Disallow `else` blocks after `return` statements in `if` statements", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -715,6 +816,7 @@ "description": "Disallow empty block statements", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -722,6 +824,7 @@ "description": "Disallow empty functions", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -729,6 +832,7 @@ "description": "Disallow empty static blocks", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -736,6 +840,7 @@ "description": "Disallow `null` comparisons without type-checking operators", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -743,6 +848,7 @@ "description": "Disallow the use of `eval()`", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -750,6 +856,7 @@ "description": "Disallow extending native types", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -757,6 +864,7 @@ "description": "Disallow unnecessary calls to `.bind()`", "recommended": false, "fixable": true, + "frozen": false, "hasSuggestions": false }, { @@ -764,6 +872,7 @@ "description": "Disallow unnecessary boolean casts", "recommended": true, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -771,6 +880,7 @@ "description": "Disallow unnecessary labels", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -778,6 +888,7 @@ "description": "Disallow assignments to native objects or read-only global variables", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -785,6 +896,7 @@ "description": "Disallow shorthand type conversions", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": true }, { @@ -792,6 +904,7 @@ "description": "Disallow declarations in the global scope", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -799,6 +912,7 @@ "description": "Disallow the use of `eval()`-like methods", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -806,6 +920,7 @@ "description": "Disallow inline comments after code", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -813,6 +928,7 @@ "description": "Disallow use of `this` in contexts where the value of `this` is `undefined`", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -820,6 +936,7 @@ "description": "Disallow the use of the `__iterator__` property", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -827,6 +944,7 @@ "description": "Disallow labels that share a name with a variable", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -834,6 +952,7 @@ "description": "Disallow labeled statements", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -841,6 +960,7 @@ "description": "Disallow unnecessary nested blocks", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -848,6 +968,7 @@ "description": "Disallow `if` statements as the only statement in `else` blocks", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -855,6 +976,7 @@ "description": "Disallow function declarations that contain unsafe references inside loop statements", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -862,6 +984,7 @@ "description": "Disallow magic numbers", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -869,6 +992,7 @@ "description": "Disallow use of chained assignment expressions", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -876,6 +1000,7 @@ "description": "Disallow multiline strings", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -883,6 +1008,7 @@ "description": "Disallow negated conditions", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -890,6 +1016,7 @@ "description": "Disallow nested ternary expressions", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -897,6 +1024,7 @@ "description": "Disallow `new` operators outside of assignments or comparisons", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -904,6 +1032,7 @@ "description": "Disallow `new` operators with the `Function` object", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -911,6 +1040,7 @@ "description": "Disallow `new` operators with the `String`, `Number`, and `Boolean` objects", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -918,6 +1048,7 @@ "description": "Disallow `\\8` and `\\9` escape sequences in string literals", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -925,6 +1056,7 @@ "description": "Disallow calls to the `Object` constructor without an argument", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -932,6 +1064,7 @@ "description": "Disallow octal literals", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -939,6 +1072,7 @@ "description": "Disallow octal escape sequences in string literals", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -946,6 +1080,7 @@ "description": "Disallow reassigning function parameters", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -953,6 +1088,7 @@ "description": "Disallow the unary operators `++` and `--`", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -960,6 +1096,7 @@ "description": "Disallow the use of the `__proto__` property", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -967,6 +1104,7 @@ "description": "Disallow variable redeclaration", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -974,6 +1112,7 @@ "description": "Disallow multiple spaces in regular expressions", "recommended": true, "fixable": true, + "frozen": false, "hasSuggestions": false }, { @@ -981,6 +1120,7 @@ "description": "Disallow specified names in exports", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -988,6 +1128,7 @@ "description": "Disallow specified global variables", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -995,6 +1136,7 @@ "description": "Disallow specified modules when loaded by `import`", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1002,6 +1144,7 @@ "description": "Disallow certain properties on certain objects", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1009,6 +1152,7 @@ "description": "Disallow specified syntax", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1016,6 +1160,7 @@ "description": "Disallow assignment operators in `return` statements", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1023,6 +1168,7 @@ "description": "Disallow `javascript:` URLs", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1030,6 +1176,7 @@ "description": "Disallow comma operators", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1037,6 +1184,7 @@ "description": "Disallow variable declarations from shadowing variables declared in the outer scope", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1044,6 +1192,7 @@ "description": "Disallow identifiers from shadowing restricted names", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1051,6 +1200,7 @@ "description": "Disallow ternary operators", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -1058,6 +1208,7 @@ "description": "Disallow throwing literals as exceptions", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1065,6 +1216,7 @@ "description": "Disallow initializing variables to `undefined`", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1072,6 +1224,7 @@ "description": "Disallow the use of `undefined` as an identifier", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -1079,6 +1232,7 @@ "description": "Disallow dangling underscores in identifiers", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -1086,6 +1240,7 @@ "description": "Disallow ternary operators when simpler alternatives exist", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1093,6 +1248,7 @@ "description": "Disallow unused expressions", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1100,6 +1256,7 @@ "description": "Disallow unused labels", "recommended": true, "fixable": true, + "frozen": false, "hasSuggestions": false }, { @@ -1107,6 +1264,7 @@ "description": "Disallow unnecessary calls to `.call()` and `.apply()`", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1114,6 +1272,7 @@ "description": "Disallow unnecessary `catch` clauses", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1121,6 +1280,7 @@ "description": "Disallow unnecessary computed property keys in objects and classes", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1128,6 +1288,7 @@ "description": "Disallow unnecessary concatenation of literals or template literals", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -1135,6 +1296,7 @@ "description": "Disallow unnecessary constructors", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -1142,6 +1304,7 @@ "description": "Disallow unnecessary escape characters", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -1149,6 +1312,7 @@ "description": "Disallow renaming import, export, and destructured assignments to the same name", "recommended": false, "fixable": true, + "frozen": false, "hasSuggestions": false }, { @@ -1156,6 +1320,7 @@ "description": "Disallow redundant return statements", "recommended": false, "fixable": true, + "frozen": false, "hasSuggestions": false }, { @@ -1163,6 +1328,7 @@ "description": "Require `let` or `const` instead of `var`", "recommended": false, "fixable": true, + "frozen": false, "hasSuggestions": false }, { @@ -1170,6 +1336,7 @@ "description": "Disallow `void` operators", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -1177,6 +1344,7 @@ "description": "Disallow specified warning terms in comments", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -1184,6 +1352,7 @@ "description": "Disallow `with` statements", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1191,6 +1360,7 @@ "description": "Require or disallow method and property shorthand syntax for object literals", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1198,6 +1368,7 @@ "description": "Enforce variables to be declared either together or separately in functions", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1205,6 +1376,7 @@ "description": "Require or disallow assignment operator shorthand where possible", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1212,6 +1384,7 @@ "description": "Require using arrow functions for callbacks", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1219,6 +1392,7 @@ "description": "Require `const` declarations for variables that are never reassigned after declared", "recommended": false, "fixable": true, + "frozen": false, "hasSuggestions": false }, { @@ -1226,6 +1400,7 @@ "description": "Require destructuring from arrays and/or objects", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1233,6 +1408,7 @@ "description": "Disallow the use of `Math.pow` in favor of the `**` operator", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1240,6 +1416,7 @@ "description": "Enforce using named capture group in regular expression", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -1247,6 +1424,7 @@ "description": "Disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1254,6 +1432,7 @@ "description": "Disallow use of `Object.prototype.hasOwnProperty.call()` and prefer use of `Object.hasOwn()`", "recommended": false, "fixable": true, + "frozen": false, "hasSuggestions": false }, { @@ -1261,6 +1440,7 @@ "description": "Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1268,6 +1448,7 @@ "description": "Require using Error objects as Promise rejection reasons", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1275,6 +1456,7 @@ "description": "Disallow use of the `RegExp` constructor in favor of regular expression literals", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -1282,6 +1464,7 @@ "description": "Require rest parameters instead of `arguments`", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1289,6 +1472,7 @@ "description": "Require spread operators instead of `.apply()`", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -1296,6 +1480,7 @@ "description": "Require template literals instead of string concatenation", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1303,6 +1488,7 @@ "description": "Enforce the consistent use of the radix argument when using `parseInt()`", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -1310,6 +1496,7 @@ "description": "Disallow async functions which have no `await` expression", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -1317,6 +1504,7 @@ "description": "Enforce the use of `u` or `v` flag on regular expressions", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": true }, { @@ -1324,6 +1512,7 @@ "description": "Require generator functions to contain `yield`", "recommended": true, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1331,6 +1520,7 @@ "description": "Enforce sorted import declarations within modules", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1338,6 +1528,7 @@ "description": "Require object keys to be sorted", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -1345,6 +1536,7 @@ "description": "Require variables within the same declaration block to be sorted", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false }, { @@ -1352,6 +1544,7 @@ "description": "Require or disallow strict mode directives", "recommended": false, "fixable": true, + "frozen": false, "hasSuggestions": false }, { @@ -1359,6 +1552,7 @@ "description": "Require symbol descriptions", "recommended": false, "fixable": false, + "frozen": false, "hasSuggestions": false }, { @@ -1366,6 +1560,7 @@ "description": "Require `var` declarations be placed at the top of their containing scope", "recommended": false, "fixable": false, + "frozen": true, "hasSuggestions": false }, { @@ -1373,6 +1568,7 @@ "description": "Require or disallow \"Yoda\" conditions", "recommended": false, "fixable": true, + "frozen": true, "hasSuggestions": false } ], @@ -1382,6 +1578,7 @@ "description": "Require or disallow Unicode byte order mark (BOM)", "recommended": false, "fixable": true, + "frozen": false, "hasSuggestions": false } ] diff --git a/docs/src/_data/rules_meta.json b/docs/src/_data/rules_meta.json index 0b28511d56a3..4eede7a53cd6 100644 --- a/docs/src/_data/rules_meta.json +++ b/docs/src/_data/rules_meta.json @@ -71,6 +71,7 @@ "docs": { "description": "Require braces around arrow function bodies", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/arrow-body-style" }, "fixable": "code" @@ -151,6 +152,7 @@ "docs": { "description": "Enforce camelcase naming convention", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/camelcase" } }, @@ -159,6 +161,7 @@ "docs": { "description": "Enforce or disallow capitalization of the first letter of a comment", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/capitalized-comments" }, "fixable": "code" @@ -250,6 +253,7 @@ "docs": { "description": "Enforce consistent naming when capturing the current execution context", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/consistent-this" }, "defaultOptions": [ @@ -269,6 +273,7 @@ "docs": { "description": "Enforce consistent brace style for all control statements", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/curly" }, "defaultOptions": [ @@ -300,6 +305,7 @@ "docs": { "description": "Enforce default parameters to be last", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/default-param-last" } }, @@ -325,6 +331,7 @@ "docs": { "description": "Enforce dot notation whenever possible", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/dot-notation" }, "fixable": "code" @@ -374,6 +381,7 @@ "docs": { "description": "Require function names to match the name of the variable or property to which they are assigned", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/func-name-matching" } }, @@ -401,6 +409,7 @@ "docs": { "description": "Enforce the consistent use of either `function` declarations or expressions assigned to variables", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/func-style" } }, @@ -508,6 +517,7 @@ "docs": { "description": "Disallow specified identifiers", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/id-denylist" } }, @@ -524,6 +534,7 @@ "docs": { "description": "Enforce minimum and maximum identifier lengths", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/id-length" } }, @@ -541,6 +552,7 @@ "docs": { "description": "Require identifiers to match a specified regular expression", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/id-match" } }, @@ -584,6 +596,7 @@ "docs": { "description": "Require or disallow initialization in variable declarations", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/init-declarations" } }, @@ -681,6 +694,7 @@ "docs": { "description": "Require or disallow logical assignment operator shorthand", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/logical-assignment-operators" }, "fixable": "code", @@ -1042,6 +1056,7 @@ "docs": { "description": "Disallow `continue` statements", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-continue" } }, @@ -1075,6 +1090,7 @@ "docs": { "description": "Disallow equal signs explicitly at the beginning of regular expressions", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-div-regex" }, "fixable": "code" @@ -1142,6 +1158,7 @@ "docs": { "description": "Disallow `else` blocks after `return` statements in `if` statements", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-else-return" }, "fixable": "code" @@ -1261,6 +1278,7 @@ "docs": { "description": "Disallow unnecessary boolean casts", "recommended": true, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-extra-boolean-cast" }, "fixable": "code" @@ -1270,6 +1288,7 @@ "docs": { "description": "Disallow unnecessary labels", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-extra-label" }, "fixable": "code" @@ -1348,6 +1367,7 @@ "docs": { "description": "Disallow shorthand type conversions", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-implicit-coercion" }, "fixable": "code", @@ -1398,6 +1418,7 @@ "docs": { "description": "Disallow inline comments after code", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-inline-comments" } }, @@ -1469,6 +1490,7 @@ "docs": { "description": "Disallow labels that share a name with a variable", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-label-var" } }, @@ -1483,6 +1505,7 @@ "docs": { "description": "Disallow labeled statements", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-labels" } }, @@ -1499,6 +1522,7 @@ "docs": { "description": "Disallow `if` statements as the only statement in `else` blocks", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-lonely-if" }, "fixable": "code" @@ -1524,6 +1548,7 @@ "docs": { "description": "Disallow magic numbers", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-magic-numbers" } }, @@ -1595,6 +1620,7 @@ "docs": { "description": "Disallow multiline strings", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-multi-str" } }, @@ -1626,6 +1652,7 @@ "docs": { "description": "Disallow negated conditions", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-negated-condition" } }, @@ -1646,6 +1673,7 @@ "docs": { "description": "Disallow nested ternary expressions", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-nested-ternary" } }, @@ -1785,6 +1813,7 @@ "docs": { "description": "Disallow the unary operators `++` and `--`", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-plusplus" } }, @@ -2062,6 +2091,7 @@ "docs": { "description": "Disallow ternary operators", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-ternary" } }, @@ -2110,6 +2140,7 @@ "docs": { "description": "Disallow initializing variables to `undefined`", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-undef-init" }, "fixable": "code" @@ -2119,6 +2150,7 @@ "docs": { "description": "Disallow the use of `undefined` as an identifier", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-undefined" } }, @@ -2140,6 +2172,7 @@ "docs": { "description": "Disallow dangling underscores in identifiers", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-underscore-dangle" } }, @@ -2169,6 +2202,7 @@ "docs": { "description": "Disallow ternary operators when simpler alternatives exist", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-unneeded-ternary" }, "fixable": "code" @@ -2331,6 +2365,7 @@ "docs": { "description": "Disallow unnecessary computed property keys in objects and classes", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-useless-computed-key" }, "fixable": "code" @@ -2340,6 +2375,7 @@ "docs": { "description": "Disallow unnecessary concatenation of literals or template literals", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-useless-concat" } }, @@ -2405,6 +2441,7 @@ "docs": { "description": "Disallow `void` operators", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-void" } }, @@ -2423,6 +2460,7 @@ "docs": { "description": "Disallow specified warning terms in comments", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-warning-comments" } }, @@ -2494,6 +2532,7 @@ "docs": { "description": "Require or disallow method and property shorthand syntax for object literals", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/object-shorthand" }, "fixable": "code" @@ -2503,6 +2542,7 @@ "docs": { "description": "Enforce variables to be declared either together or separately in functions", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/one-var" }, "fixable": "code" @@ -2526,6 +2566,7 @@ "docs": { "description": "Require or disallow assignment operator shorthand where possible", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/operator-assignment" }, "fixable": "code" @@ -2574,6 +2615,7 @@ "docs": { "description": "Require using arrow functions for callbacks", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/prefer-arrow-callback" }, "fixable": "code" @@ -2598,6 +2640,7 @@ "docs": { "description": "Require destructuring from arrays and/or objects", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/prefer-destructuring" }, "fixable": "code" @@ -2607,6 +2650,7 @@ "docs": { "description": "Disallow the use of `Math.pow` in favor of the `**` operator", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/prefer-exponentiation-operator" }, "fixable": "code" @@ -2625,6 +2669,7 @@ "docs": { "description": "Disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/prefer-numeric-literals" }, "fixable": "code" @@ -2643,6 +2688,7 @@ "docs": { "description": "Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/prefer-object-spread" }, "fixable": "code" @@ -2698,6 +2744,7 @@ "docs": { "description": "Require spread operators instead of `.apply()`", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/prefer-spread" }, "fixable": null @@ -2707,6 +2754,7 @@ "docs": { "description": "Require template literals instead of string concatenation", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/prefer-template" }, "fixable": "code" @@ -2848,6 +2896,7 @@ "docs": { "description": "Enforce sorted import declarations within modules", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/sort-imports" }, "fixable": "code" @@ -2867,6 +2916,7 @@ "docs": { "description": "Require object keys to be sorted", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/sort-keys" } }, @@ -2880,6 +2930,7 @@ "docs": { "description": "Require variables within the same declaration block to be sorted", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/sort-vars" }, "fixable": "code" @@ -3050,6 +3101,7 @@ "docs": { "description": "Require `var` declarations be placed at the top of their containing scope", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/vars-on-top" } }, @@ -3098,6 +3150,7 @@ "docs": { "description": "Require or disallow \"Yoda\" conditions", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/yoda" }, "fixable": "code" diff --git a/docs/src/_includes/components/rule-categories.macro.html b/docs/src/_includes/components/rule-categories.macro.html index 29143e5d4b74..250ff6f24c42 100644 --- a/docs/src/_includes/components/rule-categories.macro.html +++ b/docs/src/_includes/components/rule-categories.macro.html @@ -1,11 +1,12 @@ - {%- macro ruleCategories(params) -%}
{%- if params.recommended == true -%}
Recommended

- Using the recommended config from @eslint/js in a configuration file enables this rule + Using the recommended config from @eslint/js in a configuration file + enables this rule

{%- endif -%} @@ -13,7 +14,8 @@
🔧 Fixable

- Some problems reported by this rule are automatically fixable by the --fix command line option + Some problems reported by this rule are automatically fixable by the --fix command line option

{%- endif -%} @@ -21,7 +23,16 @@
💡 hasSuggestions

- Some problems reported by this rule are manually fixable by editor suggestions + Some problems reported by this rule are manually fixable by editor suggestions +

+
+ {%- endif -%} + {%- if params.frozen == true -%} +
+ ❄️ Frozen +

+ This rule is currently frozen and is not accepting changes.

{%- endif -%} @@ -54,3 +65,12 @@

{%- endmacro -%} + +{%- macro frozen() -%} +
+ ❄️ Frozen +

+ if the rule is currently frozen and not accepting changes. +

+
+{%- endmacro -%} diff --git a/docs/src/_includes/components/rule.macro.html b/docs/src/_includes/components/rule.macro.html index cd5d61b0386f..82a008a2cb82 100644 --- a/docs/src/_includes/components/rule.macro.html +++ b/docs/src/_includes/components/rule.macro.html @@ -22,7 +22,12 @@ {%- else -%}

{{ params.description }}

{%- endif -%} {%- else -%} +
{{ params.name }} + {%- if params.categories and params.categories.frozen %} +

❄️ Frozen

+ {%- endif -%} +

{{ params.description }}

{%- endif -%} diff --git a/docs/src/_includes/layouts/doc.html b/docs/src/_includes/layouts/doc.html index f17bd15873e5..3c9837947817 100644 --- a/docs/src/_includes/layouts/doc.html +++ b/docs/src/_includes/layouts/doc.html @@ -87,6 +87,7 @@

{{ title }}

index: id, recommended: rule_meta.docs.recommended, fixable: rule_meta.fixable, + frozen: rule_meta.docs.frozen, hasSuggestions: rule_meta.hasSuggestions }) }} {% endif %} diff --git a/docs/src/assets/scss/components/rules.scss b/docs/src/assets/scss/components/rules.scss index 55ba6995bbac..fcdbb2eb8a78 100644 --- a/docs/src/assets/scss/components/rules.scss +++ b/docs/src/assets/scss/components/rules.scss @@ -89,6 +89,16 @@ flex: 1 1 35ch; } +.rule__name_wrapper { + display: flex; + align-items: center; + gap: 0.5rem; + + .frozen { + font-size: .875rem; + } +} + .rule__name { font-weight: 500; font-size: .875rem; diff --git a/docs/src/pages/rules.md b/docs/src/pages/rules.md index 0b475b868fdd..0f1508d4a206 100644 --- a/docs/src/pages/rules.md +++ b/docs/src/pages/rules.md @@ -17,6 +17,7 @@ Rules in ESLint are grouped by type to help you understand their purpose. Each r index: true, recommended: true, fixable: true, + frozen: true, hasSuggestions: true }) }} @@ -35,6 +36,7 @@ Rules in ESLint are grouped by type to help you understand their purpose. Each r {%- set name_value = the_rule.name -%} {%- set description_value = the_rule.description -%} {%- set isRecommended = the_rule.recommended -%} + {%- set isFrozen = the_rule.frozen -%} {%- set isFixable = the_rule.fixable -%} {%- set isHasSuggestions = the_rule.hasSuggestions -%} @@ -45,6 +47,7 @@ Rules in ESLint are grouped by type to help you understand their purpose. Each r categories: { recommended: isRecommended, fixable: isFixable, + frozen: isFrozen, hasSuggestions: isHasSuggestions } }) }} diff --git a/lib/rules/arrow-body-style.js b/lib/rules/arrow-body-style.js index a5947e500c2e..ab219d42fc3b 100644 --- a/lib/rules/arrow-body-style.js +++ b/lib/rules/arrow-body-style.js @@ -24,6 +24,7 @@ module.exports = { docs: { description: "Require braces around arrow function bodies", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/arrow-body-style" }, diff --git a/lib/rules/camelcase.js b/lib/rules/camelcase.js index 6fac7462f606..7bc75ea5e64e 100644 --- a/lib/rules/camelcase.js +++ b/lib/rules/camelcase.js @@ -31,6 +31,7 @@ module.exports = { docs: { description: "Enforce camelcase naming convention", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/camelcase" }, diff --git a/lib/rules/capitalized-comments.js b/lib/rules/capitalized-comments.js index 07a27b6ec963..79646363d5eb 100644 --- a/lib/rules/capitalized-comments.js +++ b/lib/rules/capitalized-comments.js @@ -107,6 +107,7 @@ module.exports = { docs: { description: "Enforce or disallow capitalization of the first letter of a comment", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/capitalized-comments" }, diff --git a/lib/rules/consistent-this.js b/lib/rules/consistent-this.js index 9a76e7a49a8d..ad5ea3e3cd6a 100644 --- a/lib/rules/consistent-this.js +++ b/lib/rules/consistent-this.js @@ -16,6 +16,7 @@ module.exports = { docs: { description: "Enforce consistent naming when capturing the current execution context", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/consistent-this" }, diff --git a/lib/rules/curly.js b/lib/rules/curly.js index fa273dccf5ab..c08b7e39988d 100644 --- a/lib/rules/curly.js +++ b/lib/rules/curly.js @@ -22,6 +22,7 @@ module.exports = { docs: { description: "Enforce consistent brace style for all control statements", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/curly" }, diff --git a/lib/rules/default-param-last.js b/lib/rules/default-param-last.js index 3254fa8026f4..e1260c17cf7b 100644 --- a/lib/rules/default-param-last.js +++ b/lib/rules/default-param-last.js @@ -13,6 +13,7 @@ module.exports = { docs: { description: "Enforce default parameters to be last", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/default-param-last" }, diff --git a/lib/rules/dot-notation.js b/lib/rules/dot-notation.js index 370c1caec66a..30537ae72f42 100644 --- a/lib/rules/dot-notation.js +++ b/lib/rules/dot-notation.js @@ -33,6 +33,7 @@ module.exports = { docs: { description: "Enforce dot notation whenever possible", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/dot-notation" }, diff --git a/lib/rules/func-name-matching.js b/lib/rules/func-name-matching.js index b9555d6bdf4e..b71e6e6ac28f 100644 --- a/lib/rules/func-name-matching.js +++ b/lib/rules/func-name-matching.js @@ -76,6 +76,7 @@ module.exports = { docs: { description: "Require function names to match the name of the variable or property to which they are assigned", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/func-name-matching" }, diff --git a/lib/rules/func-style.js b/lib/rules/func-style.js index b6682d609eae..be2298340d20 100644 --- a/lib/rules/func-style.js +++ b/lib/rules/func-style.js @@ -21,6 +21,7 @@ module.exports = { docs: { description: "Enforce the consistent use of either `function` declarations or expressions assigned to variables", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/func-style" }, diff --git a/lib/rules/id-denylist.js b/lib/rules/id-denylist.js index 5d394be27a0e..8441c641dc67 100644 --- a/lib/rules/id-denylist.js +++ b/lib/rules/id-denylist.js @@ -109,6 +109,7 @@ module.exports = { docs: { description: "Disallow specified identifiers", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/id-denylist" }, diff --git a/lib/rules/id-length.js b/lib/rules/id-length.js index 65b75709fd60..700763641602 100644 --- a/lib/rules/id-length.js +++ b/lib/rules/id-length.js @@ -32,6 +32,7 @@ module.exports = { docs: { description: "Enforce minimum and maximum identifier lengths", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/id-length" }, diff --git a/lib/rules/id-match.js b/lib/rules/id-match.js index 76d774efbb32..c099deb153ab 100644 --- a/lib/rules/id-match.js +++ b/lib/rules/id-match.js @@ -30,6 +30,7 @@ module.exports = { docs: { description: "Require identifiers to match a specified regular expression", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/id-match" }, diff --git a/lib/rules/init-declarations.js b/lib/rules/init-declarations.js index 3abe107f1993..6ed83ee38c37 100644 --- a/lib/rules/init-declarations.js +++ b/lib/rules/init-declarations.js @@ -50,6 +50,7 @@ module.exports = { docs: { description: "Require or disallow initialization in variable declarations", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/init-declarations" }, diff --git a/lib/rules/logical-assignment-operators.js b/lib/rules/logical-assignment-operators.js index c084c04c8eda..d2070beeb334 100644 --- a/lib/rules/logical-assignment-operators.js +++ b/lib/rules/logical-assignment-operators.js @@ -186,6 +186,7 @@ module.exports = { docs: { description: "Require or disallow logical assignment operator shorthand", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/logical-assignment-operators" }, diff --git a/lib/rules/no-continue.js b/lib/rules/no-continue.js index f6e484b2fc78..c1b6d75ad390 100644 --- a/lib/rules/no-continue.js +++ b/lib/rules/no-continue.js @@ -17,6 +17,7 @@ module.exports = { docs: { description: "Disallow `continue` statements", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-continue" }, diff --git a/lib/rules/no-div-regex.js b/lib/rules/no-div-regex.js index 208f840bef68..24e6f892f7e7 100644 --- a/lib/rules/no-div-regex.js +++ b/lib/rules/no-div-regex.js @@ -17,6 +17,7 @@ module.exports = { docs: { description: "Disallow equal signs explicitly at the beginning of regular expressions", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-div-regex" }, diff --git a/lib/rules/no-else-return.js b/lib/rules/no-else-return.js index d456181b594e..e4653d46a4dc 100644 --- a/lib/rules/no-else-return.js +++ b/lib/rules/no-else-return.js @@ -26,6 +26,7 @@ module.exports = { docs: { description: "Disallow `else` blocks after `return` statements in `if` statements", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-else-return" }, diff --git a/lib/rules/no-extra-boolean-cast.js b/lib/rules/no-extra-boolean-cast.js index fc17e995765b..63450c310b7e 100644 --- a/lib/rules/no-extra-boolean-cast.js +++ b/lib/rules/no-extra-boolean-cast.js @@ -28,6 +28,7 @@ module.exports = { docs: { description: "Disallow unnecessary boolean casts", recommended: true, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-extra-boolean-cast" }, diff --git a/lib/rules/no-extra-label.js b/lib/rules/no-extra-label.js index 45ff441d0017..11986c96d34c 100644 --- a/lib/rules/no-extra-label.js +++ b/lib/rules/no-extra-label.js @@ -23,6 +23,7 @@ module.exports = { docs: { description: "Disallow unnecessary labels", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-extra-label" }, diff --git a/lib/rules/no-implicit-coercion.js b/lib/rules/no-implicit-coercion.js index e82638fddb61..a1eab14f4b39 100644 --- a/lib/rules/no-implicit-coercion.js +++ b/lib/rules/no-implicit-coercion.js @@ -179,6 +179,7 @@ module.exports = { docs: { description: "Disallow shorthand type conversions", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-implicit-coercion" }, diff --git a/lib/rules/no-inline-comments.js b/lib/rules/no-inline-comments.js index 439418c7b11a..cc34dac2a8d3 100644 --- a/lib/rules/no-inline-comments.js +++ b/lib/rules/no-inline-comments.js @@ -20,6 +20,7 @@ module.exports = { docs: { description: "Disallow inline comments after code", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-inline-comments" }, diff --git a/lib/rules/no-label-var.js b/lib/rules/no-label-var.js index bf33cd157bad..31dee3b4c7b7 100644 --- a/lib/rules/no-label-var.js +++ b/lib/rules/no-label-var.js @@ -23,6 +23,7 @@ module.exports = { docs: { description: "Disallow labels that share a name with a variable", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-label-var" }, diff --git a/lib/rules/no-labels.js b/lib/rules/no-labels.js index 3860bf8a0517..2b96c928a99a 100644 --- a/lib/rules/no-labels.js +++ b/lib/rules/no-labels.js @@ -27,6 +27,7 @@ module.exports = { docs: { description: "Disallow labeled statements", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-labels" }, diff --git a/lib/rules/no-lonely-if.js b/lib/rules/no-lonely-if.js index bec9f0201cd1..f66b794b6b3d 100644 --- a/lib/rules/no-lonely-if.js +++ b/lib/rules/no-lonely-if.js @@ -22,6 +22,7 @@ module.exports = { docs: { description: "Disallow `if` statements as the only statement in `else` blocks", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-lonely-if" }, diff --git a/lib/rules/no-magic-numbers.js b/lib/rules/no-magic-numbers.js index f48a62d85cd4..4cda74dd886d 100644 --- a/lib/rules/no-magic-numbers.js +++ b/lib/rules/no-magic-numbers.js @@ -34,6 +34,7 @@ module.exports = { docs: { description: "Disallow magic numbers", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-magic-numbers" }, diff --git a/lib/rules/no-multi-str.js b/lib/rules/no-multi-str.js index 8011729ec60e..f58e2d4a44e5 100644 --- a/lib/rules/no-multi-str.js +++ b/lib/rules/no-multi-str.js @@ -23,6 +23,7 @@ module.exports = { docs: { description: "Disallow multiline strings", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-multi-str" }, diff --git a/lib/rules/no-negated-condition.js b/lib/rules/no-negated-condition.js index 3cb759049d99..641123dba4a0 100644 --- a/lib/rules/no-negated-condition.js +++ b/lib/rules/no-negated-condition.js @@ -16,6 +16,7 @@ module.exports = { docs: { description: "Disallow negated conditions", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-negated-condition" }, diff --git a/lib/rules/no-nested-ternary.js b/lib/rules/no-nested-ternary.js index faf80416c3f4..cf26f287c3a5 100644 --- a/lib/rules/no-nested-ternary.js +++ b/lib/rules/no-nested-ternary.js @@ -17,6 +17,7 @@ module.exports = { docs: { description: "Disallow nested ternary expressions", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-nested-ternary" }, diff --git a/lib/rules/no-plusplus.js b/lib/rules/no-plusplus.js index 7c91ebe8a7d7..8a1d6ad58759 100644 --- a/lib/rules/no-plusplus.js +++ b/lib/rules/no-plusplus.js @@ -57,6 +57,7 @@ module.exports = { docs: { description: "Disallow the unary operators `++` and `--`", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-plusplus" }, diff --git a/lib/rules/no-ternary.js b/lib/rules/no-ternary.js index 4d43c7e022d9..26c00ff041ac 100644 --- a/lib/rules/no-ternary.js +++ b/lib/rules/no-ternary.js @@ -17,6 +17,7 @@ module.exports = { docs: { description: "Disallow ternary operators", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-ternary" }, diff --git a/lib/rules/no-undef-init.js b/lib/rules/no-undef-init.js index be19d6f9526b..e16793bc3de0 100644 --- a/lib/rules/no-undef-init.js +++ b/lib/rules/no-undef-init.js @@ -19,6 +19,7 @@ module.exports = { docs: { description: "Disallow initializing variables to `undefined`", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-undef-init" }, diff --git a/lib/rules/no-undefined.js b/lib/rules/no-undefined.js index 8f47ca1b020a..4fa769915961 100644 --- a/lib/rules/no-undefined.js +++ b/lib/rules/no-undefined.js @@ -16,6 +16,7 @@ module.exports = { docs: { description: "Disallow the use of `undefined` as an identifier", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-undefined" }, diff --git a/lib/rules/no-underscore-dangle.js b/lib/rules/no-underscore-dangle.js index 7247f0ec0673..702027d78775 100644 --- a/lib/rules/no-underscore-dangle.js +++ b/lib/rules/no-underscore-dangle.js @@ -29,6 +29,7 @@ module.exports = { docs: { description: "Disallow dangling underscores in identifiers", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-underscore-dangle" }, diff --git a/lib/rules/no-unneeded-ternary.js b/lib/rules/no-unneeded-ternary.js index 3d3dad0f61b2..c64c14767d35 100644 --- a/lib/rules/no-unneeded-ternary.js +++ b/lib/rules/no-unneeded-ternary.js @@ -33,6 +33,7 @@ module.exports = { docs: { description: "Disallow ternary operators when simpler alternatives exist", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-unneeded-ternary" }, diff --git a/lib/rules/no-useless-computed-key.js b/lib/rules/no-useless-computed-key.js index 11dbd9d04b00..3f537caca8c2 100644 --- a/lib/rules/no-useless-computed-key.js +++ b/lib/rules/no-useless-computed-key.js @@ -100,6 +100,7 @@ module.exports = { docs: { description: "Disallow unnecessary computed property keys in objects and classes", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-useless-computed-key" }, diff --git a/lib/rules/no-useless-concat.js b/lib/rules/no-useless-concat.js index c566c62be8dc..b25ed25fb24f 100644 --- a/lib/rules/no-useless-concat.js +++ b/lib/rules/no-useless-concat.js @@ -72,6 +72,7 @@ module.exports = { docs: { description: "Disallow unnecessary concatenation of literals or template literals", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-useless-concat" }, diff --git a/lib/rules/no-void.js b/lib/rules/no-void.js index 1f643f2f2989..0ac8288347ad 100644 --- a/lib/rules/no-void.js +++ b/lib/rules/no-void.js @@ -20,6 +20,7 @@ module.exports = { docs: { description: "Disallow `void` operators", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-void" }, diff --git a/lib/rules/no-warning-comments.js b/lib/rules/no-warning-comments.js index 628f5a2ac513..0e6a2f2848ec 100644 --- a/lib/rules/no-warning-comments.js +++ b/lib/rules/no-warning-comments.js @@ -27,6 +27,7 @@ module.exports = { docs: { description: "Disallow specified warning terms in comments", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/no-warning-comments" }, diff --git a/lib/rules/object-shorthand.js b/lib/rules/object-shorthand.js index f035bbe581fe..35428ac68123 100644 --- a/lib/rules/object-shorthand.js +++ b/lib/rules/object-shorthand.js @@ -30,6 +30,7 @@ module.exports = { docs: { description: "Require or disallow method and property shorthand syntax for object literals", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/object-shorthand" }, diff --git a/lib/rules/one-var.js b/lib/rules/one-var.js index ba461a407cac..e81b5a52d4eb 100644 --- a/lib/rules/one-var.js +++ b/lib/rules/one-var.js @@ -36,6 +36,7 @@ module.exports = { docs: { description: "Enforce variables to be declared either together or separately in functions", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/one-var" }, diff --git a/lib/rules/operator-assignment.js b/lib/rules/operator-assignment.js index 412c97f66e0b..00619a3851b9 100644 --- a/lib/rules/operator-assignment.js +++ b/lib/rules/operator-assignment.js @@ -67,6 +67,7 @@ module.exports = { docs: { description: "Require or disallow assignment operator shorthand where possible", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/operator-assignment" }, diff --git a/lib/rules/prefer-arrow-callback.js b/lib/rules/prefer-arrow-callback.js index ef2ea7bbfe2d..982246e0857f 100644 --- a/lib/rules/prefer-arrow-callback.js +++ b/lib/rules/prefer-arrow-callback.js @@ -155,6 +155,7 @@ module.exports = { docs: { description: "Require using arrow functions for callbacks", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/prefer-arrow-callback" }, diff --git a/lib/rules/prefer-destructuring.js b/lib/rules/prefer-destructuring.js index c6075c55bf5a..c0af567931f8 100644 --- a/lib/rules/prefer-destructuring.js +++ b/lib/rules/prefer-destructuring.js @@ -28,6 +28,7 @@ module.exports = { docs: { description: "Require destructuring from arrays and/or objects", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/prefer-destructuring" }, diff --git a/lib/rules/prefer-exponentiation-operator.js b/lib/rules/prefer-exponentiation-operator.js index 6d807f9cfeaf..cc9b51f2d8cc 100644 --- a/lib/rules/prefer-exponentiation-operator.js +++ b/lib/rules/prefer-exponentiation-operator.js @@ -93,6 +93,7 @@ module.exports = { docs: { description: "Disallow the use of `Math.pow` in favor of the `**` operator", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/prefer-exponentiation-operator" }, diff --git a/lib/rules/prefer-numeric-literals.js b/lib/rules/prefer-numeric-literals.js index 118d6dce4e35..4233b59fdc4e 100644 --- a/lib/rules/prefer-numeric-literals.js +++ b/lib/rules/prefer-numeric-literals.js @@ -47,6 +47,7 @@ module.exports = { docs: { description: "Disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/prefer-numeric-literals" }, diff --git a/lib/rules/prefer-object-spread.js b/lib/rules/prefer-object-spread.js index a6eb4bd4f6a4..eb282dcfbe83 100644 --- a/lib/rules/prefer-object-spread.js +++ b/lib/rules/prefer-object-spread.js @@ -248,6 +248,7 @@ module.exports = { description: "Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/prefer-object-spread" }, diff --git a/lib/rules/prefer-spread.js b/lib/rules/prefer-spread.js index 7013c1d50526..5219b3efb646 100644 --- a/lib/rules/prefer-spread.js +++ b/lib/rules/prefer-spread.js @@ -51,6 +51,7 @@ module.exports = { docs: { description: "Require spread operators instead of `.apply()`", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/prefer-spread" }, diff --git a/lib/rules/prefer-template.js b/lib/rules/prefer-template.js index d7d70c50640d..3de812bc68af 100644 --- a/lib/rules/prefer-template.js +++ b/lib/rules/prefer-template.js @@ -130,6 +130,7 @@ module.exports = { docs: { description: "Require template literals instead of string concatenation", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/prefer-template" }, diff --git a/lib/rules/sort-imports.js b/lib/rules/sort-imports.js index 9a1113ab9e5b..fe3ddac2d156 100644 --- a/lib/rules/sort-imports.js +++ b/lib/rules/sort-imports.js @@ -25,6 +25,7 @@ module.exports = { docs: { description: "Enforce sorted import declarations within modules", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/sort-imports" }, diff --git a/lib/rules/sort-keys.js b/lib/rules/sort-keys.js index c8429ade9f36..47932609a14c 100644 --- a/lib/rules/sort-keys.js +++ b/lib/rules/sort-keys.js @@ -91,6 +91,7 @@ module.exports = { docs: { description: "Require object keys to be sorted", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/sort-keys" }, diff --git a/lib/rules/sort-vars.js b/lib/rules/sort-vars.js index 985f47f5ab4c..cc22061a2507 100644 --- a/lib/rules/sort-vars.js +++ b/lib/rules/sort-vars.js @@ -21,6 +21,7 @@ module.exports = { docs: { description: "Require variables within the same declaration block to be sorted", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/sort-vars" }, diff --git a/lib/rules/vars-on-top.js b/lib/rules/vars-on-top.js index 81f5d62d02d8..ccb36c426e33 100644 --- a/lib/rules/vars-on-top.js +++ b/lib/rules/vars-on-top.js @@ -17,6 +17,7 @@ module.exports = { docs: { description: "Require `var` declarations be placed at the top of their containing scope", recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/vars-on-top" }, diff --git a/lib/rules/yoda.js b/lib/rules/yoda.js index af73e8e0ca5e..2f7bfff84af6 100644 --- a/lib/rules/yoda.js +++ b/lib/rules/yoda.js @@ -119,6 +119,7 @@ module.exports = { docs: { description: 'Require or disallow "Yoda" conditions', recommended: false, + frozen: true, url: "https://eslint.org/docs/latest/rules/yoda" }, From 789edbbae5aeeefc8fee94cd653b0b5f3e2ae3eb Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Mon, 23 Dec 2024 08:09:08 +0000 Subject: [PATCH 09/51] docs: Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 326c6121e810..0d41451e772e 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,7 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).

Automattic Airbnb

Gold Sponsors

trunk.io

Silver Sponsors

SERP Triumph JetBrains Liftoff American Express Workleap

Bronze Sponsors

-

Cybozu Syntax WordHint Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

+

Syntax Cybozu WordHint Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

Technology Sponsors

Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.

Netlify Algolia 1Password

From 5db226f4da9ad7d53a4505a90290b68d4036c082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Tue, 24 Dec 2024 20:19:58 +0900 Subject: [PATCH 10/51] docs: add missing backticks in various parts of the documentation (#19269) --- docs/src/extend/plugins.md | 2 +- docs/src/rules/id-match.md | 2 +- docs/src/rules/no-array-constructor.md | 2 +- docs/src/rules/no-console.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/extend/plugins.md b/docs/src/extend/plugins.md index 592a41a3563b..65d5426d776b 100644 --- a/docs/src/extend/plugins.md +++ b/docs/src/extend/plugins.md @@ -40,7 +40,7 @@ If you plan to distribute your plugin as an npm package, make sure that the modu ### Meta Data in Plugins -For easier debugging and more effective caching of plugins, it's recommended to provide a name and version in a `meta` object at the root of your plugin, like this: +For easier debugging and more effective caching of plugins, it's recommended to provide a `name` and `version` in a `meta` object at the root of your plugin, like this: ```js const plugin = { diff --git a/docs/src/rules/id-match.md b/docs/src/rules/id-match.md index 3fbe3925d5d3..86ff85f904b7 100644 --- a/docs/src/rules/id-match.md +++ b/docs/src/rules/id-match.md @@ -9,7 +9,7 @@ rule_type: suggestion Naming things consistently in a project is an often underestimated aspect of code creation. When done correctly, it can save your team hours of unnecessary head scratching and misdirections. This rule allows you to precisely define and enforce the variables and function names on your team should use. -No more limiting yourself to camelCase, snake_case, PascalCase, or HungarianNotation. Id-match has all your needs covered! +No more limiting yourself to camelCase, snake_case, PascalCase, or HungarianNotation. `id-match` has all your needs covered! ## Rule Details diff --git a/docs/src/rules/no-array-constructor.md b/docs/src/rules/no-array-constructor.md index eff97dee776b..51152dcc0418 100644 --- a/docs/src/rules/no-array-constructor.md +++ b/docs/src/rules/no-array-constructor.md @@ -10,7 +10,7 @@ related_rules: Use of the `Array` constructor to construct a new array is generally discouraged in favor of array literal notation because of the single-argument pitfall and because the `Array` global may be redefined. The exception is when -the Array constructor is used to intentionally create sparse arrays of a +the `Array` constructor is used to intentionally create sparse arrays of a specified size by giving the constructor a single numeric argument. ## Rule Details diff --git a/docs/src/rules/no-console.md b/docs/src/rules/no-console.md index 9420c36ec03b..2887d31333be 100644 --- a/docs/src/rules/no-console.md +++ b/docs/src/rules/no-console.md @@ -69,7 +69,7 @@ console.error("Log an error level message."); If you're using Node.js, however, `console` is used to output information to the user and so is not strictly used for debugging purposes. If you are developing for Node.js then you most likely do not want this rule enabled. -Another case where you might not use this rule is if you want to enforce console calls and not console overwrites. For example: +Another case where you might not use this rule is if you want to enforce `console` calls and not `console` overwrites. For example: ```js /* eslint no-console: ["error", { allow: ["warn"] }] */ From 87a9352c621e7cd1d5bb77b3c08df7837363ea12 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Fri, 27 Dec 2024 07:23:44 +0100 Subject: [PATCH 11/51] feat: check imports and class names in `no-shadow-restricted-names` (#19272) Fixes #19271 --- docs/src/rules/no-shadow-restricted-names.md | 24 +++ lib/rules/no-shadow-restricted-names.js | 24 ++- tests/lib/rules/no-shadow-restricted-names.js | 147 +++++++++++++----- 3 files changed, 147 insertions(+), 48 deletions(-) diff --git a/docs/src/rules/no-shadow-restricted-names.md b/docs/src/rules/no-shadow-restricted-names.md index 7a5e1b0403d9..8960d336a074 100644 --- a/docs/src/rules/no-shadow-restricted-names.md +++ b/docs/src/rules/no-shadow-restricted-names.md @@ -38,6 +38,20 @@ try {} catch(eval){} ::: +::: incorrect + +```js +/*eslint no-shadow-restricted-names: "error"*/ + +import NaN from "foo"; + +import { undefined } from "bar"; + +class Infinity {} +``` + +::: + Examples of **correct** code for this rule: ::: correct { "sourceType": "script" } @@ -54,3 +68,13 @@ var undefined; ``` ::: + +::: correct + +```js +/*eslint no-shadow-restricted-names: "error"*/ + +import { undefined as undef } from "bar"; +``` + +::: diff --git a/lib/rules/no-shadow-restricted-names.js b/lib/rules/no-shadow-restricted-names.js index 29560fffc7f0..cdf96ce9e10a 100644 --- a/lib/rules/no-shadow-restricted-names.js +++ b/lib/rules/no-shadow-restricted-names.js @@ -45,17 +45,27 @@ module.exports = { const RESTRICTED = new Set(["undefined", "NaN", "Infinity", "arguments", "eval"]); const sourceCode = context.sourceCode; + // Track reported nodes to avoid duplicate reports. For example, on class declarations. + const reportedNodes = new Set(); + return { - "VariableDeclaration, :function, CatchClause"(node) { + "VariableDeclaration, :function, CatchClause, ImportDeclaration, ClassDeclaration, ClassExpression"(node) { for (const variable of sourceCode.getDeclaredVariables(node)) { if (variable.defs.length > 0 && RESTRICTED.has(variable.name) && !safelyShadowsUndefined(variable)) { - context.report({ - node: variable.defs[0].name, - messageId: "shadowingRestrictedName", - data: { - name: variable.name + for (const def of variable.defs) { + const nodeToReport = def.name; + + if (!reportedNodes.has(nodeToReport)) { + reportedNodes.add(nodeToReport); + context.report({ + node: nodeToReport, + messageId: "shadowingRestrictedName", + data: { + name: variable.name + } + }); } - }); + } } } } diff --git a/tests/lib/rules/no-shadow-restricted-names.js b/tests/lib/rules/no-shadow-restricted-names.js index 7acc0800c7a4..72ce16e890b2 100644 --- a/tests/lib/rules/no-shadow-restricted-names.js +++ b/tests/lib/rules/no-shadow-restricted-names.js @@ -40,96 +40,161 @@ ruleTester.run("no-shadow-restricted-names", rule, { { code: "let undefined", languageOptions: { ecmaVersion: 2015 } + }, + { + code: "import { undefined as undef } from 'foo';", + languageOptions: { + sourceType: "module", + ecmaVersion: 2015 + } } ], invalid: [ { code: "function NaN(NaN) { var NaN; !function NaN(NaN) { try {} catch(NaN) {} }; }", errors: [ - { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier", column: 10 }, + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier", column: 14 }, + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier", column: 25 }, + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier", column: 40 }, + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier", column: 44 }, + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier", column: 64 } ] }, { code: "function undefined(undefined) { !function undefined(undefined) { try {} catch(undefined) {} }; }", errors: [ - { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 10 }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 20 }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 43 }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 53 }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 79 } ] }, { code: "function Infinity(Infinity) { var Infinity; !function Infinity(Infinity) { try {} catch(Infinity) {} }; }", errors: [ - { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier", column: 10 }, + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier", column: 19 }, + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier", column: 35 }, + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier", column: 55 }, + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier", column: 64 }, + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier", column: 89 } ] }, { code: "function arguments(arguments) { var arguments; !function arguments(arguments) { try {} catch(arguments) {} }; }", errors: [ - { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier", column: 10 }, + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier", column: 20 }, + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier", column: 37 }, + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier", column: 58 }, + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier", column: 68 }, + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier", column: 94 } ] }, { code: "function eval(eval) { var eval; !function eval(eval) { try {} catch(eval) {} }; }", errors: [ - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 10 }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 15 }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 27 }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 43 }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 48 }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 69 } ] }, { code: "var eval = (eval) => { var eval; !function eval(eval) { try {} catch(eval) {} }; }", languageOptions: { ecmaVersion: 6 }, errors: [ - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 5 }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 13 }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 28 }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 44 }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 49 }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier", column: 70 } ] }, { code: "var [undefined] = [1]", languageOptions: { ecmaVersion: 6 }, errors: [ - { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 6 } ] }, { code: "var {undefined} = obj; var {a: undefined} = obj; var {a: {b: {undefined}}} = obj; var {a, ...undefined} = obj;", languageOptions: { ecmaVersion: 9 }, errors: [ - { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, - { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 6 }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 32 }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 63 }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 94 } ] }, { code: "var undefined; undefined = 5;", errors: [ - { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 5 } + ] + }, + { + code: "class undefined {}", + languageOptions: { + ecmaVersion: 2015 + }, + errors: [ + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 7 } + ] + }, + { + code: "(class undefined {})", + languageOptions: { + ecmaVersion: 2015 + }, + errors: [ + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 8 } + ] + }, + { + code: "import undefined from 'foo';", + languageOptions: { + ecmaVersion: 2015, + sourceType: "module" + }, + errors: [ + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 8 } + ] + }, + { + code: "import { undefined } from 'foo';", + languageOptions: { + ecmaVersion: 2015, + sourceType: "module" + }, + errors: [ + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 10 } + ] + }, + { + code: "import { baz as undefined } from 'foo';", + languageOptions: { + ecmaVersion: 2015, + sourceType: "module" + }, + errors: [ + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 17 } + ] + }, + { + code: "import * as undefined from 'foo';", + languageOptions: { + ecmaVersion: 2015, + sourceType: "module" + }, + errors: [ + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier", column: 13 } ] } ] From 8efc2d0c92dab6099f34c1479cd80bdc5cd1b07b Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Fri, 27 Dec 2024 08:06:15 +0100 Subject: [PATCH 12/51] feat: unflag TypeScript config files (#19266) --- docs/src/use/configure/configuration-files.md | 14 +- lib/cli.js | 7 +- lib/config/config-loader.js | 31 +--- lib/eslint/eslint.js | 7 +- lib/shared/flags.js | 6 +- tests/fixtures/ts-config-files/helper.ts | 31 +--- tests/lib/eslint/eslint.js | 156 ++++++++---------- 7 files changed, 86 insertions(+), 166 deletions(-) diff --git a/docs/src/use/configure/configuration-files.md b/docs/src/use/configure/configuration-files.md index 05cc2bd8bbb1..d90c0fefec70 100644 --- a/docs/src/use/configure/configuration-files.md +++ b/docs/src/use/configure/configuration-files.md @@ -517,18 +517,6 @@ For more information about using feature flags, see [Feature Flags](../../flags/ ## TypeScript Configuration Files -::: warning -This feature is currently experimental and may change in future versions. -::: - -You need to enable this feature through the `unstable_ts_config` feature flag: - -```bash -npx eslint --flag unstable_ts_config -``` - -For more information about using feature flags, see [Feature Flags](../../flags/). - For Deno and Bun, TypeScript configuration files are natively supported; for Node.js, you must install the optional dev dependency [`jiti`](https://github.com/unjs/jiti) in version 2.0.0 or later in your project (this dependency is not automatically installed by ESLint): ```bash @@ -591,5 +579,5 @@ If you have multiple ESLint configuration files, ESLint prioritizes JavaScript f To override this behavior, use the `--config` or `-c` command line option to specify a different configuration file: ```bash -npx eslint --flag unstable_ts_config --config eslint.config.ts +npx eslint --config eslint.config.ts ``` diff --git a/lib/cli.js b/lib/cli.js index 3229d6a20056..3a508d76637b 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -341,16 +341,15 @@ const cli = { /** * Calculates the command string for the --inspect-config operation. * @param {string} configFile The path to the config file to inspect. - * @param {boolean} hasUnstableTSConfigFlag `true` if the `unstable_ts_config` flag is enabled, `false` if it's not. * @returns {Promise} The command string to execute. */ - async calculateInspectConfigFlags(configFile, hasUnstableTSConfigFlag) { + async calculateInspectConfigFlags(configFile) { // find the config file const { configFilePath, basePath - } = await locateConfigFileToUse({ cwd: process.cwd(), configFile }, hasUnstableTSConfigFlag); + } = await locateConfigFileToUse({ cwd: process.cwd(), configFile }); return ["--config", configFilePath, "--basePath", basePath]; }, @@ -451,7 +450,7 @@ const cli = { try { const flatOptions = await translateOptions(options, "flat"); const spawn = require("cross-spawn"); - const flags = await cli.calculateInspectConfigFlags(flatOptions.overrideConfigFile, flatOptions.flags ? flatOptions.flags.includes("unstable_ts_config") : false); + const flags = await cli.calculateInspectConfigFlags(flatOptions.overrideConfigFile); spawn.sync("npx", ["@eslint/config-inspector@latest", ...flags], { encoding: "utf8", stdio: "inherit" }); } catch (error) { diff --git a/lib/config/config-loader.js b/lib/config/config-loader.js index 845cd0c92861..85944672ac23 100644 --- a/lib/config/config-loader.js +++ b/lib/config/config-loader.js @@ -31,7 +31,6 @@ const { FlatConfigArray } = require("./flat-config-array"); * @property {Array} [defaultConfigs] The default configs to use. * @property {Array} [ignorePatterns] The ignore patterns to use. * @property {FlatConfigObject|Array} overrideConfig The override config to use. - * @property {boolean} allowTS Indicates if TypeScript configuration files are allowed. */ //------------------------------------------------------------------------------ @@ -41,10 +40,7 @@ const { FlatConfigArray } = require("./flat-config-array"); const FLAT_CONFIG_FILENAMES = [ "eslint.config.js", "eslint.config.mjs", - "eslint.config.cjs" -]; - -const TS_FLAT_CONFIG_FILENAMES = [ + "eslint.config.cjs", "eslint.config.ts", "eslint.config.mts", "eslint.config.cts" @@ -119,10 +115,9 @@ function isRunningInDeno() { /** * Load the config array from the given filename. * @param {string} filePath The filename to load from. - * @param {boolean} allowTS Indicates if TypeScript configuration files are allowed. * @returns {Promise} The config loaded from the config file. */ -async function loadConfigFile(filePath, allowTS) { +async function loadConfigFile(filePath) { debug(`Loading config from ${filePath}`); @@ -171,7 +166,7 @@ async function loadConfigFile(filePath, allowTS) { * * When Node.js supports native TypeScript imports, we can remove this check. */ - if (allowTS && isTS && !isDeno && !isBun) { + if (isTS && !isDeno && !isBun) { // eslint-disable-next-line no-use-before-define -- `ConfigLoader.loadJiti` can be overwritten for testing const { createJiti } = await ConfigLoader.loadJiti().catch(() => { @@ -261,8 +256,7 @@ class ConfigLoader { const resultPromise = ConfigLoader.locateConfigFileToUse({ useConfigFile: this.#options.configFile, cwd: this.#options.cwd, - fromDirectory, - allowTS: this.#options.allowTS + fromDirectory }); // ensure `ConfigLoader.locateConfigFileToUse` is called only once for `fromDirectory` @@ -443,15 +437,10 @@ class ConfigLoader { * @param {string|false|undefined} options.useConfigFile The path to the config file to use. * @param {string} options.cwd Path to a directory that should be considered as the current working directory. * @param {string} [options.fromDirectory] The directory from which to start searching. Defaults to `cwd`. - * @param {boolean} options.allowTS Indicates if TypeScript configuration files are allowed. * @returns {Promise<{configFilePath:string|undefined,basePath:string}>} Location information for * the config file. */ - static async locateConfigFileToUse({ useConfigFile, cwd, fromDirectory = cwd, allowTS }) { - - const configFilenames = allowTS - ? [...FLAT_CONFIG_FILENAMES, ...TS_FLAT_CONFIG_FILENAMES] - : FLAT_CONFIG_FILENAMES; + static async locateConfigFileToUse({ useConfigFile, cwd, fromDirectory = cwd }) { // determine where to load config file from let configFilePath; @@ -464,7 +453,7 @@ class ConfigLoader { } else if (useConfigFile !== false) { debug("Searching for eslint.config.js"); configFilePath = await findUp( - configFilenames, + FLAT_CONFIG_FILENAMES, { cwd: fromDirectory } ); @@ -497,8 +486,7 @@ class ConfigLoader { ignoreEnabled, ignorePatterns, overrideConfig, - defaultConfigs = [], - allowTS + defaultConfigs = [] } = options; debug(`Calculating config array from config file ${configFilePath} and base path ${basePath}`); @@ -509,7 +497,7 @@ class ConfigLoader { if (configFilePath) { debug(`Loading config file ${configFilePath}`); - const fileConfig = await loadConfigFile(configFilePath, allowTS); + const fileConfig = await loadConfigFile(configFilePath); if (Array.isArray(fileConfig)) { configs.push(...fileConfig); @@ -618,8 +606,7 @@ class LegacyConfigLoader extends ConfigLoader { if (!this.#configFilePath) { this.#configFilePath = ConfigLoader.locateConfigFileToUse({ useConfigFile: this.#options.configFile, - cwd: this.#options.cwd, - allowTS: this.#options.allowTS + cwd: this.#options.cwd }); } diff --git a/lib/eslint/eslint.js b/lib/eslint/eslint.js index c91a376fb518..89583d53f59d 100644 --- a/lib/eslint/eslint.js +++ b/lib/eslint/eslint.js @@ -266,15 +266,13 @@ function compareResultsByFilePath(a, b) { * This function is used primarily by the `--inspect-config` option. For now, * we will maintain the existing behavior, which is to search up from the cwd. * @param {ESLintOptions} options The ESLint instance options. - * @param {boolean} allowTS `true` if the `unstable_ts_config` flag is enabled, `false` if it's not. * @returns {Promise<{configFilePath:string|undefined;basePath:string}>} Location information for * the config file. */ -async function locateConfigFileToUse({ configFile, cwd }, allowTS) { +async function locateConfigFileToUse({ configFile, cwd }) { const configLoader = new ConfigLoader({ cwd, - allowTS, configFile }); @@ -469,8 +467,7 @@ class ESLint { configFile: processedOptions.configFile, ignoreEnabled: processedOptions.ignore, ignorePatterns: processedOptions.ignorePatterns, - defaultConfigs, - allowTS: processedOptions.flags.includes("unstable_ts_config") + defaultConfigs }; this.#configLoader = processedOptions.flags.includes("unstable_config_lookup_from_file") diff --git a/lib/shared/flags.js b/lib/shared/flags.js index 70ef2c9034a2..ba2ea2504106 100644 --- a/lib/shared/flags.js +++ b/lib/shared/flags.js @@ -10,8 +10,7 @@ */ const activeFlags = new Map([ ["test_only", "Used only for testing."], - ["unstable_config_lookup_from_file", "Look up `eslint.config.js` from the file being linted."], - ["unstable_ts_config", "Enable TypeScript configuration files."] + ["unstable_config_lookup_from_file", "Look up `eslint.config.js` from the file being linted."] ]); /** @@ -19,7 +18,8 @@ const activeFlags = new Map([ * @type {Map} */ const inactiveFlags = new Map([ - ["test_only_old", "Used only for testing."] + ["test_only_old", "Used only for testing."], + ["unstable_ts_config", "This flag is no longer required to enable TypeScript configuration files."] ]); module.exports = { diff --git a/tests/fixtures/ts-config-files/helper.ts b/tests/fixtures/ts-config-files/helper.ts index 4763889adcb6..c4728b4e6ed9 100644 --- a/tests/fixtures/ts-config-files/helper.ts +++ b/tests/fixtures/ts-config-files/helper.ts @@ -4,12 +4,7 @@ * and namespaces from other TypeScript files. */ -export type RuleLevelAndOptions = Prepend< - Partial, - RuleLevel ->; - -export type StringSeverity = "off" | "warn" | "error"; +import { Linter } from "eslint"; export const enum Severity { "Off" = 0, @@ -17,29 +12,7 @@ export const enum Severity { "Error" = 2, } -export type RuleLevel = Severity | StringSeverity; - -export type RuleEntry = - | RuleLevel - | RuleLevelAndOptions; - -export interface RulesRecord { - [rule: string]: RuleEntry; -} - -export interface FlatConfig { - name?: string; - files?: Array; - ignores?: string[]; - linterOptions?: { - noInlineConfig?: boolean; - reportUnusedDisableDirectives?: Severity | StringSeverity | boolean; - }; - processor?: string; - plugins?: Record; - rules?: Partial; - settings?: Record; -} +export type FlatConfig = Linter.Config; export namespace ESLintNameSpace { export const enum StringSeverity { diff --git a/tests/lib/eslint/eslint.js b/tests/lib/eslint/eslint.js index 1c851ffea4a3..96c270e62b07 100644 --- a/tests/lib/eslint/eslint.js +++ b/tests/lib/eslint/eslint.js @@ -335,6 +335,15 @@ describe("ESLint", () => { processStub.restore(); }); + + it("should throw an error if the flag 'unstable_ts_config' is used", () => { + assert.throws( + () => new ESLint({ + flags: [...flags, "unstable_ts_config"] + }), + { message: "The flag 'unstable_ts_config' is inactive: This flag is no longer required to enable TypeScript configuration files." } + ); + }); }); describe("hasFlag", () => { @@ -1107,15 +1116,13 @@ describe("ESLint", () => { describe("TypeScript config files", () => { - const tsFlags = ["unstable_ts_config", ...flags]; - it("should find and load eslint.config.ts when present", async () => { const cwd = getFixturePath("ts-config-files", "ts"); eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo"); @@ -1133,7 +1140,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo"); @@ -1151,7 +1158,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo"); @@ -1169,7 +1176,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo"); @@ -1187,7 +1194,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo"); @@ -1205,7 +1212,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags, + flags, overrideConfigFile: getFixturePath("ts-config-files", "ts", "custom-config", "eslint.custom.config.ts") }); @@ -1224,7 +1231,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo"); @@ -1242,7 +1249,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo"); @@ -1260,7 +1267,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo"); @@ -1278,7 +1285,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo"); @@ -1296,7 +1303,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo"); @@ -1314,7 +1321,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo"); @@ -1332,7 +1339,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); const results = await eslint.lintText("foo;"); @@ -1354,7 +1361,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); await assert.rejects( @@ -1373,7 +1380,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags + flags }); await assert.rejects( @@ -1388,7 +1395,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: tsFlags, + flags, overrideConfigFile: "eslint.undefined.config.ts" }); @@ -4878,15 +4885,13 @@ describe("ESLint", () => { const typeCommonJS = JSON.stringify({ type: "commonjs" }, null, 2); - const newFlags = flags.concat("unstable_ts_config"); - it("should find and load eslint.config.ts when present", async () => { const cwd = getFixturePath("ts-config-files", "ts"); eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles("foo.js"); @@ -4905,7 +4910,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles("foo.js"); @@ -4924,7 +4929,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles("foo.js"); @@ -4959,7 +4964,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -4994,7 +4999,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5029,7 +5034,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5064,7 +5069,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5099,7 +5104,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5135,7 +5140,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5171,7 +5176,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5207,7 +5212,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5243,7 +5248,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5279,7 +5284,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5313,7 +5318,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5347,7 +5352,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5381,7 +5386,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5415,7 +5420,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5452,7 +5457,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5489,7 +5494,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5523,7 +5528,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5557,7 +5562,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5591,7 +5596,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5625,7 +5630,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5659,7 +5664,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5693,7 +5698,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo.js"]); @@ -5713,7 +5718,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles("foo.js"); @@ -5732,7 +5737,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles("foo.js"); @@ -5753,7 +5758,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags, + flags, overrideConfigFile }); @@ -5773,7 +5778,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles("foo.js"); @@ -5792,7 +5797,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles("foo.js"); @@ -5811,7 +5816,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles("foo.js"); @@ -5830,7 +5835,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles("foo.js"); @@ -5849,7 +5854,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles("foo.js"); @@ -5868,7 +5873,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles("foo.js"); @@ -5904,7 +5909,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, overrideConfigFile: "eslint.config.mcts", - flags: newFlags + flags }); assert.strictEqual(await eslint.findConfigFile(), path.join(cwd, "eslint.config.mcts")); @@ -5912,42 +5917,13 @@ describe("ESLint", () => { }); - it("should not load TS config files when `\"unstable_ts_config\"` flag is not set", async () => { - - const cwd = getFixturePath("ts-config-files", "ts"); - - eslint = new ESLint({ - cwd, - flags, - overrideConfigFile: "eslint.config.ts" - }); - - assert.strictEqual(await eslint.findConfigFile(), path.join(cwd, "eslint.config.ts")); - await assert.rejects(() => eslint.lintFiles(["foo.js"])); - - }); - - it("should fallback to JS config files when `\"unstable_ts_config\"` flag is not set", async () => { - - const cwd = getFixturePath("ts-config-files", "ts"); - - eslint = new ESLint({ - cwd, - flags - }); - - assert.strictEqual(await eslint.findConfigFile(), path.join(cwd, "../../eslint.config.js")); - await assert.doesNotReject(() => eslint.lintFiles(["foo.js"])); - - }); - it("should successfully load a TS config file that exports a promise", async () => { const cwd = getFixturePath("ts-config-files", "ts", "exports-promise"); eslint = new ESLint({ cwd, - flags: newFlags + flags }); const results = await eslint.lintFiles(["foo*.js"]); @@ -5971,7 +5947,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); await assert.rejects( @@ -5990,7 +5966,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags + flags }); await assert.rejects( @@ -6005,7 +5981,7 @@ describe("ESLint", () => { eslint = new ESLint({ cwd, - flags: newFlags, + flags, overrideConfigFile: "eslint.undefined.config.ts" }); @@ -8503,7 +8479,7 @@ describe("ESLint", () => { await teardown.prepare(); - let eslint = new ESLint({ cwd, flags: ["unstable_ts_config"] }); + let eslint = new ESLint({ flags, cwd }); let [{ messages }] = await eslint.lintFiles(["a.js"]); assert.strictEqual(messages.length, 1); @@ -8514,7 +8490,7 @@ describe("ESLint", () => { await sleep(100); await fsp.writeFile(path.join(cwd, "eslint.config.ts"), configFileContent.replace("always", "never")); - eslint = new ESLint({ cwd, flags: ["unstable_ts_config"] }); + eslint = new ESLint({ flags, cwd }); [{ messages }] = await eslint.lintFiles(["a.js"]); assert.strictEqual(messages.length, 1); From eff7c5721c101975a03e7906905f1fe2c9538df0 Mon Sep 17 00:00:00 2001 From: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> Date: Sat, 28 Dec 2024 22:09:14 +0530 Subject: [PATCH 13/51] docs: add limitation section in `no-loop-func` (#19287) * docs: add limitation in no-loop-func * fix heading --- docs/src/rules/no-loop-func.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/src/rules/no-loop-func.md b/docs/src/rules/no-loop-func.md index 7d79eda106af..356804c0ada3 100644 --- a/docs/src/rules/no-loop-func.md +++ b/docs/src/rules/no-loop-func.md @@ -140,3 +140,20 @@ for (var i = 0; i < 5; i++) { ``` ::: + +## Known Limitations + +The rule cannot identify whether the function instance is just immediately invoked and then discarded, or possibly stored for later use. + +```js +const foo = [1, 2, 3, 4]; +var i = 0; + +while(foo.some(e => e > i)){ + i += 1; +} +``` + +Here the `some` method immediately executes the callback function for each element in the array and then discards the function instance. The function is not stored or reused beyond the scope of the loop iteration. So, this will work as intended. + +`eslint-disable` comments can be used in such cases. From 8c07ebb9004309f8691f972d554e8bbb3eb517bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Sun, 29 Dec 2024 03:28:59 +0900 Subject: [PATCH 14/51] docs: add `border-radius` to `hX:target` selector styles (#19270) * chore: add `border-radius` to `hX:target` selector styles * style: add padding to heading elements --- docs/src/assets/scss/foundations.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/assets/scss/foundations.scss b/docs/src/assets/scss/foundations.scss index 68e44651f4fb..5d07a6de03a8 100644 --- a/docs/src/assets/scss/foundations.scss +++ b/docs/src/assets/scss/foundations.scss @@ -10,6 +10,7 @@ h4:target, h5:target, h6:target { background-color: var(--lighter-background-color); + border-radius: var(--border-radius); } *:focus { @@ -363,6 +364,7 @@ h6 { font-weight: 500; margin-top: 0; margin-block-start: 0; + padding: 0.25rem 0; } h2, From da768d4541c4c30bfc33640a07a8d8a485520b18 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Sun, 29 Dec 2024 14:39:23 +0100 Subject: [PATCH 15/51] fix: correct `overrideConfigFile` type (#19289) --- lib/types/index.d.ts | 2 +- tests/lib/types/types.test.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index 1576548f5d25..b86ac2caae93 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -1484,7 +1484,7 @@ export namespace ESLint { allowInlineConfig?: boolean | undefined; baseConfig?: Linter.Config | Linter.Config[] | null | undefined; overrideConfig?: Linter.Config | Linter.Config[] | null | undefined; - overrideConfigFile?: string | boolean | undefined; + overrideConfigFile?: string | true | null | undefined; plugins?: Record | null | undefined; ruleFilter?: ((arg: { ruleId: string; severity: Exclude }) => boolean) | undefined; stats?: boolean | undefined; diff --git a/tests/lib/types/types.test.ts b/tests/lib/types/types.test.ts index 5ece3df0a5a4..bc4d268beea6 100644 --- a/tests/lib/types/types.test.ts +++ b/tests/lib/types/types.test.ts @@ -927,8 +927,6 @@ linterWithEslintrcConfig.getRules(); eslint = new ESLint(); eslint = new ESLint({ allowInlineConfig: false }); eslint = new ESLint({ baseConfig: {} }); - eslint = new ESLint({ overrideConfig: {} }); - eslint = new ESLint({ overrideConfigFile: "foo" }); eslint = new ESLint({ cache: true }); eslint = new ESLint({ cacheLocation: "foo" }); eslint = new ESLint({ cacheStrategy: "content" }); @@ -941,6 +939,14 @@ linterWithEslintrcConfig.getRules(); eslint = new ESLint({ globInputPaths: true }); eslint = new ESLint({ ignore: true }); eslint = new ESLint({ ignorePatterns: ["foo", "bar"] }); + eslint = new ESLint({ overrideConfig: {} }); + + eslint = new ESLint({ overrideConfigFile: "foo" }); + eslint = new ESLint({ overrideConfigFile: true }); + eslint = new ESLint({ overrideConfigFile: null }); + // @ts-expect-error `overrideConfigFile` cannot be `false` + eslint = new ESLint({ overrideConfigFile: false }); + eslint = new ESLint({ plugins: { foo: {} } }); eslint = new ESLint({ ruleFilter({ severity }) { From 0367a70a43346f1b9df8be75d38f98f9cfe4007c Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Sun, 29 Dec 2024 15:12:48 +0100 Subject: [PATCH 16/51] docs: update custom parser docs (#19288) --- docs/src/extend/custom-parsers.md | 32 ++++++++++++++++++++++++++++--- docs/src/extend/ways-to-extend.md | 2 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/docs/src/extend/custom-parsers.md b/docs/src/extend/custom-parsers.md index f9cbb9f08726..80b08eea2f3d 100644 --- a/docs/src/extend/custom-parsers.md +++ b/docs/src/extend/custom-parsers.md @@ -121,14 +121,29 @@ Once you've published the npm package, you can use it by adding the package to y npm install eslint-parser-myparser --save-dev ``` -Then add the custom parser to your ESLint configuration file with the `parser` property. For example: +Then add the custom parser to your ESLint configuration file with the `languageOptions.parser` property. For example: + +```js +// eslint.config.js + +const myparser = require("eslint-parser-myparser"); + +module.exports = [{ + languageOptions: { + parser: myparser + }, + // ... rest of configuration +}]; +``` + +When using legacy configuration, specify the `parser` property as a string: ```js // .eslintrc.js module.exports = { - parser: 'eslint-parser-myparser', - // ... rest of configuration + parser: "eslint-parser-myparser", + // ... rest of configuration }; ``` @@ -161,6 +176,17 @@ module.exports = { parseForESLint }; Include the custom parser in an ESLint configuration file: +```js +// eslint.config.js +module.exports = [{ + languageOptions: { + parser: require("./path/to/awesome-custom-parser") + } +}]; +``` + +Or if using legacy configuration: + ```js // .eslintrc.json { diff --git a/docs/src/extend/ways-to-extend.md b/docs/src/extend/ways-to-extend.md index 3bf8314e1afa..2684d340974a 100644 --- a/docs/src/extend/ways-to-extend.md +++ b/docs/src/extend/ways-to-extend.md @@ -55,6 +55,6 @@ ESLint ships with a built-in JavaScript parser (Espree), but custom parsers allo For example, the custom parser [@typescript-eslint/parser](https://typescript-eslint.io/packages/parser) extends ESLint to lint TypeScript code. -Custom parsers **cannot** be included in a plugin, unlike the other extension types. +Custom parsers can be also included in a plugin. To learn more about creating a custom parser, refer to [Custom Parsers](custom-parsers). From d122c8a756bb8e232ef7c25cca6dcae645094835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Tue, 31 Dec 2024 02:48:36 +0900 Subject: [PATCH 17/51] docs: add missing backticks to `sort-imports` (#19282) * docs: add missing backticks to `sort-imports` * wip --- docs/src/_data/rules_meta.json | 2 +- docs/src/rules/sort-imports.md | 8 ++++---- lib/rules/sort-imports.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/src/_data/rules_meta.json b/docs/src/_data/rules_meta.json index 4eede7a53cd6..97fe8d775175 100644 --- a/docs/src/_data/rules_meta.json +++ b/docs/src/_data/rules_meta.json @@ -2894,7 +2894,7 @@ } ], "docs": { - "description": "Enforce sorted import declarations within modules", + "description": "Enforce sorted `import` declarations within modules", "recommended": false, "frozen": true, "url": "https://eslint.org/docs/latest/rules/sort-imports" diff --git a/docs/src/rules/sort-imports.md b/docs/src/rules/sort-imports.md index fa284593207a..6d59e89a56a9 100644 --- a/docs/src/rules/sort-imports.md +++ b/docs/src/rules/sort-imports.md @@ -8,7 +8,7 @@ related_rules: -The import statement is used to import members (functions, objects or primitives) that have been exported from an external module. Using a specific member syntax: +The `import` statement is used to import members (functions, objects or primitives) that have been exported from an external module. Using a specific member syntax: ```js // single - Import single member. @@ -22,18 +22,18 @@ import {foo, bar} from "my-module.js"; import * as myModule from "my-module.js"; ``` -The import statement can also import a module without exported bindings. Used when the module does not export anything, but runs it own code or changes the global context object. +The `import` statement can also import a module without exported bindings. Used when the module does not export anything, but runs it own code or changes the global context object. ```js // none - Import module without exported bindings. import "my-module.js" ``` -When declaring multiple imports, a sorted list of import declarations make it easier for developers to read the code and find necessary imports later. This rule is purely a matter of style. +When declaring multiple imports, a sorted list of `import` declarations make it easier for developers to read the code and find necessary imports later. This rule is purely a matter of style. ## Rule Details -This rule checks all import declarations and verifies that all imports are first sorted by the used member syntax and then alphabetically by the first member or alias name. +This rule checks all `import` declarations and verifies that all imports are first sorted by the used member syntax and then alphabetically by the first member or alias name. The `--fix` option on the command line automatically fixes some problems reported by this rule: multiple members on a single line are automatically sorted (e.g. `import { b, a } from 'foo.js'` is corrected to `import { a, b } from 'foo.js'`), but multiple lines are not reordered. diff --git a/lib/rules/sort-imports.js b/lib/rules/sort-imports.js index fe3ddac2d156..b355da982775 100644 --- a/lib/rules/sort-imports.js +++ b/lib/rules/sort-imports.js @@ -1,5 +1,5 @@ /** - * @fileoverview Rule to require sorting of import declarations + * @fileoverview Rule to enforce sorted `import` declarations within modules * @author Christian Schuller */ @@ -23,7 +23,7 @@ module.exports = { }], docs: { - description: "Enforce sorted import declarations within modules", + description: "Enforce sorted `import` declarations within modules", recommended: false, frozen: true, url: "https://eslint.org/docs/latest/rules/sort-imports" From b36ca0a490829c579358ec7193bde35275000e04 Mon Sep 17 00:00:00 2001 From: Amaresh S M Date: Tue, 31 Dec 2024 03:31:59 +0530 Subject: [PATCH 18/51] docs: Fixing Focus Order by Rearranging Element Sequence (#19241) * chore: Fixing Focus Order by Rearranging Element Sequence * hide results on focus --- docs/src/_includes/components/search.html | 18 ++++++++++-------- docs/src/assets/js/search.js | 7 +++++++ docs/src/assets/scss/components/search.scss | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/src/_includes/components/search.html b/docs/src/_includes/components/search.html index 37a71361dddb..9635900f7529 100644 --- a/docs/src/_includes/components/search.html +++ b/docs/src/_includes/components/search.html @@ -9,11 +9,18 @@

Results will be shown and updated as you type.

+
+
- Powered by + Powered by
- +
-
+ diff --git a/docs/src/assets/js/search.js b/docs/src/assets/js/search.js index a7d0225c3011..3fc6e65578cf 100644 --- a/docs/src/assets/js/search.js +++ b/docs/src/assets/js/search.js @@ -22,6 +22,7 @@ const resultsElement = document.querySelector('#search-results'); const resultsLiveRegion = document.querySelector('#search-results-announcement'); const searchInput = document.querySelector('#search'); const searchClearBtn = document.querySelector('#search__clear-btn'); +const poweredByLink = document.querySelector('.search_powered-by-wrapper'); let activeIndex = -1; let searchQuery; @@ -210,6 +211,12 @@ if (searchClearBtn) searchClearBtn.setAttribute('hidden', ''); }); +if (poweredByLink) { + poweredByLink.addEventListener('focus', function () { + clearSearchResults(); + }); +} + document.addEventListener('keydown', function (e) { const searchResults = Array.from(document.querySelectorAll('.search-results__item')); diff --git a/docs/src/assets/scss/components/search.scss b/docs/src/assets/scss/components/search.scss index 0ab8138861a3..4d633956970a 100644 --- a/docs/src/assets/scss/components/search.scss +++ b/docs/src/assets/scss/components/search.scss @@ -74,7 +74,7 @@ padding: 10px 6px 0 0; align-items: center; - .powered-by-text { + .powered_by-text { color: var(--body-text-color); margin-right: 5px; margin-top: -2px; From eec01f04ae1c44f7c9a8c6afec59dd72f5a57600 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Tue, 31 Dec 2024 14:00:03 +0100 Subject: [PATCH 19/51] docs: switch rule examples config format to `languageOptions` (#19277) * docs: switch rule examples config format to `languageOptions` * revert trailing spaces * mark languageOptions as possibly undefined in callbacks --- docs/.eleventy.js | 8 ++++---- docs/src/rules/jsx-quotes.md | 8 ++++---- docs/src/rules/keyword-spacing.md | 4 ++-- docs/src/rules/no-extra-parens.md | 10 +++++----- docs/src/rules/no-inline-comments.md | 4 ++-- docs/src/rules/no-irregular-whitespace.md | 2 +- docs/src/rules/no-unused-expressions.md | 4 ++-- docs/src/rules/space-before-keywords.md | 2 +- docs/tools/markdown-it-rule-example.js | 14 +++++++------- docs/tools/prism-eslint-hook.js | 14 +++++++------- tests/fixtures/good-examples.md | 2 +- tools/check-rule-examples.js | 22 ++++++++++++++-------- 12 files changed, 50 insertions(+), 44 deletions(-) diff --git a/docs/.eleventy.js b/docs/.eleventy.js index c526abae509c..caebabcab639 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -197,9 +197,9 @@ module.exports = function(eleventyConfig) { // markdown-it plugin options for playground-linked code blocks in rule examples. const ruleExampleOptions = markdownItRuleExample({ - open({ type, code, parserOptions, env, codeBlockToken }) { + open({ type, code, languageOptions, env, codeBlockToken }) { - prismESLintHook.addContentMustBeMarked(codeBlockToken.content, parserOptions); + prismESLintHook.addContentMustBeMarked(codeBlockToken.content, languageOptions); const isRuleRemoved = !Object.hasOwn(env.rules_meta, env.title); @@ -207,10 +207,10 @@ module.exports = function(eleventyConfig) { return `
`; } - // See https://github.com/eslint/eslint.org/blob/ac38ab41f99b89a8798d374f74e2cce01171be8b/src/playground/App.js#L44 + // See https://github.com/eslint/eslint.org/blob/29e1d8a000592245e4a30c1996e794643e9b263a/src/playground/App.js#L91-L105 const state = encodeToBase64( JSON.stringify({ - options: { parserOptions }, + options: languageOptions ? { languageOptions } : void 0, text: code }) ); diff --git a/docs/src/rules/jsx-quotes.md b/docs/src/rules/jsx-quotes.md index 25ea1295dc64..41e145302e57 100644 --- a/docs/src/rules/jsx-quotes.md +++ b/docs/src/rules/jsx-quotes.md @@ -37,7 +37,7 @@ This rule has a string option: Examples of **incorrect** code for this rule with the default `"prefer-double"` option: -:::incorrect { "ecmaFeatures": { "jsx": true } } +:::incorrect { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /*eslint jsx-quotes: ["error", "prefer-double"]*/ @@ -49,7 +49,7 @@ Examples of **incorrect** code for this rule with the default `"prefer-double"` Examples of **correct** code for this rule with the default `"prefer-double"` option: -:::correct { "ecmaFeatures": { "jsx": true } } +:::correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /*eslint jsx-quotes: ["error", "prefer-double"]*/ @@ -64,7 +64,7 @@ Examples of **correct** code for this rule with the default `"prefer-double"` op Examples of **incorrect** code for this rule with the `"prefer-single"` option: -:::incorrect { "ecmaFeatures": { "jsx": true } } +:::incorrect { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /*eslint jsx-quotes: ["error", "prefer-single"]*/ @@ -76,7 +76,7 @@ Examples of **incorrect** code for this rule with the `"prefer-single"` option: Examples of **correct** code for this rule with the `"prefer-single"` option: -:::correct { "ecmaFeatures": { "jsx": true } } +:::correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /*eslint jsx-quotes: ["error", "prefer-single"]*/ diff --git a/docs/src/rules/keyword-spacing.md b/docs/src/rules/keyword-spacing.md index e6c485a75af7..ba278295da8a 100644 --- a/docs/src/rules/keyword-spacing.md +++ b/docs/src/rules/keyword-spacing.md @@ -58,7 +58,7 @@ if (foo) { Examples of **correct** code for this rule with the default `{ "before": true }` option: -::: correct { "ecmaFeatures": { "jsx": true } } +::: correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /*eslint keyword-spacing: ["error", { "before": true }]*/ @@ -172,7 +172,7 @@ if(foo) { Examples of **correct** code for this rule with the default `{ "after": true }` option: -::: correct { "ecmaFeatures": { "jsx": true } } +::: correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /*eslint keyword-spacing: ["error", { "after": true }]*/ diff --git a/docs/src/rules/no-extra-parens.md b/docs/src/rules/no-extra-parens.md index 3685d88b7932..851107ceb1fb 100644 --- a/docs/src/rules/no-extra-parens.md +++ b/docs/src/rules/no-extra-parens.md @@ -212,7 +212,7 @@ foo ? bar : (baz || qux); Examples of **correct** code for this rule with the `all` and `{ "ignoreJSX": "all" }` options: -::: correct { "ecmaFeatures": { "jsx": true } } +::: correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /* eslint no-extra-parens: ["error", "all", { ignoreJSX: "all" }] */ @@ -228,7 +228,7 @@ const ThatComponent = ( Examples of **incorrect** code for this rule with the `all` and `{ "ignoreJSX": "multi-line" }` options: -::: incorrect { "ecmaFeatures": { "jsx": true } } +::: incorrect { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /* eslint no-extra-parens: ["error", "all", { ignoreJSX: "multi-line" }] */ @@ -240,7 +240,7 @@ const ThatComponent = (

) Examples of **correct** code for this rule with the `all` and `{ "ignoreJSX": "multi-line" }` options: -::: correct { "ecmaFeatures": { "jsx": true } } +::: correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /* eslint no-extra-parens: ["error", "all", { ignoreJSX: "multi-line" }] */ @@ -260,7 +260,7 @@ const ThatComponent = ( Examples of **incorrect** code for this rule with the `all` and `{ "ignoreJSX": "single-line" }` options: -::: incorrect { "ecmaFeatures": { "jsx": true } } +::: incorrect { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /* eslint no-extra-parens: ["error", "all", { ignoreJSX: "single-line" }] */ @@ -280,7 +280,7 @@ const ThatComponent = ( Examples of **correct** code for this rule with the `all` and `{ "ignoreJSX": "single-line" }` options: -::: correct { "ecmaFeatures": { "jsx": true } } +::: correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /* eslint no-extra-parens: ["error", "all", { ignoreJSX: "single-line" }] */ diff --git a/docs/src/rules/no-inline-comments.md b/docs/src/rules/no-inline-comments.md index d6a32db4e47b..548ac746eb94 100644 --- a/docs/src/rules/no-inline-comments.md +++ b/docs/src/rules/no-inline-comments.md @@ -54,7 +54,7 @@ Comments inside the curly braces in JSX are allowed to be on the same line as th Examples of **incorrect** code for this rule: -::: incorrect { "ecmaFeatures": { "jsx": true } } +::: incorrect { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /*eslint no-inline-comments: "error"*/ @@ -74,7 +74,7 @@ var bar = ( Examples of **correct** code for this rule: -::: correct { "ecmaFeatures": { "jsx": true } } +::: correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /*eslint no-inline-comments: "error"*/ diff --git a/docs/src/rules/no-irregular-whitespace.md b/docs/src/rules/no-irregular-whitespace.md index eb0086f57ab4..8fb3f3fac49c 100644 --- a/docs/src/rules/no-irregular-whitespace.md +++ b/docs/src/rules/no-irregular-whitespace.md @@ -202,7 +202,7 @@ function thing() { Examples of additional **correct** code for this rule with the `{ "skipJSXText": true }` option: -::: correct { "ecmaFeatures": { "jsx": true } } +::: correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /*eslint no-irregular-whitespace: ["error", { "skipJSXText": true }]*/ diff --git a/docs/src/rules/no-unused-expressions.md b/docs/src/rules/no-unused-expressions.md index 52379726dcea..939f5f66f8a2 100644 --- a/docs/src/rules/no-unused-expressions.md +++ b/docs/src/rules/no-unused-expressions.md @@ -251,7 +251,7 @@ JSX is most-commonly used in the React ecosystem, where it is compiled to `React Examples of **incorrect** code for the `{ "enforceForJSX": true }` option: -::: incorrect { "ecmaFeatures": { "jsx": true } } +::: incorrect { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /*eslint no-unused-expressions: ["error", { "enforceForJSX": true }]*/ @@ -265,7 +265,7 @@ Examples of **incorrect** code for the `{ "enforceForJSX": true }` option: Examples of **correct** code for the `{ "enforceForJSX": true }` option: -::: correct { "ecmaFeatures": { "jsx": true } } +::: correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx /*eslint no-unused-expressions: ["error", { "enforceForJSX": true }]*/ diff --git a/docs/src/rules/space-before-keywords.md b/docs/src/rules/space-before-keywords.md index 7d969d2c83d8..01c1ac85a68b 100644 --- a/docs/src/rules/space-before-keywords.md +++ b/docs/src/rules/space-before-keywords.md @@ -67,7 +67,7 @@ function bar() { Examples of **correct** code for this rule with the default `"always"` option: -::: correct { "ecmaFeatures": { "jsx": true } } +::: correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```js /*eslint space-before-keywords: ["error", "always"]*/ diff --git a/docs/tools/markdown-it-rule-example.js b/docs/tools/markdown-it-rule-example.js index a769b120db52..7b95e3c4c644 100644 --- a/docs/tools/markdown-it-rule-example.js +++ b/docs/tools/markdown-it-rule-example.js @@ -2,7 +2,7 @@ const { docsExampleCodeToParsableCode } = require("./code-block-utils"); -/** @typedef {import("../../lib/shared/types").ParserOptions} ParserOptions */ +/** @typedef {import("../../lib/shared/types").LanguageOptions} LanguageOptions */ /** * A callback function to handle the opening of container blocks. @@ -10,7 +10,7 @@ const { docsExampleCodeToParsableCode } = require("./code-block-utils"); * @param {Object} data Callback data. * @param {"correct" | "incorrect"} data.type The type of the example. * @param {string} data.code The example code. - * @param {ParserOptions} data.parserOptions The parser options to be passed to the Playground. + * @param {LanguageOptions | undefined} data.languageOptions The language options to be passed to the Playground. * @param {Object} data.codeBlockToken The `markdown-it` token for the code block inside the container. * @param {Object} data.env Additional Eleventy metadata, if available. * @returns {string | undefined} If a text is returned, it will be appended to the rendered output @@ -31,7 +31,7 @@ const { docsExampleCodeToParsableCode } = require("./code-block-utils"); * * - Ensure that the plugin instance only matches container blocks tagged with 'correct' or * 'incorrect'. - * - Parse the optional `parserOptions` after the correct/incorrect tag. + * - Parse the optional `languageOptions` after the correct/incorrect tag. * - Apply common transformations to the code inside the code block, like stripping '⏎' at the end * of a line or the last newline character. * @@ -47,7 +47,7 @@ const { docsExampleCodeToParsableCode } = require("./code-block-utils"); * * markdownIt() * .use(markdownItContainer, "rule-example", markdownItRuleExample({ - * open({ type, code, parserOptions, codeBlockToken, env }) { + * open({ type, code, languageOptions, codeBlockToken, env }) { * // do something * } * close() { @@ -72,14 +72,14 @@ function markdownItRuleExample({ open, close }) { return typeof text === "string" ? text : ""; } - const { type, parserOptionsJSON } = /^\s*(?\S+)(\s+(?\S.*?))?\s*$/u.exec(tagToken.info).groups; - const parserOptions = { sourceType: "module", ...(parserOptionsJSON && JSON.parse(parserOptionsJSON)) }; + const { type, languageOptionsJSON } = /^\s*(?\S+)(\s+(?\S.*?))?\s*$/u.exec(tagToken.info).groups; + const languageOptions = languageOptionsJSON ? JSON.parse(languageOptionsJSON) : void 0; const codeBlockToken = tokens[index + 1]; // Remove trailing newline and presentational `⏎` characters (https://github.com/eslint/eslint/issues/17627): const code = docsExampleCodeToParsableCode(codeBlockToken.content); - const text = open({ type, code, parserOptions, codeBlockToken, env }); + const text = open({ type, code, languageOptions, codeBlockToken, env }); // Return an empty string to avoid appending unexpected text to the output. return typeof text === "string" ? text : ""; diff --git a/docs/tools/prism-eslint-hook.js b/docs/tools/prism-eslint-hook.js index 74dd5197ceae..bbbe764c9d6a 100644 --- a/docs/tools/prism-eslint-hook.js +++ b/docs/tools/prism-eslint-hook.js @@ -27,7 +27,7 @@ try { // ignore } -/** @typedef {import("../../lib/shared/types").ParserOptions} ParserOptions */ +/** @typedef {import("../../lib/shared/types").LanguageOptions} LanguageOptions */ /** * Content that needs to be marked with ESLint @@ -37,19 +37,19 @@ let contentMustBeMarked; /** * Parser options received from the `::: incorrect` or `::: correct` container. - * @type {ParserOptions|undefined} + * @type {LanguageOptions|undefined} */ -let contentParserOptions; +let contentLanguageOptions; /** * Set content that needs to be marked. * @param {string} content Source code content that marks ESLint errors. - * @param {ParserOptions} options The options used for validation. + * @param {LanguageOptions} options The options used for validation. * @returns {void} */ function addContentMustBeMarked(content, options) { contentMustBeMarked = content; - contentParserOptions = options; + contentLanguageOptions = options; } /** @@ -113,7 +113,7 @@ function installPrismESLintMarkerHook() { return; } contentMustBeMarked = void 0; - const parserOptions = contentParserOptions; + const config = contentLanguageOptions ? { languageOptions: contentLanguageOptions } : {}; const code = env.code; @@ -148,7 +148,7 @@ function installPrismESLintMarkerHook() { // Remove trailing newline and presentational `⏎` characters docsExampleCodeToParsableCode(code), - { languageOptions: { sourceType: parserOptions.sourceType, parserOptions } }, + config, { filename: "code.js" } ); diff --git a/tests/fixtures/good-examples.md b/tests/fixtures/good-examples.md index eaed65d3d046..fcb7d95cd4e8 100644 --- a/tests/fixtures/good-examples.md +++ b/tests/fixtures/good-examples.md @@ -9,7 +9,7 @@ export default⏎ ::: -::: correct { "ecmaFeatures": { "jsx": true } } +::: correct { "parserOptions": { "ecmaFeatures": { "jsx": true } } } ```jsx const foo = ; diff --git a/tools/check-rule-examples.js b/tools/check-rule-examples.js index b2c9cd0a9900..e04447802921 100644 --- a/tools/check-rule-examples.js +++ b/tools/check-rule-examples.js @@ -21,7 +21,7 @@ const { LATEST_ECMA_VERSION } = require("../conf/ecma-version"); /** @typedef {import("../lib/shared/types").LintMessage} LintMessage */ /** @typedef {import("../lib/shared/types").LintResult} LintResult */ -/** @typedef {import("../lib/shared/types").ParserOptions} ParserOptions */ +/** @typedef {import("../lib/shared/types").LanguageOptions} LanguageOptions */ //------------------------------------------------------------------------------ // Helpers @@ -40,12 +40,18 @@ const commentParser = new ConfigCommentParser(); /** * Tries to parse a specified JavaScript code with Playground presets. * @param {string} code The JavaScript code to parse. - * @param {ParserOptions} parserOptions Explicitly specified parser options. + * @param {LanguageOptions} [languageOptions] Explicitly specified language options. * @returns {{ ast: ASTNode } | { error: SyntaxError }} An AST with comments, or a `SyntaxError` object if the code cannot be parsed. */ -function tryParseForPlayground(code, parserOptions) { +function tryParseForPlayground(code, languageOptions) { try { - const ast = parse(code, { ecmaVersion: "latest", ...parserOptions, comment: true, loc: true }); + const ast = parse(code, { + ecmaVersion: languageOptions?.ecmaVersion ?? "latest", + sourceType: languageOptions?.sourceType ?? "module", + ...languageOptions?.parserOptions, + comment: true, + loc: true + }); return { ast }; } catch (error) { @@ -64,7 +70,7 @@ async function findProblems(filename) { const isRuleRemoved = !rules.has(title); const problems = []; const ruleExampleOptions = markdownItRuleExample({ - open({ code, parserOptions, codeBlockToken }) { + open({ code, languageOptions, codeBlockToken }) { const languageTag = codeBlockToken.info; if (!STANDARD_LANGUAGE_TAGS.has(languageTag)) { @@ -86,8 +92,8 @@ async function findProblems(filename) { }); } - if (parserOptions && typeof parserOptions.ecmaVersion !== "undefined") { - const { ecmaVersion } = parserOptions; + if (typeof languageOptions?.ecmaVersion !== "undefined") { + const { ecmaVersion } = languageOptions; let ecmaVersionErrorMessage; if (ecmaVersion === "latest") { @@ -109,7 +115,7 @@ async function findProblems(filename) { } } - const { ast, error } = tryParseForPlayground(code, parserOptions); + const { ast, error } = tryParseForPlayground(code, languageOptions); if (ast) { let hasRuleConfigComment = false; From 5d64851955f410f31c159a7097f6cc7d4a01d6a1 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Tue, 31 Dec 2024 18:15:47 +0100 Subject: [PATCH 20/51] docs: remove outdated info about environments (#19296) --- docs/src/rules/no-global-assign.md | 3 +-- docs/src/rules/no-implicit-globals.md | 7 ++----- docs/src/rules/no-native-reassign.md | 3 +-- docs/src/rules/no-restricted-globals.md | 2 +- docs/src/rules/no-unused-vars.md | 5 ++--- docs/src/rules/strict.md | 3 ++- docs/src/use/configure/index.md | 2 +- docs/src/use/core-concepts/index.md | 2 +- 8 files changed, 11 insertions(+), 16 deletions(-) diff --git a/docs/src/rules/no-global-assign.md b/docs/src/rules/no-global-assign.md index 9791b0bba375..d0d057c55ed9 100644 --- a/docs/src/rules/no-global-assign.md +++ b/docs/src/rules/no-global-assign.md @@ -23,8 +23,7 @@ This rule disallows modifications to read-only global variables. ESLint has the capability to configure global variables as read-only. -* [Specifying Environments](../use/configure#specifying-environments) -* [Specifying Globals](../use/configure#specifying-globals) +See also: [Specifying Globals](../use/configure#specifying-globals) Examples of **incorrect** code for this rule: diff --git a/docs/src/rules/no-implicit-globals.md b/docs/src/rules/no-implicit-globals.md index 63a65e98a964..3cba52615f3a 100644 --- a/docs/src/rules/no-implicit-globals.md +++ b/docs/src/rules/no-implicit-globals.md @@ -118,12 +118,9 @@ Bar.prototype.baz = function () { This rule also disallows redeclarations of read-only global variables and assignments to read-only global variables. -A read-only global variable can be a built-in ES global (e.g. `Array`), an environment specific global -(e.g. `window` in the browser environment), or a global variable defined as `readonly` in the configuration file -or in a `/*global */` comment. +A read-only global variable can be a built-in ES global (e.g. `Array`), or a global variable defined as `readonly` in the configuration file or in a `/*global */` comment. -* [Specifying Environments](../use/configure#specifying-environments) -* [Specifying Globals](../use/configure#specifying-globals) +See also: [Specifying Globals](../use/configure#specifying-globals) Examples of **incorrect** code for this rule: diff --git a/docs/src/rules/no-native-reassign.md b/docs/src/rules/no-native-reassign.md index 2ec916404b6f..a7ae558968d4 100644 --- a/docs/src/rules/no-native-reassign.md +++ b/docs/src/rules/no-native-reassign.md @@ -24,8 +24,7 @@ This rule disallows modifications to read-only global variables. ESLint has the capability to configure global variables as read-only. -* [Specifying Environments](../use/configure#specifying-environments) -* [Specifying Globals](../use/configure#specifying-globals) +See also: [Specifying Globals](../use/configure#specifying-globals) Examples of **incorrect** code for this rule: diff --git a/docs/src/rules/no-restricted-globals.md b/docs/src/rules/no-restricted-globals.md index 58a4ad008171..7a8ab46e25fb 100644 --- a/docs/src/rules/no-restricted-globals.md +++ b/docs/src/rules/no-restricted-globals.md @@ -8,7 +8,7 @@ related_rules: Disallowing usage of specific global variables can be useful if you want to allow a set of global -variables by enabling an environment, but still want to disallow some of those. +variables, but still want to disallow some of those. For instance, early Internet Explorer versions exposed the current DOM event as a global variable `event`, but using this variable has been considered as a bad practice for a long time. Restricting diff --git a/docs/src/rules/no-unused-vars.md b/docs/src/rules/no-unused-vars.md index f66487f4fdb4..54504ac35ed5 100644 --- a/docs/src/rules/no-unused-vars.md +++ b/docs/src/rules/no-unused-vars.md @@ -103,9 +103,8 @@ In environments outside of CommonJS or ECMAScript modules, you may use `var` to Note that `/* exported */` has no effect for any of the following: -* when the environment is `node` or `commonjs` -* when `parserOptions.sourceType` is `module` -* when `ecmaFeatures.globalReturn` is `true` +* when `languageOptions.sourceType` is `module` (default) or `commonjs` +* when `languageOptions.parserOptions.ecmaFeatures.globalReturn` is `true` The line comment `// exported variableName` will not work as `exported` is not line-specific. diff --git a/docs/src/rules/strict.md b/docs/src/rules/strict.md index 8206eaaa3007..bf3bd6206c2b 100644 --- a/docs/src/rules/strict.md +++ b/docs/src/rules/strict.md @@ -73,9 +73,10 @@ 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: +* `"sourceType": "commonjs"` in [language options](../use/configure/language-options#specifying-javascript-options) * `"globalReturn": true` property in the `ecmaFeatures` object of [parser options](../use/configure/language-options#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. +Otherwise the `"safe"` option corresponds to the `"function"` option. ### global diff --git a/docs/src/use/configure/index.md b/docs/src/use/configure/index.md index c99b0a0ea0f6..6173b520f59c 100644 --- a/docs/src/use/configure/index.md +++ b/docs/src/use/configure/index.md @@ -17,7 +17,7 @@ Here are some of the options that you can configure in ESLint: * [**Globals**](./language-options#specifying-globals) - the additional global variables your script accesses during execution. * [**Rules**](rules) - which rules are enabled and at what error level. -* [**Plugins**](plugins) - which third-party plugins define additional rules, environments, configs, etc. for ESLint to use. +* [**Plugins**](plugins) - which third-party plugins define additional rules, languages, configs, etc. for ESLint to use. All of these options give you fine-grained control over how ESLint treats your code. diff --git a/docs/src/use/core-concepts/index.md b/docs/src/use/core-concepts/index.md index e76f1caa2180..d43db3da5723 100644 --- a/docs/src/use/core-concepts/index.md +++ b/docs/src/use/core-concepts/index.md @@ -56,7 +56,7 @@ For more information, refer to [Using a shareable configuration package](../conf ## Plugins -An ESLint plugin is an npm module that can contain a set of ESLint rules, configurations, processors, and environments. Often plugins include custom rules. Plugins can be used to enforce a style guide and support JavaScript extensions (like TypeScript), libraries (like React), and frameworks (Angular). +An ESLint plugin is an npm module that can contain a set of ESLint rules, configurations, processors, and languages. Often plugins include custom rules. Plugins can be used to enforce a style guide and support JavaScript extensions (like TypeScript), libraries (like React), and frameworks (Angular). A popular use case for plugins is to enforce best practices for a framework. For example, [@angular-eslint/eslint-plugin](https://www.npmjs.com/package/@angular-eslint/eslint-plugin) contains best practices for using the Angular framework. From e255cc98abef202929112378bfe133f260f2ac9d Mon Sep 17 00:00:00 2001 From: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> Date: Tue, 31 Dec 2024 22:55:47 +0530 Subject: [PATCH 21/51] docs: add bluesky icon to footer (#19290) * docs: add bluesky icon to footer * fix padding of social --- docs/src/_data/sites/en.yml | 3 ++- docs/src/_data/sites/zh-hans.yml | 4 +++- .../_includes/components/social-icons.html | 21 ++++++++++++------- .../assets/scss/components/social-icons.scss | 4 ++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/docs/src/_data/sites/en.yml b/docs/src/_data/sites/en.yml index da1ab1818f58..d53528732c9a 100644 --- a/docs/src/_data/sites/en.yml +++ b/docs/src/_data/sites/en.yml @@ -73,10 +73,11 @@ footer: secondary: Secondary social_icons: title: Social Media - twitter: Twitter chat: Discord github: GitHub + bluesky: Bluesky mastodon: Mastodon + twitter: Twitter theme_switcher: title: Theme Switcher light: Light diff --git a/docs/src/_data/sites/zh-hans.yml b/docs/src/_data/sites/zh-hans.yml index 99bbd5ce8600..ffc4ed7e3574 100644 --- a/docs/src/_data/sites/zh-hans.yml +++ b/docs/src/_data/sites/zh-hans.yml @@ -71,9 +71,11 @@ footer: secondary: 次要 social_icons: title: 社交媒体 - twitter: Twitter chat: Discord github: GitHub + bluesky: Bluesky + mastodon: Mastodon + twitter: Twitter theme_switcher: title: 主题切换 light: 浅色 diff --git a/docs/src/_includes/components/social-icons.html b/docs/src/_includes/components/social-icons.html index 6f2b887e9490..d346aec18eec 100644 --- a/docs/src/_includes/components/social-icons.html +++ b/docs/src/_includes/components/social-icons.html @@ -1,13 +1,6 @@ diff --git a/docs/src/assets/scss/components/social-icons.scss b/docs/src/assets/scss/components/social-icons.scss index eddd47f3ec77..86ba6a27f6ff 100644 --- a/docs/src/assets/scss/components/social-icons.scss +++ b/docs/src/assets/scss/components/social-icons.scss @@ -18,5 +18,9 @@ padding: 1rem .75rem; } } + + @media screen and (min-width: 800px) and (max-width: 1500px) { + flex-wrap: wrap; + } } } From ce0b9ff04242f61c8c49fc1ce164eb45eb3c459a Mon Sep 17 00:00:00 2001 From: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> Date: Tue, 31 Dec 2024 22:59:16 +0530 Subject: [PATCH 22/51] docs: add navigation link for `code explorer` (#19285) docs: add nav link to code explorer --- docs/src/_data/links.json | 1 + docs/src/_data/navigation.json | 4 ++++ docs/src/_data/sites/en.yml | 3 +++ docs/src/_data/sites/zh-hans.yml | 3 +++ 4 files changed, 11 insertions(+) diff --git a/docs/src/_data/links.json b/docs/src/_data/links.json index 9bf8222a4f58..bdf3b61c8bbe 100644 --- a/docs/src/_data/links.json +++ b/docs/src/_data/links.json @@ -6,6 +6,7 @@ "blog": "/blog", "docs": "/docs/latest/", "playground": "/play", + "codeExplorer": "https://explorer.eslint.org/", "getStarted": "/docs/latest/use/getting-started", "sponsors": "/sponsors", "branding": "/branding", diff --git a/docs/src/_data/navigation.json b/docs/src/_data/navigation.json index bc831667e91a..14973172906e 100644 --- a/docs/src/_data/navigation.json +++ b/docs/src/_data/navigation.json @@ -19,6 +19,10 @@ { "text": "Playground", "url": "https://eslint.org/play" + }, + { + "text": "Code Explorer", + "url": "https://explorer.eslint.org/" } ] } diff --git a/docs/src/_data/sites/en.yml b/docs/src/_data/sites/en.yml index d53528732c9a..adde1125b361 100644 --- a/docs/src/_data/sites/en.yml +++ b/docs/src/_data/sites/en.yml @@ -62,6 +62,9 @@ navigation: target: _blank - text: Playground link: playground +- text: Code Explorer + link: codeExplorer + target: _blank #------------------------------------------------------------------------------ # Footer diff --git a/docs/src/_data/sites/zh-hans.yml b/docs/src/_data/sites/zh-hans.yml index ffc4ed7e3574..bd27824486f9 100644 --- a/docs/src/_data/sites/zh-hans.yml +++ b/docs/src/_data/sites/zh-hans.yml @@ -60,6 +60,9 @@ navigation: target: _blank - text: 演练场 link: playground +- text: Code Explorer + link: codeExplorer + target: _blank #------------------------------------------------------------------------------ # Footer From 0bfdf6caaf3e1553c67a77da900245879c730ad3 Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Wed, 1 Jan 2025 08:08:33 +0000 Subject: [PATCH 23/51] docs: Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d41451e772e..3a1f81d1cb11 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,7 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).

Automattic Airbnb

Gold Sponsors

trunk.io

Silver Sponsors

SERP Triumph JetBrains Liftoff American Express Workleap

Bronze Sponsors

-

Syntax Cybozu WordHint Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

+

Cybozu WordHint Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

Technology Sponsors

Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.

Netlify Algolia 1Password

From a559009f51ad9f081bae5252bb2b7a6e23c54767 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Wed, 1 Jan 2025 04:55:16 -0500 Subject: [PATCH 24/51] docs: Add warning about extending core rules (#19295) * docs: Add warning about extending core rules fixes #19169 * Update docs/src/extend/custom-rules.md Co-authored-by: Amaresh S M --------- Co-authored-by: Amaresh S M --- docs/src/extend/custom-rules.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/src/extend/custom-rules.md b/docs/src/extend/custom-rules.md index 24f0489521d3..66b679f9358e 100644 --- a/docs/src/extend/custom-rules.md +++ b/docs/src/extend/custom-rules.md @@ -32,6 +32,10 @@ module.exports = { }; ``` +::: warning +The core rules shipped in the `eslint` package are not considered part of the public API and are not designed to be extended from. Building on top of these rules is fragile and will most likely result in your rules breaking completely at some point in the future. If you're interested in creating a rule that is similar to a core rule, you should first copy the rule file into your project and proceed from there. +::: + ## Rule Structure The source file for a rule exports an object with the following properties. Both custom rules and core rules follow this format. From 8e003056a805468b07bcf4edba83a90a932fb520 Mon Sep 17 00:00:00 2001 From: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> Date: Wed, 1 Jan 2025 20:44:36 +0530 Subject: [PATCH 25/51] docs: replace `var` with `const` in rule examples (#19299) * docs: replace var with const in rule example * revert changes in no-else-block * replace var in no-empty-pattern --- docs/src/rules/no-dupe-class-members.md | 2 +- docs/src/rules/no-dupe-keys.md | 10 ++++---- docs/src/rules/no-duplicate-case.md | 4 +-- docs/src/rules/no-empty-character-class.md | 4 +-- docs/src/rules/no-empty-pattern.md | 30 +++++++++++----------- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/src/rules/no-dupe-class-members.md b/docs/src/rules/no-dupe-class-members.md index d186d33e21cc..1b44736da731 100644 --- a/docs/src/rules/no-dupe-class-members.md +++ b/docs/src/rules/no-dupe-class-members.md @@ -15,7 +15,7 @@ class Foo { bar() { console.log("goodbye"); } } -var foo = new Foo(); +const foo = new Foo(); foo.bar(); // goodbye ``` diff --git a/docs/src/rules/no-dupe-keys.md b/docs/src/rules/no-dupe-keys.md index 1527bf8f1ec7..b8edaf81ff0e 100644 --- a/docs/src/rules/no-dupe-keys.md +++ b/docs/src/rules/no-dupe-keys.md @@ -9,7 +9,7 @@ handled_by_typescript: true Multiple properties with the same key in object literals can cause unexpected behavior in your application. ```js -var foo = { +const foo = { bar: "baz", bar: "qux" }; @@ -26,17 +26,17 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-dupe-keys: "error"*/ -var foo = { +const foo = { bar: "baz", bar: "qux" }; -var foo = { +const bar = { "bar": "baz", bar: "qux" }; -var foo = { +const baz = { 0x1: "baz", 1: "qux" }; @@ -51,7 +51,7 @@ Examples of **correct** code for this rule: ```js /*eslint no-dupe-keys: "error"*/ -var foo = { +const foo = { bar: "baz", quxx: "qux" }; diff --git a/docs/src/rules/no-duplicate-case.md b/docs/src/rules/no-duplicate-case.md index 59a2a9874953..c65a58f7d059 100644 --- a/docs/src/rules/no-duplicate-case.md +++ b/docs/src/rules/no-duplicate-case.md @@ -18,7 +18,7 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-duplicate-case: "error"*/ -var a = 1, +const a = 1, one = 1; switch (a) { @@ -64,7 +64,7 @@ Examples of **correct** code for this rule: ```js /*eslint no-duplicate-case: "error"*/ -var a = 1, +const a = 1, one = 1; switch (a) { diff --git a/docs/src/rules/no-empty-character-class.md b/docs/src/rules/no-empty-character-class.md index 2ab0679b394c..7f72ece6aec6 100644 --- a/docs/src/rules/no-empty-character-class.md +++ b/docs/src/rules/no-empty-character-class.md @@ -8,7 +8,7 @@ rule_type: problem Because empty character classes in regular expressions do not match anything, they might be typing mistakes. ```js -var foo = /^abc[]/; +const foo = /^abc[]/; ``` ## Rule Details @@ -73,5 +73,5 @@ Example of a *false negative* when this rule reports correct code: ```js /*eslint no-empty-character-class: "error"*/ -var abcNeverMatches = new RegExp("^abc[]"); +const abcNeverMatches = new RegExp("^abc[]"); ``` diff --git a/docs/src/rules/no-empty-pattern.md b/docs/src/rules/no-empty-pattern.md index 92000add1857..86aac082235a 100644 --- a/docs/src/rules/no-empty-pattern.md +++ b/docs/src/rules/no-empty-pattern.md @@ -9,21 +9,21 @@ When using destructuring, it's possible to create a pattern that has no effect. ```js // doesn't create any variables -var {a: {}} = foo; +const {a: {}} = foo; ``` In this code, no new variables are created because `a` is just a location helper while the `{}` is expected to contain the variables to create, such as: ```js // creates variable b -var {a: { b }} = foo; +const {a: { b }} = foo; ``` In many cases, the empty object pattern is a mistake where the author intended to use a default value instead, such as: ```js // creates variable a -var {a = {}} = foo; +const {a = {}} = foo; ``` The difference between these two patterns is subtle, especially because the problematic empty pattern looks just like an object literal. @@ -39,10 +39,10 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-empty-pattern: "error"*/ -var {} = foo; -var [] = foo; -var {a: {}} = foo; -var {a: []} = foo; +const {} = foo; +const [] = foo; +const {a: {}} = foo; +const {a: []} = foo; function foo({}) {} function bar([]) {} function baz({a: {}}) {} @@ -58,8 +58,8 @@ Examples of **correct** code for this rule: ```js /*eslint no-empty-pattern: "error"*/ -var {a = {}} = foo; -var {a = []} = foo; +const {a = {}} = foo; +const {b = []} = foo; function foo({a = {}}) {} function bar({a = []}) {} ``` @@ -84,10 +84,10 @@ Examples of **incorrect** code for this rule with the `{"allowObjectPatternsAsPa /*eslint no-empty-pattern: ["error", { "allowObjectPatternsAsParameters": true }]*/ function foo({a: {}}) {} -var bar = function({a: {}}) {}; -var bar = ({a: {}}) => {}; -var bar = ({} = bar) => {}; -var bar = ({} = { bar: 1 }) => {}; +const bar = function({a: {}}) {}; +const qux = ({a: {}}) => {}; +const quux = ({} = bar) => {}; +const item = ({} = { bar: 1 }) => {}; function baz([]) {} ``` @@ -102,8 +102,8 @@ Examples of **correct** code for this rule with the `{"allowObjectPatternsAsPara /*eslint no-empty-pattern: ["error", { "allowObjectPatternsAsParameters": true }]*/ function foo({}) {} -var bar = function({}) {}; -var bar = ({}) => {}; +const bar = function({}) {}; +const qux = ({}) => {}; function baz({} = {}) {} ``` From 064e35de95339cfedcad467c3c9871d5ff70c1a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josh=20Goldberg=20=E2=9C=A8?= Date: Thu, 2 Jan 2025 02:38:06 -0500 Subject: [PATCH 26/51] docs: remove 'I hope to' comments from scope-manager-interface (#19300) --- docs/src/extend/scope-manager-interface.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/src/extend/scope-manager-interface.md b/docs/src/extend/scope-manager-interface.md index f8b00db2d212..65a9afda486b 100644 --- a/docs/src/extend/scope-manager-interface.md +++ b/docs/src/extend/scope-manager-interface.md @@ -119,8 +119,6 @@ Those members are defined but not used in ESLint. * **Type:** `Map` * **Description:** The map from variable names to variable objects. -> I hope to rename `set` field or replace by a method. - #### references * **Type:** `Reference[]` @@ -136,8 +134,6 @@ Those members are defined but not used in ESLint. * **Type:** `boolean` * **Description:** `true` if this scope is `"function-expression-name"` scope. -> I hope to deprecate `functionExpressionScope` field as replacing by `scope.type === "function-expression-name"`. - ### Deprecated members Those members are defined but not used in ESLint. @@ -217,8 +213,6 @@ Those members are defined but not used in ESLint. * **Type:** `ASTNode[]` * **Description:** The array of `Identifier` nodes which define this variable. If this variable is redeclared, this array includes two or more nodes. -> I hope to deprecate `identifiers` field as replacing by `defs[].name` field. - #### references * **Type:** `Reference[]` From 069af5e9ac43c7f33bd2a30abce3d5d94f504465 Mon Sep 17 00:00:00 2001 From: Kim GyeonWon <84277185+ruddnjs3769@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:30:06 +0900 Subject: [PATCH 27/51] docs: rewrite `var` using `const` in rule examples (#19303) --- docs/src/rules/no-useless-computed-key.md | 34 +++++++++++------------ docs/src/rules/no-useless-concat.md | 24 ++++++++-------- docs/src/rules/no-useless-return.md | 26 ++++++++--------- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/docs/src/rules/no-useless-computed-key.md b/docs/src/rules/no-useless-computed-key.md index 947f7180489b..2cff67729663 100644 --- a/docs/src/rules/no-useless-computed-key.md +++ b/docs/src/rules/no-useless-computed-key.md @@ -8,13 +8,13 @@ rule_type: suggestion It's unnecessary to use computed properties with literals such as: ```js -var foo = {["a"]: "b"}; +const foo = {["a"]: "b"}; ``` The code can be rewritten as: ```js -var foo = {"a": "b"}; +const foo = {"a": "b"}; ``` ## Rule Details @@ -28,14 +28,14 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-useless-computed-key: "error"*/ -var a = { ['0']: 0 }; -var a = { ['0+1,234']: 0 }; -var a = { [0]: 0 }; -var a = { ['x']: 0 }; -var a = { ['x']() {} }; +const a = { ['0']: 0 }; +const b = { ['0+1,234']: 0 }; +const c = { [0]: 0 }; +const d = { ['x']: 0 }; +const e = { ['x']() {} }; -var { [0]: a } = obj; -var { ['x']: a } = obj; +const { [0]: foo } = obj; +const { ['x']: bar } = obj; class Foo { ["foo"] = "bar"; @@ -60,14 +60,14 @@ Examples of **correct** code for this rule: ```js /*eslint no-useless-computed-key: "error"*/ -var c = { 'a': 0 }; -var c = { 0: 0 }; -var a = { x() {} }; -var c = { a: 0 }; -var c = { '0+1,234': 0 }; +const a = { 'a': 0 }; +const b = { 0: 0 }; +const c = { x() {} }; +const d = { a: 0 }; +const e = { '0+1,234': 0 }; -var { 0: a } = obj; -var { 'x': a } = obj; +const { 0: foo } = obj; +const { 'x': bar } = obj; class Foo { "foo" = "bar"; @@ -92,7 +92,7 @@ Examples of additional **correct** code for this rule: ```js /*eslint no-useless-computed-key: "error"*/ -var c = { +const c = { "__proto__": foo, // defines object's prototype ["__proto__"]: bar // defines a property named "__proto__" diff --git a/docs/src/rules/no-useless-concat.md b/docs/src/rules/no-useless-concat.md index a0f214a50c25..a5d1a86d0429 100644 --- a/docs/src/rules/no-useless-concat.md +++ b/docs/src/rules/no-useless-concat.md @@ -7,13 +7,13 @@ rule_type: suggestion It's unnecessary to concatenate two strings together, such as: ```js -var foo = "a" + "b"; +const foo = "a" + "b"; ``` This code is likely the result of refactoring where a variable was removed from the concatenation (such as `"a" + b + "b"`). In such a case, the concatenation isn't important and the code can be rewritten as: ```js -var foo = "ab"; +const foo = "ab"; ``` ## Rule Details @@ -27,13 +27,13 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-useless-concat: "error"*/ -var a = `some` + `string`; +const a = `some` + `string`; // these are the same as "10" -var a = '1' + '0'; -var a = '1' + `0`; -var a = `1` + '0'; -var a = `1` + `0`; +const b = '1' + '0'; +const c = '1' + `0`; +const d = `1` + '0'; +const e = `1` + `0`; ``` ::: @@ -46,12 +46,12 @@ Examples of **correct** code for this rule: /*eslint no-useless-concat: "error"*/ // when a non string is included -var c = a + b; -var c = '1' + a; -var a = 1 + '1'; -var c = 1 - 2; +const a = a + b; +const b = '1' + a; +const c = 1 + '1'; +const d = 1 - 2; // when the string concatenation is multiline -var c = "foo" + +const e = "foo" + "bar"; ``` diff --git a/docs/src/rules/no-useless-return.md b/docs/src/rules/no-useless-return.md index de7045347c2e..5b1664772ae6 100644 --- a/docs/src/rules/no-useless-return.md +++ b/docs/src/rules/no-useless-return.md @@ -18,23 +18,23 @@ Examples of **incorrect** code for this rule: ```js /* eslint no-useless-return: "error" */ -var foo = function() { return; } +const foo = function() { return; } -var foo = function() { +const bar = function() { doSomething(); return; } -var foo = function() { +const baz = function() { if (condition) { - bar(); + qux(); return; } else { - baz(); + quux(); } } -var foo = function() { +const item = function() { switch (bar) { case 1: doSomething(); @@ -55,23 +55,23 @@ Examples of **correct** code for this rule: ```js /* eslint no-useless-return: "error" */ -var foo = function() { return 5; } +const foo = function() { return 5; } -var foo = function() { +const bar = function() { return doSomething(); } -var foo = function() { +const baz = function() { if (condition) { - bar(); + qux(); return; } else { - baz(); + quux(); } qux(); } -var foo = function() { +const item = function() { switch (bar) { case 1: doSomething(); @@ -81,7 +81,7 @@ var foo = function() { } } -var foo = function() { +const func = function() { for (const foo of bar) { return; } From 6e7361bb6ae93c87fccdf2219379c7793517f17a Mon Sep 17 00:00:00 2001 From: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:12:31 +0530 Subject: [PATCH 28/51] docs: replace `var` with `let` and `const` in rule example (#19302) * docs: replace var with let and const * replace more var in no-func-assign --- docs/src/rules/no-ex-assign.md | 2 +- docs/src/rules/no-func-assign.md | 8 +++--- docs/src/rules/no-irregular-whitespace.md | 24 ++++++++-------- .../src/rules/no-new-native-nonconstructor.md | 12 ++++---- docs/src/rules/no-obj-calls.md | 28 +++++++++---------- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/docs/src/rules/no-ex-assign.md b/docs/src/rules/no-ex-assign.md index 395164d204bc..79263089f009 100644 --- a/docs/src/rules/no-ex-assign.md +++ b/docs/src/rules/no-ex-assign.md @@ -40,7 +40,7 @@ Examples of **correct** code for this rule: try { // code } catch (e) { - var foo = 10; + const foo = 10; } ``` diff --git a/docs/src/rules/no-func-assign.md b/docs/src/rules/no-func-assign.md index 6346e2b8064f..160f9380a311 100644 --- a/docs/src/rules/no-func-assign.md +++ b/docs/src/rules/no-func-assign.md @@ -6,7 +6,7 @@ handled_by_typescript: true -JavaScript functions can be written as a FunctionDeclaration `function foo() { ... }` or as a FunctionExpression `var foo = function() { ... };`. While a JavaScript interpreter might tolerate it, overwriting/reassigning a function written as a FunctionDeclaration is often indicative of a mistake or issue. +JavaScript functions can be written as a FunctionDeclaration `function foo() { ... }` or as a FunctionExpression `const foo = function() { ... };`. While a JavaScript interpreter might tolerate it, overwriting/reassigning a function written as a FunctionDeclaration is often indicative of a mistake or issue. ```js function foo() {} @@ -31,7 +31,7 @@ function baz() { baz = bar; } -var a = function hello() { +let a = function hello() { hello = 123; }; ``` @@ -58,7 +58,7 @@ Examples of **correct** code for this rule: ```js /*eslint no-func-assign: "error"*/ -var foo = function () {} +let foo = function () {} foo = bar; function baz(baz) { // `baz` is shadowed. @@ -66,7 +66,7 @@ function baz(baz) { // `baz` is shadowed. } function qux() { - var qux = bar; // `qux` is shadowed. + const qux = bar; // `qux` is shadowed. } ``` diff --git a/docs/src/rules/no-irregular-whitespace.md b/docs/src/rules/no-irregular-whitespace.md index 8fb3f3fac49c..8b1972d1d61f 100644 --- a/docs/src/rules/no-irregular-whitespace.md +++ b/docs/src/rules/no-irregular-whitespace.md @@ -81,31 +81,31 @@ Examples of **incorrect** code for this rule with the default `{ "skipStrings": ```js /*eslint no-irregular-whitespace: "error"*/ -var thing = function() /**/{ +const thing = function() /**/{ return 'test'; } -var thing = function( /**/){ +const foo = function( /**/){ return 'test'; } -var thing = function /**/(){ +const bar = function /**/(){ return 'test'; } -var thing = function /**/(){ +const baz = function /**/(){ return 'test'; } -var thing = function() { +const qux = function() { return 'test'; /**/ } -var thing = function() { +const quux = function() { return 'test'; /**/ } -var thing = function() { +const item = function() { // Description : some descriptive text } @@ -113,11 +113,11 @@ var thing = function() { Description : some descriptive text */ -var thing = function() { +const func = function() { return / regexp/; } -var thing = function() { +const myFunc = function() { return `template string`; } ``` @@ -131,15 +131,15 @@ Examples of **correct** code for this rule with the default `{ "skipStrings": tr ```js /*eslint no-irregular-whitespace: "error"*/ -var thing = function() { +const thing = function() { return ' thing'; } -var thing = function() { +const foo = function() { return '​thing'; } -var thing = function() { +const bar = function() { return 'th ing'; } ``` diff --git a/docs/src/rules/no-new-native-nonconstructor.md b/docs/src/rules/no-new-native-nonconstructor.md index e605241abc0d..a8d35a108001 100644 --- a/docs/src/rules/no-new-native-nonconstructor.md +++ b/docs/src/rules/no-new-native-nonconstructor.md @@ -16,10 +16,10 @@ It is a convention in JavaScript that global variables beginning with an upperca ```js // throws a TypeError -let foo = new Symbol("foo"); +const foo = new Symbol("foo"); // throws a TypeError -let result = new BigInt(9007199254740991); +const result = new BigInt(9007199254740991); ``` Both `new Symbol` and `new BigInt` throw a type error because they are functions and not classes. It is easy to make this mistake by assuming the uppercase letters indicate classes. @@ -40,8 +40,8 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-new-native-nonconstructor: "error"*/ -var foo = new Symbol('foo'); -var bar = new BigInt(9007199254740991); +const foo = new Symbol('foo'); +const bar = new BigInt(9007199254740991); ``` ::: @@ -53,8 +53,8 @@ Examples of **correct** code for this rule: ```js /*eslint no-new-native-nonconstructor: "error"*/ -var foo = Symbol('foo'); -var bar = BigInt(9007199254740991); +const foo = Symbol('foo'); +const bar = BigInt(9007199254740991); // Ignores shadowed Symbol. function baz(Symbol) { diff --git a/docs/src/rules/no-obj-calls.md b/docs/src/rules/no-obj-calls.md index 2ab8d27f8b71..e7cadbd16778 100644 --- a/docs/src/rules/no-obj-calls.md +++ b/docs/src/rules/no-obj-calls.md @@ -39,25 +39,25 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-obj-calls: "error"*/ -var math = Math(); +const math = Math(); -var newMath = new Math(); +const newMath = new Math(); -var json = JSON(); +const json = JSON(); -var newJSON = new JSON(); +const newJSON = new JSON(); -var reflect = Reflect(); +const reflect = Reflect(); -var newReflect = new Reflect(); +const newReflect = new Reflect(); -var atomics = Atomics(); +const atomics = Atomics(); -var newAtomics = new Atomics(); +const newAtomics = new Atomics(); -var intl = Intl(); +const intl = Intl(); -var newIntl = new Intl(); +const newIntl = new Intl(); ``` ::: @@ -73,13 +73,13 @@ function area(r) { return Math.PI * r * r; } -var object = JSON.parse("{}"); +const object = JSON.parse("{}"); -var value = Reflect.get({ x: 1, y: 2 }, "x"); +const value = Reflect.get({ x: 1, y: 2 }, "x"); -var first = Atomics.load(foo, 0); +const first = Atomics.load(foo, 0); -var segmenterFr = new Intl.Segmenter("fr", { granularity: "word" }); +const segmenterFr = new Intl.Segmenter("fr", { granularity: "word" }); ``` ::: From 2e842138e689ee5623552e885c3a5ac1b0c2bfcf Mon Sep 17 00:00:00 2001 From: Amaresh S M Date: Thu, 2 Jan 2025 23:31:34 +0530 Subject: [PATCH 29/51] docs: Fix Horizontal Scroll Overflow in Rule Description on Mobile View (#19304) * docs: Fix Horizontal Scroll Overflow in Rule Description on Mobile View * Update rules.scss --- docs/src/assets/scss/components/rules.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/assets/scss/components/rules.scss b/docs/src/assets/scss/components/rules.scss index fcdbb2eb8a78..f7b77bf89a40 100644 --- a/docs/src/assets/scss/components/rules.scss +++ b/docs/src/assets/scss/components/rules.scss @@ -87,6 +87,7 @@ .rule__content { flex: 1 1 35ch; + overflow-x: auto; } .rule__name_wrapper { From e84e6e269c4aefc84952e17a1f967697b02b7ad2 Mon Sep 17 00:00:00 2001 From: Anna Bocharova Date: Fri, 3 Jan 2025 18:39:50 +0100 Subject: [PATCH 30/51] feat: Report allowed methods for `no-console` rule (#19306) * Renaming canProvideSuggestions() to canRemove(). * Implementing suggestions on console method replacement. * Report allowed methods of console. * Minor: formatting assetions for readability. * Revert: no method replacement suggestions. * Add missing data to assertion. * Accepted message text adjustment Co-authored-by: Milos Djermanovic --------- Co-authored-by: Milos Djermanovic --- lib/rules/no-console.js | 4 ++- tests/lib/rules/no-console.js | 54 +++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/lib/rules/no-console.js b/lib/rules/no-console.js index 62dc1693836c..7d11b4854d4a 100644 --- a/lib/rules/no-console.js +++ b/lib/rules/no-console.js @@ -49,6 +49,7 @@ module.exports = { messages: { unexpected: "Unexpected console statement.", + limited: "Unexpected console statement. Only these console methods are allowed: {{ allowed }}.", removeConsole: "Remove the console.{{ propertyName }}()." } }, @@ -169,7 +170,8 @@ module.exports = { context.report({ node, loc: node.loc, - messageId: "unexpected", + messageId: allowed.length ? "limited" : "unexpected", + data: { allowed: allowed.join(", ") }, suggest: canProvideSuggestions(node) ? [{ messageId: "removeConsole", diff --git a/tests/lib/rules/no-console.js b/tests/lib/rules/no-console.js index 1f1e0bf8642b..95b207d5ffd2 100644 --- a/tests/lib/rules/no-console.js +++ b/tests/lib/rules/no-console.js @@ -190,7 +190,8 @@ ruleTester.run("no-console", rule, { code: "if (a) console.info(foo)", options: [{ allow: ["warn"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "warn" }, type: "MemberExpression", suggestions: null }] @@ -199,7 +200,8 @@ ruleTester.run("no-console", rule, { code: "foo(console.warn)", options: [{ allow: ["log"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "log" }, type: "MemberExpression", suggestions: null }] @@ -208,7 +210,8 @@ ruleTester.run("no-console", rule, { code: "console.log(foo)", options: [{ allow: ["error"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "error" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -221,7 +224,8 @@ ruleTester.run("no-console", rule, { code: "console.error(foo)", options: [{ allow: ["warn"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "warn" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -234,7 +238,8 @@ ruleTester.run("no-console", rule, { code: "console.info(foo)", options: [{ allow: ["log"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "log" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -247,7 +252,8 @@ ruleTester.run("no-console", rule, { code: "console.warn(foo)", options: [{ allow: ["error"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "error" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -260,7 +266,8 @@ ruleTester.run("no-console", rule, { code: "switch (a) { case 1: console.log(foo) }", options: [{ allow: ["error"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "error" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -273,7 +280,8 @@ ruleTester.run("no-console", rule, { code: "if (a) { console.info(foo) }", options: [{ allow: ["warn"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "warn" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -287,7 +295,8 @@ ruleTester.run("no-console", rule, { options: [{ allow: ["log"] }], languageOptions: { ecmaVersion: "latest" }, errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "log" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -302,7 +311,8 @@ ruleTester.run("no-console", rule, { code: "if (a) console.log(foo)", options: [{ allow: ["warn", "error"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "warn, error" }, type: "MemberExpression", suggestions: null }] @@ -311,7 +321,8 @@ ruleTester.run("no-console", rule, { code: "foo(console.info)", options: [{ allow: ["warn", "error"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "warn, error" }, type: "MemberExpression", suggestions: null }] @@ -320,7 +331,8 @@ ruleTester.run("no-console", rule, { code: "console.log(foo)", options: [{ allow: ["warn", "info"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "warn, info" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -333,7 +345,8 @@ ruleTester.run("no-console", rule, { code: "console.error(foo)", options: [{ allow: ["warn", "info", "log"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "warn, info, log" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -346,7 +359,8 @@ ruleTester.run("no-console", rule, { code: "console.info(foo)", options: [{ allow: ["warn", "error", "log"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "warn, error, log" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -359,7 +373,8 @@ ruleTester.run("no-console", rule, { code: "console.warn(foo)", options: [{ allow: ["info", "log"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "info, log" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -372,7 +387,8 @@ ruleTester.run("no-console", rule, { code: "switch (a) { case 1: console.error(foo) }", options: [{ allow: ["info", "log"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "info, log" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -385,7 +401,8 @@ ruleTester.run("no-console", rule, { code: "if (a) { console.log(foo) }", options: [{ allow: ["warn", "error"] }], errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "warn, error" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", @@ -399,7 +416,8 @@ ruleTester.run("no-console", rule, { options: [{ allow: ["log", "error", "warn"] }], languageOptions: { ecmaVersion: "latest" }, errors: [{ - messageId: "unexpected", + messageId: "limited", + data: { allowed: "log, error, warn" }, type: "MemberExpression", suggestions: [{ messageId: "removeConsole", From df409d8f76555c7baa4353d678d5fc460454a4d7 Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Sat, 4 Jan 2025 08:07:57 +0000 Subject: [PATCH 31/51] docs: Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3a1f81d1cb11..9aec95f558c4 100644 --- a/README.md +++ b/README.md @@ -299,8 +299,8 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).

Platinum Sponsors

Automattic Airbnb

Gold Sponsors

trunk.io

Silver Sponsors

-

SERP Triumph JetBrains Liftoff American Express Workleap

Bronze Sponsors

-

Cybozu WordHint Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

+

SERP Triumph JetBrains Liftoff American Express Workleap

Bronze Sponsors

+

Cybozu Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

Technology Sponsors

Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.

Netlify Algolia 1Password

From 1610c9ee1479f23b1bc5a6853d0b42b83dacdb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Sat, 4 Jan 2025 22:22:38 +0900 Subject: [PATCH 32/51] docs: add missing backticks to `no-else-return` (#19309) --- docs/src/rules/no-else-return.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/rules/no-else-return.md b/docs/src/rules/no-else-return.md index 379de922b321..a41336553f79 100644 --- a/docs/src/rules/no-else-return.md +++ b/docs/src/rules/no-else-return.md @@ -19,14 +19,14 @@ function foo() { ## Rule Details -This rule is aimed at highlighting an unnecessary block of code following an `if` containing a return statement. As such, it will warn when it encounters an `else` following a chain of `if`s, all of them containing a `return` statement. +This rule is aimed at highlighting an unnecessary block of code following an `if` containing a `return` statement. As such, it will warn when it encounters an `else` following a chain of `if`s, all of them containing a `return` statement. ## Options This rule has an object option: -* `allowElseIf: true` (default) allows `else if` blocks after a return -* `allowElseIf: false` disallows `else if` blocks after a return +* `allowElseIf: true` (default) allows `else if` blocks after a `return` +* `allowElseIf: false` disallows `else if` blocks after a `return` ### allowElseIf: true From 36ef8bbeab495ef2598a4b1f52e32b4cb50be5e2 Mon Sep 17 00:00:00 2001 From: Amaresh S M Date: Sun, 5 Jan 2025 00:39:32 +0530 Subject: [PATCH 33/51] docs: rewrite examples with var using let and const (#19298) * docs: rewrite examples with var using let and const * revert comma-spacing.md changes * consistent this rename to let/const * id-length rename eg with let/const * id-match rename eg with let/const * rewrite missed eg * Update docs/src/rules/consistent-this.md Co-authored-by: Milos Djermanovic * Update docs/src/rules/consistent-this.md Co-authored-by: Milos Djermanovic * Update docs/src/rules/no-multi-assign.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update id-match.md --------- Co-authored-by: Milos Djermanovic Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> --- docs/src/rules/consistent-this.md | 31 +++++++---- docs/src/rules/id-length.md | 91 +++++++++++++++---------------- docs/src/rules/id-match.md | 38 ++++++------- docs/src/rules/no-iterator.md | 2 +- docs/src/rules/no-multi-assign.md | 8 +-- docs/src/rules/no-octal-escape.md | 8 +-- docs/src/rules/no-self-compare.md | 2 +- 7 files changed, 95 insertions(+), 85 deletions(-) diff --git a/docs/src/rules/consistent-this.md b/docs/src/rules/consistent-this.md index 8f029adaa937..a77ea987179e 100644 --- a/docs/src/rules/consistent-this.md +++ b/docs/src/rules/consistent-this.md @@ -7,7 +7,7 @@ rule_type: suggestion It is often necessary to capture the current execution context in order to make it available subsequently. A prominent example of this are jQuery callbacks: ```js -var that = this; +const that = this; jQuery('li').click(function (event) { // here, "this" is the HTMLElement where the click event occurred that.setFoo(42); @@ -36,9 +36,9 @@ Examples of **incorrect** code for this rule with the default `"that"` option: ```js /*eslint consistent-this: ["error", "that"]*/ -var that = 42; +let that = 42; -var self = this; +let self = this; that = 42; @@ -54,11 +54,11 @@ Examples of **correct** code for this rule with the default `"that"` option: ```js /*eslint consistent-this: ["error", "that"]*/ -var that = this; +let that = this; -var self = 42; +const self = 42; -var self; +let foo; that = this; @@ -74,7 +74,7 @@ Examples of **incorrect** code for this rule with the default `"that"` option, i ```js /*eslint consistent-this: ["error", "that"]*/ -var that; +let that; function f() { that = this; } @@ -84,16 +84,27 @@ function f() { Examples of **correct** code for this rule with the default `"that"` option, if the variable is not initialized: +Declaring a variable `that` and assigning `this` to it. + ::: correct ```js /*eslint consistent-this: ["error", "that"]*/ -var that; +let that; that = this; +``` + +::: + +Declaring two variables, `foo` and `that`, with `foo` initialized, and then assigning `this` to `that`. + +::: correct + +```js +/*eslint consistent-this: ["error", "that"]*/ -var foo, that; -foo = 42; +let foo = 42, that; that = this; ``` diff --git a/docs/src/rules/id-length.md b/docs/src/rules/id-length.md index 7c8359e47945..8d18cacee7eb 100644 --- a/docs/src/rules/id-length.md +++ b/docs/src/rules/id-length.md @@ -12,7 +12,7 @@ related_rules: Very short identifier names like `e`, `x`, `_t` or very long ones like `hashGeneratorResultOutputContainerObject` can make code harder to read and potentially less maintainable. To prevent this, one may enforce a minimum and/or maximum identifier length. ```js -var x = 5; // too short; difficult to understand its purpose without context +const x = 5; // too short; difficult to understand its purpose without context ``` ## Rule Details @@ -30,15 +30,15 @@ Examples of **incorrect** code for this rule with the default options: ```js /*eslint id-length: "error"*/ // default is minimum 2-chars ({ "min": 2 }) -var x = 5; +const x = 5; obj.e = document.body; -var foo = function (e) { }; +const foo = function (e) { }; try { dangerousStuff(); } catch (e) { // ignore as many do } -var myObj = { a: 1 }; +const myObj = { a: 1 }; (a) => { a * a }; class y { } class Foo { x() {} } @@ -47,11 +47,11 @@ class Baz { x = 1 } class Qux { #x = 1 } function bar(...x) { } function baz([x]) { } -var [x] = arr; -var { prop: [x]} = {}; +const [z] = arr; +const { prop: [i]} = {}; function qux({x}) { } -var { x } = {}; -var { prop: a} = {}; +const { j } = {}; +const { prop: a} = {}; ({ prop: obj.x } = {}); ``` @@ -64,17 +64,17 @@ Examples of **correct** code for this rule with the default options: ```js /*eslint id-length: "error"*/ // default is minimum 2-chars ({ "min": 2 }) -var num = 5; +const num = 5; function _f() { return 42; } function _func() { return 42; } obj.el = document.body; -var foo = function (evt) { /* do stuff */ }; +const foo = function (evt) { /* do stuff */ }; try { dangerousStuff(); } catch (error) { // ignore as many do } -var myObj = { apple: 1 }; +const myObj = { apple: 1 }; (num) => { num * num }; function bar(num = 0) { } class MyClass { } @@ -84,15 +84,14 @@ class Baz { field = 1 } class Qux { #field = 1 } function baz(...args) { } function qux([longName]) { } -var { prop } = {}; -var { prop: [longName] } = {}; -var [longName] = arr; +const { prop } = {}; +const { prop: [name] } = {}; +const [longName] = arr; function foobar({ prop }) { } function foobaz({ a: prop }) { } -var { prop } = {}; -var { a: prop } = {}; +const { a: property } = {}; ({ prop: obj.longName } = {}); -var data = { "x": 1 }; // excused because of quotes +const data = { "x": 1 }; // excused because of quotes data["y"] = 3; // excused because of calculated property access ``` @@ -116,7 +115,7 @@ Examples of **incorrect** code for this rule with the `{ "min": 4 }` option: ```js /*eslint id-length: ["error", { "min": 4 }]*/ -var val = 5; +const val = 5; obj.e = document.body; function foo (e) { }; try { @@ -124,15 +123,15 @@ try { } catch (e) { // ignore as many do } -var myObj = { a: 1 }; +const myObj = { a: 1 }; (val) => { val * val }; class y { } class Foo { x() {} } function bar(...x) { } -var { x } = {}; -var { prop: a} = {}; -var [x] = arr; -var { prop: [x]} = {}; +const { x } = {}; +const { prop: a} = {}; +const [i] = arr; +const { prop: [num]} = {}; ({ prop: obj.x } = {}); ``` @@ -145,27 +144,27 @@ Examples of **correct** code for this rule with the `{ "min": 4 }` option: ```js /*eslint id-length: ["error", { "min": 4 }]*/ -var value = 5; +const value = 5; function func() { return 42; } object.element = document.body; -var foobar = function (event) { /* do stuff */ }; +const foobar = function (event) { /* do stuff */ }; try { dangerousStuff(); } catch (error) { // ignore as many do } -var myObj = { apple: 1 }; +const myObj = { apple: 1 }; (value) => { value * value }; function foobaz(value = 0) { } class MyClass { } class Foobar { method() {} } function barbaz(...args) { } -var { prop } = {}; -var [longName] = foo; -var { a: [prop] } = {}; -var { a: longName } = {}; +const { prop } = {}; +const [longName] = foo; +const { a: [name] } = {}; +const { a: record } = {}; ({ prop: object.name } = {}); -var data = { "x": 1 }; // excused because of quotes +const data = { "x": 1 }; // excused because of quotes data["y"] = 3; // excused because of calculated property access ``` @@ -180,17 +179,17 @@ Examples of **incorrect** code for this rule with the `{ "max": 10 }` option: ```js /*eslint id-length: ["error", { "max": 10 }]*/ -var reallyLongVarName = 5; +const reallyLongVarName = 5; function reallyLongFuncName() { return 42; } obj.reallyLongPropName = document.body; -var foo = function (reallyLongArgName) { /* do stuff */ }; +const foo = function (reallyLongArgName) { /* do stuff */ }; try { dangerousStuff(); } catch (reallyLongErrorName) { // ignore as many do } (reallyLongArgName) => { return !reallyLongArgName; }; -var [reallyLongFirstElementName] = arr; +const [reallyLongFirstElementName] = arr; ``` ::: @@ -202,17 +201,17 @@ Examples of **correct** code for this rule with the `{ "max": 10 }` option: ```js /*eslint id-length: ["error", { "max": 10 }]*/ -var varName = 5; +const varName = 5; function funcName() { return 42; } obj.propName = document.body; -var foo = function (arg) { /* do stuff */ }; +const foo = function (arg) { /* do stuff */ }; try { dangerousStuff(); } catch (error) { // ignore as many do } (arg) => { return !arg; }; -var [first] = arr; +const [first] = arr; ``` ::: @@ -226,7 +225,7 @@ Examples of **correct** code for this rule with the `{ "properties": "never" }` ```js /*eslint id-length: ["error", { "properties": "never" }]*/ -var myObj = { a: 1 }; +const myObj = { a: 1 }; ({ a: obj.x.y.z } = {}); ({ prop: obj.i } = {}); ``` @@ -240,19 +239,19 @@ Examples of additional **correct** code for this rule with the `{ "exceptions": ::: correct ```js -/*eslint id-length: ["error", { "exceptions": ["x", "y", "z", "ζ"] }]*/ +/*eslint id-length: ["error", { "exceptions": ["x", "y", "z", "ζ", "i"] }]*/ -var x = 5; +const x = 5; function y() { return 42; } obj.x = document.body; -var foo = function (x) { /* do stuff */ }; +const foo = function (x) { /* do stuff */ }; try { dangerousStuff(); } catch (x) { // ignore as many do } (x) => { return x * x; }; -var [x] = arr; +const [i] = arr; const { z } = foo; const { a: ζ } = foo; ``` @@ -266,19 +265,19 @@ Examples of additional **correct** code for this rule with the `{ "exceptionPatt ::: correct ```js -/*eslint id-length: ["error", { "exceptionPatterns": ["E|S", "[x-z]"] }]*/ +/*eslint id-length: ["error", { "exceptionPatterns": ["E|S|X", "[x-z]"] }]*/ -var E = 5; +const E = 5; function S() { return 42; } obj.x = document.body; -var foo = function (x) { /* do stuff */ }; +const foo = function (x) { /* do stuff */ }; try { dangerousStuff(); } catch (x) { // ignore as many do } (y) => {return y * y}; -var [E] = arr; +const [X] = arr; const { y } = foo; const { a: z } = foo; ``` diff --git a/docs/src/rules/id-match.md b/docs/src/rules/id-match.md index 86ff85f904b7..f016b3ab43d9 100644 --- a/docs/src/rules/id-match.md +++ b/docs/src/rules/id-match.md @@ -34,10 +34,10 @@ Examples of **incorrect** code for this rule with the `"^[a-z]+([A-Z][a-z]+)*$"` ```js /*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/ -var my_favorite_color = "#112C85"; -var _myFavoriteColor = "#112C85"; -var myFavoriteColor_ = "#112C85"; -var MY_FAVORITE_COLOR = "#112C85"; +const my_favorite_color = "#112C85"; +const _myFavoriteColor = "#112C85"; +const myFavoriteColor_ = "#112C85"; +const MY_FAVORITE_COLOR = "#112C85"; function do_something() { // ... } @@ -62,11 +62,11 @@ Examples of **correct** code for this rule with the `"^[a-z]+([A-Z][a-z]+)*$"` o ```js /*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/ -var myFavoriteColor = "#112C85"; -var foo = bar.baz_boom; -var foo = { qux: bar.baz_boom }; +const myFavoriteColor = "#112C85"; +const foo = bar.baz_boom; +const buz = { qux: bar.baz_boom }; do_something(); -var obj = { +const obj = { my_pref: 1 }; @@ -103,7 +103,7 @@ Examples of **incorrect** code for this rule with the `"^[a-z]+([A-Z][a-z]+)*$", ```js /*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/ -var obj = { +const obj = { my_pref: 1 }; @@ -157,15 +157,15 @@ Examples of **incorrect** code for this rule with the default `"^[^_]+$", { "ign ```js /*eslint id-match: [2, "^[^_]+$", { "ignoreDestructuring": false }]*/ -var { category_id } = query; +const { category_id } = query; -var { category_id = 1 } = query; +const { categoryid_Default = 1 } = query; -var { category_id: category_id } = query; +const { category_ids: category_ids } = query; -var { category_id: category_alias } = query; +const { category_id: category_Alias } = query; -var { category_id: categoryId, ...other_props } = query; +const { category_id: category_IdRenamed, ...other_Props } = query; ``` ::: @@ -179,9 +179,9 @@ Examples of **incorrect** code for this rule with the `"^[^_]+$", { "ignoreDestr ```js /*eslint id-match: [2, "^[^_]+$", { "ignoreDestructuring": true }]*/ -var { category_id: category_alias } = query; +const { category_id: category_alias } = query; -var { category_id, ...other_props } = query; +const { category_id: category_Id, ...other_props } = query; ``` ::: @@ -193,11 +193,11 @@ Examples of **correct** code for this rule with the `"^[^_]+$", { "ignoreDestruc ```js /*eslint id-match: [2, "^[^_]+$", { "ignoreDestructuring": true }]*/ -var { category_id } = query; +const { category_id } = query; -var { category_id = 1 } = query; +const { category_Id = 1 } = query; -var { category_id: category_id } = query; +const { category_alias: category_alias } = query; ``` ::: diff --git a/docs/src/rules/no-iterator.md b/docs/src/rules/no-iterator.md index 70186826239b..7da0a23775f4 100644 --- a/docs/src/rules/no-iterator.md +++ b/docs/src/rules/no-iterator.md @@ -48,7 +48,7 @@ Examples of **correct** code for this rule: ```js /*eslint no-iterator: "error"*/ -var __iterator__ = foo; // Not using the `__iterator__` property. +const __iterator__ = foo; // Not using the `__iterator__` property. ``` ::: diff --git a/docs/src/rules/no-multi-assign.md b/docs/src/rules/no-multi-assign.md index f4f4c2fce5aa..a9d9c158eb4a 100644 --- a/docs/src/rules/no-multi-assign.md +++ b/docs/src/rules/no-multi-assign.md @@ -27,7 +27,7 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-multi-assign: "error"*/ -var a = b = c = 5; +let a = b = c = 5; const foo = bar = "baz"; @@ -51,9 +51,9 @@ Examples of **correct** code for this rule: ```js /*eslint no-multi-assign: "error"*/ -var a = 5; -var b = 5; -var c = 5; +let a = 5; +let b = 5; +const c = 5; const foo = "baz"; const bar = "baz"; diff --git a/docs/src/rules/no-octal-escape.md b/docs/src/rules/no-octal-escape.md index 755bc56bc84f..d470007536a2 100644 --- a/docs/src/rules/no-octal-escape.md +++ b/docs/src/rules/no-octal-escape.md @@ -7,7 +7,7 @@ rule_type: suggestion As of the ECMAScript 5 specification, octal escape sequences in string literals are deprecated and should not be used. Unicode escape sequences should be used instead. ```js -var foo = "Copyright \251"; +const foo = "Copyright \251"; ``` ## Rule Details @@ -23,7 +23,7 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-octal-escape: "error"*/ -var foo = "Copyright \251"; +const foo = "Copyright \251"; ``` ::: @@ -35,9 +35,9 @@ Examples of **correct** code for this rule: ```js /*eslint no-octal-escape: "error"*/ -var foo = "Copyright \u00A9"; // unicode +const foo = "Copyright \u00A9"; // unicode -var foo = "Copyright \xA9"; // hexadecimal +const buz = "Copyright \xA9"; // hexadecimal ``` ::: diff --git a/docs/src/rules/no-self-compare.md b/docs/src/rules/no-self-compare.md index bf0562993df1..139b97c96c3e 100644 --- a/docs/src/rules/no-self-compare.md +++ b/docs/src/rules/no-self-compare.md @@ -19,7 +19,7 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-self-compare: "error"*/ -var x = 10; +let x = 10; if (x === x) { x = 20; } From 8d943c335c528a6a6a631dcbd98506238240ecfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Tue, 7 Jan 2025 00:13:31 +0900 Subject: [PATCH 34/51] docs: add missing backticks to `default-case-last` (#19311) --- docs/src/_data/rules_meta.json | 2 +- lib/rules/default-case-last.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/_data/rules_meta.json b/docs/src/_data/rules_meta.json index 97fe8d775175..283745477e6b 100644 --- a/docs/src/_data/rules_meta.json +++ b/docs/src/_data/rules_meta.json @@ -295,7 +295,7 @@ "default-case-last": { "type": "suggestion", "docs": { - "description": "Enforce `default` clauses in switch statements to be last", + "description": "Enforce `default` clauses in `switch` statements to be last", "recommended": false, "url": "https://eslint.org/docs/latest/rules/default-case-last" } diff --git a/lib/rules/default-case-last.js b/lib/rules/default-case-last.js index bd2d93ec7bde..3a47078c8ca2 100644 --- a/lib/rules/default-case-last.js +++ b/lib/rules/default-case-last.js @@ -1,5 +1,5 @@ /** - * @fileoverview Rule to enforce `default` clauses in switch statements to be last + * @fileoverview Rule to enforce `default` clauses in `switch` statements to be last * @author Milos Djermanovic */ @@ -15,7 +15,7 @@ module.exports = { type: "suggestion", docs: { - description: "Enforce `default` clauses in switch statements to be last", + description: "Enforce `default` clauses in `switch` statements to be last", recommended: false, url: "https://eslint.org/docs/latest/rules/default-case-last" }, From db574c4d380e2d25b6111a06bd15caa83f75bb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Tue, 7 Jan 2025 00:17:11 +0900 Subject: [PATCH 35/51] docs: add missing backticks to `no-void` (#19313) --- docs/src/rules/no-void.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/rules/no-void.md b/docs/src/rules/no-void.md index 6120cf4d142a..9bd67bf5238e 100644 --- a/docs/src/rules/no-void.md +++ b/docs/src/rules/no-void.md @@ -56,7 +56,7 @@ Some code styles prohibit `void` operator, marking it as non-obvious and hard to ## Rule Details -This rule aims to eliminate use of void operator. +This rule aims to eliminate use of `void` operator. Examples of **incorrect** code for this rule: @@ -80,11 +80,11 @@ function baz() { This rule has an object option: -* `allowAsStatement` set to `true` allows the void operator to be used as a statement (Default `false`). +* `allowAsStatement` set to `true` allows the `void` operator to be used as a statement (Default `false`). ### allowAsStatement -When `allowAsStatement` is set to true, the rule will not error on cases that the void operator is used as a statement, i.e. when it's not used in an expression position, like in a variable assignment or a function return. +When `allowAsStatement` is set to true, the rule will not error on cases that the `void` operator is used as a statement, i.e. when it's not used in an expression position, like in a variable assignment or a function return. Examples of **incorrect** code for `{ "allowAsStatement": true }`: From 495aa499a7390f99b763cba8f2b8312e3eecfe0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Tue, 7 Jan 2025 00:26:05 +0900 Subject: [PATCH 36/51] chore: extract package `name` from `package.json` for public interface (#19314) --- packages/js/src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/js/src/index.js b/packages/js/src/index.js index f58dd798a831..ec252bcd5167 100644 --- a/packages/js/src/index.js +++ b/packages/js/src/index.js @@ -5,7 +5,7 @@ "use strict"; -const { version } = require("../package.json"); +const { name, version } = require("../package.json"); //------------------------------------------------------------------------------ // Public Interface @@ -13,7 +13,7 @@ const { version } = require("../package.json"); module.exports = { meta: { - name: "@eslint/js", + name, version }, configs: { From 89c8fc54c977ac457d3b5525a87cec1c51e72e23 Mon Sep 17 00:00:00 2001 From: Amaresh S M Date: Mon, 6 Jan 2025 22:03:23 +0530 Subject: [PATCH 37/51] docs: rewrite examples with var using let and const (#19315) --- docs/src/rules/array-callback-return.md | 18 +++++++-------- docs/src/rules/for-direction.md | 12 +++++----- docs/src/rules/getter-return.md | 8 +++---- docs/src/rules/no-cond-assign.md | 28 +++++++++++------------ docs/src/rules/no-constant-condition.md | 4 ++-- docs/src/rules/no-control-regex.md | 30 ++++++++++++------------- docs/src/rules/no-dupe-args.md | 4 ++-- 7 files changed, 52 insertions(+), 52 deletions(-) diff --git a/docs/src/rules/array-callback-return.md b/docs/src/rules/array-callback-return.md index 625cb14ced31..f606ec010889 100644 --- a/docs/src/rules/array-callback-return.md +++ b/docs/src/rules/array-callback-return.md @@ -9,7 +9,7 @@ If we forget to write `return` statement in a callback of those, it's probably a ```js // example: convert ['a', 'b', 'c'] --> {a: 0, b: 1, c: 2} -var indexMap = myArray.reduce(function(memo, item, index) { +const indexMap = myArray.reduce(function(memo, item, index) { memo[item] = index; }, {}); // Error: cannot set property 'b' of undefined ``` @@ -45,17 +45,17 @@ Examples of **incorrect** code for this rule: ```js /*eslint array-callback-return: "error"*/ -var indexMap = myArray.reduce(function(memo, item, index) { +const indexMap = myArray.reduce(function(memo, item, index) { memo[item] = index; }, {}); -var foo = Array.from(nodes, function(node) { +const foo = Array.from(nodes, function(node) { if (node.tagName === "DIV") { return true; } }); -var bar = foo.filter(function(x) { +const bar = foo.filter(function(x) { if (x) { return true; } else { @@ -73,19 +73,19 @@ Examples of **correct** code for this rule: ```js /*eslint array-callback-return: "error"*/ -var indexMap = myArray.reduce(function(memo, item, index) { +const indexMap = myArray.reduce(function(memo, item, index) { memo[item] = index; return memo; }, {}); -var foo = Array.from(nodes, function(node) { +const foo = Array.from(nodes, function(node) { if (node.tagName === "DIV") { return true; } return false; }); -var bar = foo.map(node => node.getAttribute("id")); +const bar = foo.map(node => node.getAttribute("id")); ``` ::: @@ -98,7 +98,7 @@ This rule accepts a configuration object with three options: * `"checkForEach": false` (default) When set to `true`, rule will also report `forEach` callbacks that return a value. * `"allowVoid": false` (default) When set to `true`, allows `void` in `forEach` callbacks, so rule will not report the return value with a `void` operator. -**Note:** `{ "allowVoid": true }` works only if `checkForEach` option is set to `true`. +**Note:** `{ "allowVoid": true }` works only if `checkForEach` option is set to `true`. ### allowImplicit @@ -108,7 +108,7 @@ Examples of **correct** code for the `{ "allowImplicit": true }` option: ```js /*eslint array-callback-return: ["error", { allowImplicit: true }]*/ -var undefAllTheThings = myArray.map(function(item) { +const undefAllTheThings = myArray.map(function(item) { return; }); ``` diff --git a/docs/src/rules/for-direction.md b/docs/src/rules/for-direction.md index aa09cb181e36..219e97526175 100644 --- a/docs/src/rules/for-direction.md +++ b/docs/src/rules/for-direction.md @@ -15,16 +15,16 @@ Examples of **incorrect** code for this rule: ```js /*eslint for-direction: "error"*/ -for (var i = 0; i < 10; i--) { +for (let i = 0; i < 10; i--) { } -for (var i = 10; i >= 0; i++) { +for (let i = 10; i >= 0; i++) { } -for (var i = 0; i > 10; i++) { +for (let i = 0; i > 10; i++) { } -for (var i = 0; 10 > i; i--) { +for (let i = 0; 10 > i; i--) { } const n = -2; @@ -40,10 +40,10 @@ Examples of **correct** code for this rule: ```js /*eslint for-direction: "error"*/ -for (var i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { } -for (var i = 0; 10 > i; i++) { // with counter "i" on the right +for (let i = 0; 10 > i; i++) { // with counter "i" on the right } for (let i = 10; i >= 0; i += this.step) { // direction unknown diff --git a/docs/src/rules/getter-return.md b/docs/src/rules/getter-return.md index 9d316303d025..aaf4ea3eba2c 100644 --- a/docs/src/rules/getter-return.md +++ b/docs/src/rules/getter-return.md @@ -12,7 +12,7 @@ further_reading: The get syntax binds an object property to a function that will be called when that property is looked up. It was first introduced in ECMAScript 5: ```js -var p = { +const p = { get name(){ return "nicholas"; } @@ -38,7 +38,7 @@ Examples of **incorrect** code for this rule: ```js /*eslint getter-return: "error"*/ -p = { +const p = { get name(){ // no returns. } @@ -66,7 +66,7 @@ Examples of **correct** code for this rule: ```js /*eslint getter-return: "error"*/ -p = { +const p = { get name(){ return "nicholas"; } @@ -99,7 +99,7 @@ Examples of **correct** code for the `{ "allowImplicit": true }` option: ```js /*eslint getter-return: ["error", { allowImplicit: true }]*/ -p = { +const p = { get name(){ return; // return undefined implicitly. } diff --git a/docs/src/rules/no-cond-assign.md b/docs/src/rules/no-cond-assign.md index e9b807db2b65..a7872a28bb1f 100644 --- a/docs/src/rules/no-cond-assign.md +++ b/docs/src/rules/no-cond-assign.md @@ -39,13 +39,13 @@ Examples of **incorrect** code for this rule with the default `"except-parens"` /*eslint no-cond-assign: "error"*/ // Unintentional assignment -var x; +let x; if (x = 0) { - var b = 1; + const b = 1; } // Practical example that is similar to an error -var setHeight = function (someNode) { +const setHeight = function (someNode) { do { someNode.height = "100px"; } while (someNode = someNode.parentNode); @@ -62,20 +62,20 @@ Examples of **correct** code for this rule with the default `"except-parens"` op /*eslint no-cond-assign: "error"*/ // Assignment replaced by comparison -var x; +let x; if (x === 0) { - var b = 1; + const b = 1; } // Practical example that wraps the assignment in parentheses -var setHeight = function (someNode) { +const setHeight = function (someNode) { do { someNode.height = "100px"; } while ((someNode = someNode.parentNode)); } // Practical example that wraps the assignment and tests for 'null' -var setHeight = function (someNode) { +const set_height = function (someNode) { do { someNode.height = "100px"; } while ((someNode = someNode.parentNode) !== null); @@ -94,27 +94,27 @@ Examples of **incorrect** code for this rule with the `"always"` option: /*eslint no-cond-assign: ["error", "always"]*/ // Unintentional assignment -var x; +let x; if (x = 0) { - var b = 1; + const b = 1; } // Practical example that is similar to an error -var setHeight = function (someNode) { +const setHeight = function (someNode) { do { someNode.height = "100px"; } while (someNode = someNode.parentNode); } // Practical example that wraps the assignment in parentheses -var setHeight = function (someNode) { +const set_height = function (someNode) { do { someNode.height = "100px"; } while ((someNode = someNode.parentNode)); } // Practical example that wraps the assignment and tests for 'null' -var setHeight = function (someNode) { +const heightSetter = function (someNode) { do { someNode.height = "100px"; } while ((someNode = someNode.parentNode) !== null); @@ -131,9 +131,9 @@ Examples of **correct** code for this rule with the `"always"` option: /*eslint no-cond-assign: ["error", "always"]*/ // Assignment replaced by comparison -var x; +let x; if (x === 0) { - var b = 1; + const b = 1; } ``` diff --git a/docs/src/rules/no-constant-condition.md b/docs/src/rules/no-constant-condition.md index 26b6e8c54ba7..27988a149c7a 100644 --- a/docs/src/rules/no-constant-condition.md +++ b/docs/src/rules/no-constant-condition.md @@ -73,7 +73,7 @@ do { doSomethingForever(); } while (x = -1); -var result = 0 ? a : b; +const result = 0 ? a : b; if(input === "hello" || "bye"){ output(input); @@ -105,7 +105,7 @@ do { doSomething(); } while (x); -var result = x !== 0 ? a : b; +const result = x !== 0 ? a : b; if(input === "hello" || input === "bye"){ output(input); diff --git a/docs/src/rules/no-control-regex.md b/docs/src/rules/no-control-regex.md index 18a5ce40148b..be30905af43f 100644 --- a/docs/src/rules/no-control-regex.md +++ b/docs/src/rules/no-control-regex.md @@ -30,13 +30,13 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-control-regex: "error"*/ -var pattern1 = /\x00/; -var pattern2 = /\x0C/; -var pattern3 = /\x1F/; -var pattern4 = /\u000C/; -var pattern5 = /\u{C}/u; -var pattern6 = new RegExp("\x0C"); // raw U+000C character in the pattern -var pattern7 = new RegExp("\\x0C"); // \x0C pattern +const pattern1 = /\x00/; +const pattern2 = /\x0C/; +const pattern3 = /\x1F/; +const pattern4 = /\u000C/; +const pattern5 = /\u{C}/u; +const pattern6 = new RegExp("\x0C"); // raw U+000C character in the pattern +const pattern7 = new RegExp("\\x0C"); // \x0C pattern ``` ::: @@ -48,14 +48,14 @@ Examples of **correct** code for this rule: ```js /*eslint no-control-regex: "error"*/ -var pattern1 = /\x20/; -var pattern2 = /\u0020/; -var pattern3 = /\u{20}/u; -var pattern4 = /\t/; -var pattern5 = /\n/; -var pattern6 = new RegExp("\x20"); -var pattern7 = new RegExp("\\t"); -var pattern8 = new RegExp("\\n"); +const pattern1 = /\x20/; +const pattern2 = /\u0020/; +const pattern3 = /\u{20}/u; +const pattern4 = /\t/; +const pattern5 = /\n/; +const pattern6 = new RegExp("\x20"); +const pattern7 = new RegExp("\\t"); +const pattern8 = new RegExp("\\n"); ``` ::: diff --git a/docs/src/rules/no-dupe-args.md b/docs/src/rules/no-dupe-args.md index 748d52c2e21f..faedda898b15 100644 --- a/docs/src/rules/no-dupe-args.md +++ b/docs/src/rules/no-dupe-args.md @@ -25,7 +25,7 @@ function foo(a, b, a) { console.log("value of the second a:", a); } -var bar = function (a, b, a) { +const bar = function (a, b, a) { console.log("value of the second a:", a); }; ``` @@ -43,7 +43,7 @@ function foo(a, b, c) { console.log(a, b, c); } -var bar = function (a, b, c) { +const bar = function (a, b, c) { console.log(a, b, c); }; ``` From c03825730d277405c357388d62ed48b3973083ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Tue, 7 Jan 2025 01:48:12 +0900 Subject: [PATCH 38/51] docs: add `eqeqeq` in related rules to `no-eq-null` (#19310) --- docs/src/rules/no-eq-null.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/src/rules/no-eq-null.md b/docs/src/rules/no-eq-null.md index 43c95574ea33..393c28824251 100644 --- a/docs/src/rules/no-eq-null.md +++ b/docs/src/rules/no-eq-null.md @@ -1,6 +1,8 @@ --- title: no-eq-null rule_type: suggestion +related_rules: +- eqeqeq --- @@ -14,7 +16,7 @@ if (foo == null) { ## Rule Details -The `no-eq-null` rule aims reduce potential bug and unwanted behavior by ensuring that comparisons to `null` only match `null`, and not also `undefined`. As such it will flag comparisons to null when using `==` and `!=`. +The `no-eq-null` rule aims reduce potential bug and unwanted behavior by ensuring that comparisons to `null` only match `null`, and not also `undefined`. As such it will flag comparisons to `null` when using `==` and `!=`. Examples of **incorrect** code for this rule: From 26c3003bfca2f7d98950446fdf5b3978d17a3a60 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Mon, 6 Jan 2025 13:01:49 -0500 Subject: [PATCH 39/51] docs: Clarify dangers of eslint:all (#19318) --- docs/src/use/configure/configuration-files.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/use/configure/configuration-files.md b/docs/src/use/configure/configuration-files.md index d90c0fefec70..7f71553c9b55 100644 --- a/docs/src/use/configure/configuration-files.md +++ b/docs/src/use/configure/configuration-files.md @@ -370,7 +370,7 @@ export default [ ESLint has two predefined configurations for JavaScript: * `js.configs.recommended` - enables the rules that ESLint recommends everyone use to avoid potential errors. -* `js.configs.all` - enables all of the rules shipped with ESLint. +* `js.configs.all` - enables all of the rules shipped with ESLint. This configuration is **not recommended** for production use because it changes with every minor and major version of ESLint. Use at your own risk. To include these predefined configurations, install the `@eslint/js` package and then make any modifications to other properties in subsequent configuration objects: From 03f2f442a9a8bec15e89786980c07be5980cdac5 Mon Sep 17 00:00:00 2001 From: Thiago <57069875+ThiagoG8@users.noreply.github.com> Date: Tue, 7 Jan 2025 06:02:34 -0300 Subject: [PATCH 40/51] docs: rewrite var with const in rules examples (#19317) * docs: rewrite var with const in rules examples * docs: max-statements error fixed * replace let to const --- docs/src/rules/max-statements.md | 124 +++++++++++++++---------------- docs/src/rules/new-cap.md | 40 +++++----- docs/src/rules/no-alert.md | 2 +- 3 files changed, 83 insertions(+), 83 deletions(-) diff --git a/docs/src/rules/max-statements.md b/docs/src/rules/max-statements.md index 0688029ec2a0..3ec91592dc8d 100644 --- a/docs/src/rules/max-statements.md +++ b/docs/src/rules/max-statements.md @@ -16,9 +16,9 @@ The `max-statements` rule allows you to specify the maximum number of statements ```js function foo() { - var bar = 1; // one statement - var baz = 2; // two statements - var qux = 3; // three statements + const bar = 1; // one statement + const baz = 2; // two statements + const qux = 3; // three statements } ``` @@ -48,33 +48,33 @@ Examples of **incorrect** code for this rule with the default `{ "max": 10 }` op /*eslint max-statements: ["error", 10]*/ function foo() { - var foo1 = 1; - var foo2 = 2; - var foo3 = 3; - var foo4 = 4; - var foo5 = 5; - var foo6 = 6; - var foo7 = 7; - var foo8 = 8; - var foo9 = 9; - var foo10 = 10; - - var foo11 = 11; // Too many. + const foo1 = 1; + const foo2 = 2; + const foo3 = 3; + const foo4 = 4; + const foo5 = 5; + const foo6 = 6; + const foo7 = 7; + const foo8 = 8; + const foo9 = 9; + const foo10 = 10; + + const foo11 = 11; // Too many. } -let bar = () => { - var foo1 = 1; - var foo2 = 2; - var foo3 = 3; - var foo4 = 4; - var foo5 = 5; - var foo6 = 6; - var foo7 = 7; - var foo8 = 8; - var foo9 = 9; - var foo10 = 10; - - var foo11 = 11; // Too many. +const bar = () => { + const foo1 = 1; + const foo2 = 2; + const foo3 = 3; + const foo4 = 4; + const foo5 = 5; + const foo6 = 6; + const foo7 = 7; + const foo8 = 8; + const foo9 = 9; + const foo10 = 10; + + const foo11 = 11; // Too many. }; ``` @@ -88,43 +88,43 @@ Examples of **correct** code for this rule with the default `{ "max": 10 }` opti /*eslint max-statements: ["error", 10]*/ function foo() { - var foo1 = 1; - var foo2 = 2; - var foo3 = 3; - var foo4 = 4; - var foo5 = 5; - var foo6 = 6; - var foo7 = 7; - var foo8 = 8; - var foo9 = 9; + const foo1 = 1; + const foo2 = 2; + const foo3 = 3; + const foo4 = 4; + const foo5 = 5; + const foo6 = 6; + const foo7 = 7; + const foo8 = 8; + const foo9 = 9; return function () { // 10 // The number of statements in the inner function does not count toward the // statement maximum. - var bar; - var baz; + let bar; + let baz; return 42; }; } -let bar = () => { - var foo1 = 1; - var foo2 = 2; - var foo3 = 3; - var foo4 = 4; - var foo5 = 5; - var foo6 = 6; - var foo7 = 7; - var foo8 = 8; - var foo9 = 9; +const bar = () => { + const foo1 = 1; + const foo2 = 2; + const foo3 = 3; + const foo4 = 4; + const foo5 = 5; + const foo6 = 6; + const foo7 = 7; + const foo8 = 8; + const foo9 = 9; return function () { // 10 // The number of statements in the inner function does not count toward the // statement maximum. - var bar; - var baz; + let bar; + let baz; return 42; }; } @@ -170,17 +170,17 @@ Examples of additional **correct** code for this rule with the `{ "max": 10 }, { /*eslint max-statements: ["error", 10, { "ignoreTopLevelFunctions": true }]*/ function foo() { - var foo1 = 1; - var foo2 = 2; - var foo3 = 3; - var foo4 = 4; - var foo5 = 5; - var foo6 = 6; - var foo7 = 7; - var foo8 = 8; - var foo9 = 9; - var foo10 = 10; - var foo11 = 11; + const foo1 = 1; + const foo2 = 2; + const foo3 = 3; + const foo4 = 4; + const foo5 = 5; + const foo6 = 6; + const foo7 = 7; + const foo8 = 8; + const foo9 = 9; + const foo10 = 10; + const foo11 = 11; } ``` diff --git a/docs/src/rules/new-cap.md b/docs/src/rules/new-cap.md index f75c65fcb762..68ce9dce2554 100644 --- a/docs/src/rules/new-cap.md +++ b/docs/src/rules/new-cap.md @@ -7,7 +7,7 @@ rule_type: suggestion The `new` operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that `new` is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors. ```js -var friend = new Person(); +const friend = new Person(); ``` ## Rule Details @@ -64,7 +64,7 @@ Examples of **incorrect** code for this rule with the default `{ "newIsCap": tru ```js /*eslint new-cap: ["error", { "newIsCap": true }]*/ -var friend = new person(); +const friend = new person(); ``` ::: @@ -76,7 +76,7 @@ Examples of **correct** code for this rule with the default `{ "newIsCap": true ```js /*eslint new-cap: ["error", { "newIsCap": true }]*/ -var friend = new Person(); +const friend = new Person(); ``` ::: @@ -88,7 +88,7 @@ Examples of **correct** code for this rule with the `{ "newIsCap": false }` opti ```js /*eslint new-cap: ["error", { "newIsCap": false }]*/ -var friend = new person(); +const friend = new person(); ``` ::: @@ -102,7 +102,7 @@ Examples of **incorrect** code for this rule with the default `{ "capIsNew": tru ```js /*eslint new-cap: ["error", { "capIsNew": true }]*/ -var colleague = Person(); +const colleague = Person(); ``` ::: @@ -114,7 +114,7 @@ Examples of **correct** code for this rule with the default `{ "capIsNew": true ```js /*eslint new-cap: ["error", { "capIsNew": true }]*/ -var colleague = new Person(); +const colleague = new Person(); ``` ::: @@ -126,7 +126,7 @@ Examples of **correct** code for this rule with the `{ "capIsNew": false }` opti ```js /*eslint new-cap: ["error", { "capIsNew": false }]*/ -var colleague = Person(); +const colleague = Person(); ``` ::: @@ -140,9 +140,9 @@ Examples of additional **correct** code for this rule with the `{ "newIsCapExcep ```js /*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/ -var events = require('events'); +const events = require('events'); -var emitter = new events(); +const emitter = new events(); ``` ::: @@ -156,9 +156,9 @@ Examples of additional **correct** code for this rule with the `{ "newIsCapExcep ```js /*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\\.." }]*/ -var friend = new person.acquaintance(); +const friend = new person.acquaintance(); -var bestFriend = new person.friend(); +const bestFriend = new person.friend(); ``` ::: @@ -170,7 +170,7 @@ Examples of additional **correct** code for this rule with the `{ "newIsCapExcep ```js /*eslint new-cap: ["error", { "newIsCapExceptionPattern": "\\.bar$" }]*/ -var friend = new person.bar(); +const friend = new person.bar(); ``` ::: @@ -200,8 +200,8 @@ Examples of additional **correct** code for this rule with the `{ "capIsNewExcep ```js /*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^person\\.." }]*/ -var friend = person.Acquaintance(); -var bestFriend = person.Friend(); +const friend = person.Acquaintance(); +const bestFriend = person.Friend(); ``` ::: @@ -225,11 +225,11 @@ Examples of additional **correct** code for this rule with the `{ "capIsNewExcep ```js /*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Foo" }]*/ -var x = Foo(42); +const x = Foo(42); -var y = Foobar(42); +const y = Foobar(42); -var z = Foo.Bar(42); +const z = Foo.Bar(42); ``` ::: @@ -243,7 +243,7 @@ Examples of **incorrect** code for this rule with the default `{ "properties": t ```js /*eslint new-cap: ["error", { "properties": true }]*/ -var friend = new person.acquaintance(); +const friend = new person.acquaintance(); ``` ::: @@ -255,7 +255,7 @@ Examples of **correct** code for this rule with the default `{ "properties": tru ```js /*eslint new-cap: ["error", { "properties": true }]*/ -var friend = new person.Acquaintance(); +const friend = new person.Acquaintance(); ``` ::: @@ -267,7 +267,7 @@ Examples of **correct** code for this rule with the `{ "properties": false }` op ```js /*eslint new-cap: ["error", { "properties": false }]*/ -var friend = new person.acquaintance(); +const friend = new person.acquaintance(); ``` ::: diff --git a/docs/src/rules/no-alert.md b/docs/src/rules/no-alert.md index fe7ffd4de71e..b52e9ec235ca 100644 --- a/docs/src/rules/no-alert.md +++ b/docs/src/rules/no-alert.md @@ -47,7 +47,7 @@ customConfirm("Are you sure?"); customPrompt("Who are you?"); function foo() { - var alert = myCustomLib.customAlert; + const alert = myCustomLib.customAlert; alert(); } ``` From 6947901d14b18dbb2db259c9769bd8ac4cd04c3c Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Wed, 8 Jan 2025 18:06:27 +0100 Subject: [PATCH 41/51] docs: remove hardcoded edit link (#19323) --- docs/src/contribute/package-json-conventions.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/src/contribute/package-json-conventions.md b/docs/src/contribute/package-json-conventions.md index ad1810da9bdf..f347f154d733 100644 --- a/docs/src/contribute/package-json-conventions.md +++ b/docs/src/contribute/package-json-conventions.md @@ -1,6 +1,5 @@ --- title: Package.json Conventions -edit_link: https://github.com/eslint/eslint/edit/main/docs/src/contribute/package-json-conventions.md eleventyNavigation: key: package.json conventions parent: contribute to eslint From 98c86a99f7657a2f15ea30a251523446b10a7cad Mon Sep 17 00:00:00 2001 From: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:38:51 +0530 Subject: [PATCH 42/51] docs: `Edit this page` button link to different branches (#19228) * docs: edit this page link to different branches * apply suggestion * update variable names * get prerelease info from eslintVersion,js --- docs/.eleventy.js | 4 +++- docs/src/_data/eslintVersions.js | 7 +++++++ docs/src/_data/sites/en.yml | 1 + docs/src/_data/sites/zh-hans.yml | 1 + docs/src/_includes/layouts/doc.html | 8 +++++++- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/.eleventy.js b/docs/.eleventy.js index caebabcab639..cd50c27ee3c3 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -37,6 +37,7 @@ module.exports = function(eleventyConfig) { */ let pathPrefix = "/docs/head/"; + const isNumberVersion = process.env.BRANCH && /^v\d+\.x$/u.test(process.env.BRANCH); if (process.env.CONTEXT === "deploy-preview") { pathPrefix = "/"; @@ -44,7 +45,7 @@ module.exports = function(eleventyConfig) { pathPrefix = "/docs/latest/"; } else if (process.env.BRANCH === "next") { pathPrefix = "/docs/next/"; - } else if (process.env.BRANCH && /^v\d+\.x$/u.test(process.env.BRANCH)) { + } else if (isNumberVersion) { pathPrefix = `/docs/${process.env.BRANCH}/`; // `/docs/v8.x/`, `/docs/v9.x/`, `/docs/v10.x/` ... } @@ -60,6 +61,7 @@ module.exports = function(eleventyConfig) { eleventyConfig.addGlobalData("HEAD", process.env.BRANCH === "main"); eleventyConfig.addGlobalData("NOINDEX", process.env.BRANCH !== "latest"); eleventyConfig.addGlobalData("PATH_PREFIX", pathPrefix); + eleventyConfig.addGlobalData("is_number_version", isNumberVersion); eleventyConfig.addDataExtension("yml", contents => yaml.load(contents)); //------------------------------------------------------------------------------ diff --git a/docs/src/_data/eslintVersions.js b/docs/src/_data/eslintVersions.js index 16e6235df0e3..40ba029011d2 100644 --- a/docs/src/_data/eslintVersions.js +++ b/docs/src/_data/eslintVersions.js @@ -31,6 +31,7 @@ module.exports = async function() { const { items } = data; let foundItemForThisBranch = false; + let isPrereleasePhase = false; for (const item of items) { const isItemForThisBranch = item.branch === thisBranch; @@ -54,6 +55,10 @@ module.exports = async function() { if (isItemForThisBranch) { item.selected = true; } + + if (item.branch === "next") { + isPrereleasePhase = true; + } } // Add an empty item if this is not a production branch @@ -67,5 +72,7 @@ module.exports = async function() { }); } + data.isPrereleasePhase = isPrereleasePhase; + return data; }; diff --git a/docs/src/_data/sites/en.yml b/docs/src/_data/sites/en.yml index adde1125b361..8e330ee39738 100644 --- a/docs/src/_data/sites/en.yml +++ b/docs/src/_data/sites/en.yml @@ -121,4 +121,5 @@ footer: edit_link: start_with: https://github.com/eslint/eslint/edit/main/docs/ + start_with_latest: https://github.com/eslint/eslint/edit/latest/docs/ text: Edit this page diff --git a/docs/src/_data/sites/zh-hans.yml b/docs/src/_data/sites/zh-hans.yml index bd27824486f9..8f5587a221a7 100644 --- a/docs/src/_data/sites/zh-hans.yml +++ b/docs/src/_data/sites/zh-hans.yml @@ -119,4 +119,5 @@ footer: edit_link: start_with: https://github.com/eslint/eslint/edit/main/docs/ + start_with_latest: https://github.com/eslint/eslint/edit/latest/docs/ text: 编辑此页 diff --git a/docs/src/_includes/layouts/doc.html b/docs/src/_includes/layouts/doc.html index 3c9837947817..87917676b2fd 100644 --- a/docs/src/_includes/layouts/doc.html +++ b/docs/src/_includes/layouts/doc.html @@ -102,7 +102,13 @@

{{ title }}

{% if edit_link %} {{ edit_link }} {% else %} - {{ site.edit_link.start_with }}{{ page.inputPath }} + {% if eslintVersions.isPrereleasePhase and GIT_BRANCH === 'latest' %} + {{ site.edit_link.start_with_latest }}{{ page.inputPath }} + {% elseif is_number_version %} + https://github.com/eslint/eslint/edit/{{ GIT_BRANCH }}/docs/{{ page.inputPath }} + {% else %} + {{ site.edit_link.start_with }}{{ page.inputPath }} + {% endif %} {% endif %} " class="c-btn c-btn--secondary">{{ site.edit_link.text }} From 0b680b3cc19c1e8d79ab94e7160051177c4adfe7 Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Thu, 9 Jan 2025 08:08:36 +0000 Subject: [PATCH 43/51] docs: Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9aec95f558c4..1a35c315535f 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,7 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).

Platinum Sponsors

Automattic Airbnb

Gold Sponsors

trunk.io

Silver Sponsors

-

SERP Triumph JetBrains Liftoff American Express Workleap

Bronze Sponsors

+

SERP Triumph JetBrains Liftoff American Express

Bronze Sponsors

Cybozu Anagram Solver Icons8 Discord GitBook Nx Mercedes-Benz Group HeroCoders

Technology Sponsors

Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work. From f3aeefbd6547c25d78819ab7e77cf36a2c26611c Mon Sep 17 00:00:00 2001 From: PoloSpark Date: Thu, 9 Jan 2025 06:07:38 -0700 Subject: [PATCH 44/51] docs: rewrite using let and const in rule examples (#19320) * docs: rewrite var using let and const * docs: rewrite examples using let and const * docs: rewrite var using let and const * Update docs/src/rules/accessor-pairs.md Co-authored-by: Amaresh S M * Update docs/src/rules/accessor-pairs.md Co-authored-by: Amaresh S M * docs: rewrite using const * Update accessor-pairs.md * Update accessor-pairs.md * Update let variables to const --------- Co-authored-by: Amaresh S M --- docs/src/rules/accessor-pairs.md | 44 ++++----- docs/src/rules/array-bracket-newline.md | 120 ++++++++++++------------ 2 files changed, 82 insertions(+), 82 deletions(-) diff --git a/docs/src/rules/accessor-pairs.md b/docs/src/rules/accessor-pairs.md index b84205d34935..776b116e6d28 100644 --- a/docs/src/rules/accessor-pairs.md +++ b/docs/src/rules/accessor-pairs.md @@ -17,7 +17,7 @@ Here are some examples: ```js // Bad -var o = { +const o = { set a(value) { this.val = value; } @@ -25,7 +25,7 @@ var o = { // Good -var o = { +const p = { set a(value) { this.val = value; }, @@ -61,15 +61,15 @@ Examples of **incorrect** code for the default `{ "setWithoutGet": true }` optio ```js /*eslint accessor-pairs: "error"*/ -var o = { +const q = { set a(value) { this.val = value; } }; -var o = {d: 1}; -Object.defineProperty(o, 'c', { +const r = {d: 1}; +Object.defineProperty(r, 'c', { set: function(value) { this.val = value; } @@ -85,7 +85,7 @@ Examples of **correct** code for the default `{ "setWithoutGet": true }` option: ```js /*eslint accessor-pairs: "error"*/ -var o = { +const s = { set a(value) { this.val = value; }, @@ -94,8 +94,8 @@ var o = { } }; -var o = {d: 1}; -Object.defineProperty(o, 'c', { +const t = {d: 1}; +Object.defineProperty(t, 'c', { set: function(value) { this.val = value; }, @@ -117,27 +117,27 @@ Examples of **incorrect** code for the `{ "getWithoutSet": true }` option: ```js /*eslint accessor-pairs: ["error", { "getWithoutSet": true }]*/ -var o = { +const u = { set a(value) { this.val = value; } }; -var o = { +const v = { get a() { return this.val; } }; -var o = {d: 1}; -Object.defineProperty(o, 'c', { +const w = {d: 1}; +Object.defineProperty(w, 'c', { set: function(value) { this.val = value; } }); -var o = {d: 1}; -Object.defineProperty(o, 'c', { +const x = {d: 1}; +Object.defineProperty(x, 'c', { get: function() { return this.val; } @@ -152,7 +152,7 @@ Examples of **correct** code for the `{ "getWithoutSet": true }` option: ```js /*eslint accessor-pairs: ["error", { "getWithoutSet": true }]*/ -var o = { +const y = { set a(value) { this.val = value; }, @@ -161,8 +161,8 @@ var o = { } }; -var o = {d: 1}; -Object.defineProperty(o, 'c', { +const z = {d: 1}; +Object.defineProperty(z, 'c', { set: function(value) { this.val = value; }, @@ -281,14 +281,14 @@ might not report a missing pair for a getter/setter that has a computed key, lik ```js /*eslint accessor-pairs: "error"*/ -var a = 1; +const z = 1; // no warnings -var o = { - get [a++]() { +const a = { + get [z++]() { return this.val; }, - set [a++](value) { + set [z++](value) { this.val = value; } }; @@ -301,7 +301,7 @@ might not report a missing pair for a getter/setter, like in the following examp /*eslint accessor-pairs: "error"*/ // no warnings -var o = { +const b = { get a() { return this.val; }, diff --git a/docs/src/rules/array-bracket-newline.md b/docs/src/rules/array-bracket-newline.md index 900fea16fb09..2c1c573c8014 100644 --- a/docs/src/rules/array-bracket-newline.md +++ b/docs/src/rules/array-bracket-newline.md @@ -35,12 +35,12 @@ Examples of **incorrect** code for this rule with the `"always"` option: ```js /*eslint array-bracket-newline: ["error", "always"]*/ -var a = []; -var b = [1]; -var c = [1, 2]; -var d = [1, +const a = []; +const b = [1]; +const c = [1, 2]; +const d = [1, 2]; -var e = [function foo() { +const e = [function foo() { dosomething(); }]; ``` @@ -54,19 +54,19 @@ Examples of **correct** code for this rule with the `"always"` option: ```js /*eslint array-bracket-newline: ["error", "always"]*/ -var a = [ +const a = [ ]; -var b = [ +const b = [ 1 ]; -var c = [ +const c = [ 1, 2 ]; -var d = [ +const d = [ 1, 2 ]; -var e = [ +const e = [ function foo() { dosomething(); } @@ -84,19 +84,19 @@ Examples of **incorrect** code for this rule with the `"never"` option: ```js /*eslint array-bracket-newline: ["error", "never"]*/ -var a = [ +const a = [ ]; -var b = [ +const b = [ 1 ]; -var c = [ +const c = [ 1, 2 ]; -var d = [ +const d = [ 1, 2 ]; -var e = [ +const e = [ function foo() { dosomething(); } @@ -112,12 +112,12 @@ Examples of **correct** code for this rule with the `"never"` option: ```js /*eslint array-bracket-newline: ["error", "never"]*/ -var a = []; -var b = [1]; -var c = [1, 2]; -var d = [1, +const a = []; +const b = [1]; +const c = [1, 2]; +const d = [1, 2]; -var e = [function foo() { +const e = [function foo() { dosomething(); }]; ``` @@ -133,15 +133,15 @@ Examples of **incorrect** code for this rule with the `"consistent"` option: ```js /*eslint array-bracket-newline: ["error", "consistent"]*/ -var a = [1 +const a = [1 ]; -var b = [ +const b = [ 1]; -var c = [function foo() { +const c = [function foo() { dosomething(); } ] -var d = [ +const d = [ function foo() { dosomething(); }] @@ -156,17 +156,17 @@ Examples of **correct** code for this rule with the `"consistent"` option: ```js /*eslint array-bracket-newline: ["error", "consistent"]*/ -var a = []; -var b = [ +const a = []; +const b = [ ]; -var c = [1]; -var d = [ +const c = [1]; +const d = [ 1 ]; -var e = [function foo() { +const e = [function foo() { dosomething(); }]; -var f = [ +const f = [ function foo() { dosomething(); } @@ -184,17 +184,17 @@ Examples of **incorrect** code for this rule with the default `{ "multiline": tr ```js /*eslint array-bracket-newline: ["error", { "multiline": true }]*/ -var a = [ +const a = [ ]; -var b = [ +const b = [ 1 ]; -var c = [ +const c = [ 1, 2 ]; -var d = [1, +const d = [1, 2]; -var e = [function foo() { +const e = [function foo() { dosomething(); }]; ``` @@ -208,14 +208,14 @@ Examples of **correct** code for this rule with the default `{ "multiline": true ```js /*eslint array-bracket-newline: ["error", { "multiline": true }]*/ -var a = []; -var b = [1]; -var c = [1, 2]; -var d = [ +const a = []; +const b = [1]; +const c = [1, 2]; +const d = [ 1, 2 ]; -var e = [ +const e = [ function foo() { dosomething(); } @@ -233,15 +233,15 @@ Examples of **incorrect** code for this rule with the `{ "minItems": 2 }` option ```js /*eslint array-bracket-newline: ["error", { "minItems": 2 }]*/ -var a = [ +const a = [ ]; -var b = [ +const b = [ 1 ]; -var c = [1, 2]; -var d = [1, +const c = [1, 2]; +const d = [1, 2]; -var e = [ +const e = [ function foo() { dosomething(); } @@ -257,16 +257,16 @@ Examples of **correct** code for this rule with the `{ "minItems": 2 }` option: ```js /*eslint array-bracket-newline: ["error", { "minItems": 2 }]*/ -var a = []; -var b = [1]; -var c = [ +const a = []; +const b = [1]; +const c = [ 1, 2 ]; -var d = [ +const d = [ 1, 2 ]; -var e = [function foo() { +const e = [function foo() { dosomething(); }]; ``` @@ -282,15 +282,15 @@ Examples of **incorrect** code for this rule with the `{ "multiline": true, "min ```js /*eslint array-bracket-newline: ["error", { "multiline": true, "minItems": 2 }]*/ -var a = [ +const a = [ ]; -var b = [ +const b = [ 1 ]; -var c = [1, 2]; -var d = [1, +const c = [1, 2]; +const d = [1, 2]; -var e = [function foo() { +const e = [function foo() { dosomething(); }]; ``` @@ -304,16 +304,16 @@ Examples of **correct** code for this rule with the `{ "multiline": true, "minIt ```js /*eslint array-bracket-newline: ["error", { "multiline": true, "minItems": 2 }]*/ -var a = []; -var b = [1]; -var c = [ +const a = []; +const b = [1]; +const c = [ 1, 2 ]; -var d = [ +const d = [ 1, 2 ]; -var e = [ +const e = [ function foo() { dosomething(); } From 8e1a898411fd16c73332d7a2dd28aff9bac8da01 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 9 Jan 2025 18:40:02 +0530 Subject: [PATCH 45/51] docs: add tabs to cli code blocks (#18784) * feat: add tabs component * docs: add tabs in ci reference page * docs: add tabs in dev env page * docs: add tabs in 7 pages The pages are Tests, PRs, Custom Parsers, Integration Tutorials, flags, config files and debug. * docs: add tabs to 6 pages * fix: parsing problems * chore: remove code_tabs component Added two other macro components * chore: add npx tabs component * feat: add tabs component * docs: add tabs in ci reference page * docs: add tabs in dev env page * docs: add tabs in 7 pages The pages are Tests, PRs, Custom Parsers, Integration Tutorials, flags, config files and debug. * docs: add tabs to 6 pages * fix: parsing problems * chore: remove code_tabs component Added two other macro components * chore: add npx tabs component * chore: revert * feat: add tabs component * docs: add tabs in ci reference page * docs: add tabs in dev env page * docs: add tabs in 7 pages The pages are Tests, PRs, Custom Parsers, Integration Tutorials, flags, config files and debug. * docs: add tabs to 6 pages * fix: parsing problems * chore: remove code_tabs component Added two other macro components * chore: add npx tabs component * feat: add tabs component * fix: parsing problems * chore: remove code_tabs component Added two other macro components * chore: revert * feat: npx_tabs component * chore: update params * chore: update comments in the component * fix: params Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * fix: comment render Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * docs: add npx component to all pages except cli ref * fix: typo * docs: add npx component to cli ref page * fix: commands * docs: convert all the npm commands * fix:linting * fix: remove test commands conversion * fix: param name Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * fix: command Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * fix: npx command Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * fix: commands from create to init * fix: typos in commands * fix: counting of the steps * fix: typo Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * fix: rearranged command and args also added npm tab component to config files page * fix: linting * fix: command Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * fix: args order Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * fix: spacing Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * fix: test commands * fix: create and init commands * chore: remove extra line * fix: argument names and removed unsused imports * fix: package name Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * fix: component render Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * docs: add npx component to stats page * fix: remove extra line * fix: styling * fix: build * Update docs/src/_includes/components/npx_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npm_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npx_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npx_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npx_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npx_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npx_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npx_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npx_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * chore: add command conversion json data * chore: add semicolon * delete conversions.js * rename conversions.json * Update docs/src/_includes/components/npm_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npm_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npm_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/contribute/development-environment.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npm_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npm_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Delete docs/src/_includes/components/_globals.html * Update docs/src/extend/custom-parsers.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/extend/custom-rule-tutorial.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/integrate/integration-tutorial.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/use/command-line-interface.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/use/configure/configuration-files.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/use/migrating-from-jscs.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/use/getting-started.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/use/configure/migration-guide.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_data/conversions.json Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/use/getting-started.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/use/getting-started.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/use/getting-started.md Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_data/conversions.json Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_data/conversions.json Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_data/conversions.json Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_data/conversions.json Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npm_tabs.macro.html Co-authored-by: Amaresh S M * fix: npm tab indentation * chore: remove extra conversion field * Update docs/src/_includes/components/npm_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npm_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npm_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_includes/components/npm_tabs.macro.html Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_data/conversions.json Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_data/conversions.json Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * Update docs/src/_data/conversions.json Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> * fix: lint * remove `comment: null` from npx_tabs --------- Co-authored-by: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> Co-authored-by: Amaresh S M --- docs/src/_data/conversions.json | 42 ++ .../_includes/components/npm_tabs.macro.html | 46 ++ .../_includes/components/npx_tabs.macro.html | 46 ++ .../src/contribute/development-environment.md | 25 +- docs/src/extend/custom-parsers.md | 10 +- docs/src/extend/custom-rule-tutorial.md | 42 +- docs/src/extend/stats.md | 9 +- docs/src/integrate/integration-tutorial.md | 18 +- docs/src/pages/flags.md | 9 +- docs/src/use/command-line-interface.md | 512 +++++++++++------- docs/src/use/configure/configuration-files.md | 42 +- docs/src/use/configure/debug.md | 23 +- docs/src/use/configure/ignore.md | 23 +- docs/src/use/configure/migration-guide.md | 26 +- docs/src/use/formatters/index.md | 9 +- docs/src/use/getting-started.md | 58 +- docs/src/use/migrating-from-jscs.md | 26 +- 17 files changed, 659 insertions(+), 307 deletions(-) create mode 100644 docs/src/_data/conversions.json create mode 100644 docs/src/_includes/components/npm_tabs.macro.html create mode 100644 docs/src/_includes/components/npx_tabs.macro.html diff --git a/docs/src/_data/conversions.json b/docs/src/_data/conversions.json new file mode 100644 index 000000000000..865c27a40476 --- /dev/null +++ b/docs/src/_data/conversions.json @@ -0,0 +1,42 @@ +{ + "toNpmCommands": { + "install": "install", + "init": "init", + "init-create": "init" + }, + "toNpmArgs": { + "--global": "--global", + "--save-dev": "--save-dev", + "-y": "-y" + }, + "toYarnCommands": { + "install": "add", + "init": "init", + "init-create": "create" + }, + "toYarnArgs": { + "--global": "global", + "--save-dev": "--dev", + "-y": "-y" + }, + "toPnpmCommands" : { + "install": "add", + "init": "init", + "init-create": "create" + }, + "toPnpmArgs" : { + "--global": "--global", + "--save-dev": "--save-dev", + "-y": "-y" + } , + "toBunCommands" : { + "install": "add", + "init": "init", + "init-create": "create" + }, + "toBunArgs" : { + "--global": "--global", + "--save-dev": "--dev", + "-y": "-y" + } +} diff --git a/docs/src/_includes/components/npm_tabs.macro.html b/docs/src/_includes/components/npm_tabs.macro.html new file mode 100644 index 000000000000..1dfc5dc08885 --- /dev/null +++ b/docs/src/_includes/components/npm_tabs.macro.html @@ -0,0 +1,46 @@ +{%- macro npm_tabs(params) -%} +
+ +
+

npm

+ +```shell +{% if params.comment %}# {{ params.comment | safe }}{{ "\n" }}{% endif -%} +npm {% if conversions.toNpmCommands[params.command] %}{{ conversions.toNpmCommands[params.command] | safe }}{% else %}{{ params.command | safe }}{% endif -%}{% for arg in params.args %} {{ conversions.toNpmArgs[arg] | safe }}{% endfor %}{% for package in params.packages %} {{ package | safe }}{% endfor %} +``` + +
+
+

yarn

+ +```shell +{% if params.comment %}# {{ params.comment | safe }}{{ "\n" }}{% endif -%} +yarn {% if params.args.includes("--global") %}{{ conversions.toYarnArgs["--global"] | safe }} {% endif -%} {% if conversions.toYarnCommands[params.command] %}{{ conversions.toYarnCommands[params.command] | safe }}{% else %}{{ params.command | safe }}{% endif -%}{% for arg in params.args %}{% if arg !== "--global" %} {{ conversions.toYarnArgs[arg] | safe }}{% endif -%}{% endfor %}{% for package in params.packages %} {{ package.replace("@eslint/config@latest", "@eslint/config") | safe }}{% endfor %} +``` + +
+
+

pnpm

+ +```shell +{% if params.comment %}# {{ params.comment | safe }}{{ "\n" }}{% endif -%} +pnpm {% if conversions.toPnpmCommands[params.command] %}{{ conversions.toPnpmCommands[params.command] | safe }}{% else %}{{ params.command | safe }}{% endif -%}{% for arg in params.args %} {{ conversions.toPnpmArgs[arg] | safe}}{% endfor %}{% for package in params.packages %} {{ package | safe }}{% endfor %} +``` + +
+
+

bun

+ +```shell +{% if params.comment %}# {{params.comment | safe}}{{"\n"}}{% endif -%} +bun {% if conversions.toBunCommands[params.command] %}{{ conversions.toBunCommands[params.command] | safe }}{% else %}{{ params.command | safe }}{% endif -%}{% for arg in params.args %} {{ conversions.toBunArgs[arg] | safe }}{% endfor %}{% for package in params.packages %} {{ package | safe }}{% endfor %} +``` + +
+
+{%- endmacro -%} \ No newline at end of file diff --git a/docs/src/_includes/components/npx_tabs.macro.html b/docs/src/_includes/components/npx_tabs.macro.html new file mode 100644 index 000000000000..e45de8b81df8 --- /dev/null +++ b/docs/src/_includes/components/npx_tabs.macro.html @@ -0,0 +1,46 @@ +{%- macro npx_tabs(params) -%} +
+ +
+

npm

+ +```shell +{% if params.comment %}# {{ params.comment | safe }}{{ "\n" }}{% endif -%} +{% if params.previousCommands %}{% for item in params.previousCommands %}{{ item | safe }} {% endfor %}| {% endif -%}npx {{ params.package | safe }} {% for item in params.args %}{{ item | safe }} {% endfor %} +``` + +
+
+

yarn

+ +```shell +{% if params.comment %}# {{ params.comment | safe }}{{ "\n" }}{% endif -%} +{% if params.previousCommands %}{% for item in params.previousCommands %}{{ item | safe }} {% endfor %}| {% endif -%}yarn dlx {{ params.package | safe }} {% for item in params.args %}{{ item | safe }} {% endfor %} +``` + +
+
+

pnpm

+ +```shell +{% if params.comment %}# {{ params.comment | safe }}{{ "\n" }}{% endif -%} +{% if params.previousCommands %}{% for item in params.previousCommands %}{{ item | safe }} {% endfor %}| {% endif -%}pnpm dlx {{ params.package | safe }} {% for item in params.args %}{{ item | safe }} {% endfor %} +``` + +
+
+

bun

+ +```shell +{% if params.comment %}# {{ params.comment | safe }}{{ "\n" }}{% endif -%} +{% if params.previousCommands %}{% for item in params.previousCommands %}{{ item | safe }} {% endfor %}| {% endif -%}bunx {{ params.package | safe }} {% for item in params.args %}{{ item | safe }} {% endfor %} +``` + +
+
+{%- endmacro -%} \ No newline at end of file diff --git a/docs/src/contribute/development-environment.md b/docs/src/contribute/development-environment.md index 2f1033fed6db..ef1190c89a14 100644 --- a/docs/src/contribute/development-environment.md +++ b/docs/src/contribute/development-environment.md @@ -7,6 +7,8 @@ eleventyNavigation: order: 6 --- +{%- from 'components/npm_tabs.macro.html' import npm_tabs with context %} + ESLint has a very lightweight development environment that makes updating code fast and easy. This is a step-by-step guide to setting up a local development environment that will let you contribute back to the project. ## Step 1: Install Node.js @@ -29,9 +31,14 @@ Once you've cloned the repository, run `npm install` to get all the necessary de ```shell cd eslint -npm install ``` +{{ npm_tabs({ + command: "install", + packages: [], + args: [] +}) }} + You must be connected to the Internet for this step to work. You'll see a lot of utilities being downloaded. **Note:** It's a good idea to re-run `npm install` whenever you pull from the main repository to ensure you have the latest development dependencies. @@ -52,15 +59,19 @@ Now, the remote `upstream` points to the upstream source. [Yeoman](https://yeoman.io) is a scaffold generator that ESLint uses to help streamline development of new rules. If you don't already have Yeoman installed, you can install it via npm: -```shell -npm install -g yo -``` +{{ npm_tabs({ + command: "install", + packages: ["yo"], + args: ["--global"] +}) }} Then, you can install the ESLint Yeoman generator: -```shell -npm install -g generator-eslint -``` +{{ npm_tabs({ + command: "install", + packages: ["generator-eslint"], + args: ["--global"] +}) }} Please see the [generator documentation](https://github.com/eslint/generator-eslint) for instructions on how to use it. diff --git a/docs/src/extend/custom-parsers.md b/docs/src/extend/custom-parsers.md index 80b08eea2f3d..fda2fa4276d5 100644 --- a/docs/src/extend/custom-parsers.md +++ b/docs/src/extend/custom-parsers.md @@ -8,6 +8,8 @@ eleventyNavigation: --- +{%- from 'components/npm_tabs.macro.html' import npm_tabs with context %} + ESLint custom parsers let you extend ESLint to support linting new non-standard JavaScript language features or custom syntax in your code. A parser is responsible for taking your code and transforming it into an abstract syntax tree (AST) that ESLint can then analyze and lint. ## Creating a Custom Parser @@ -117,9 +119,11 @@ For more information on publishing an npm package, refer to the [npm documentati Once you've published the npm package, you can use it by adding the package to your project. For example: -```shell -npm install eslint-parser-myparser --save-dev -``` +{{ npm_tabs({ + command: "install", + packages: ["eslint-parser-myparser"], + args: ["--save-dev"] +}) }} Then add the custom parser to your ESLint configuration file with the `languageOptions.parser` property. For example: diff --git a/docs/src/extend/custom-rule-tutorial.md b/docs/src/extend/custom-rule-tutorial.md index 3523d7054235..cd5eb540e37c 100644 --- a/docs/src/extend/custom-rule-tutorial.md +++ b/docs/src/extend/custom-rule-tutorial.md @@ -6,6 +6,10 @@ eleventyNavigation: title: Custom Rule Tutorial order: 1 --- + +{%- from 'components/npm_tabs.macro.html' import npm_tabs with context %} +{%- from 'components/npx_tabs.macro.html' import npx_tabs %} + This tutorial covers how to create a custom rule for ESLint and distribute it with a plugin. You can create custom rules to validate if your code meets a certain expectation, and determine what to do if it does not meet that expectation. Plugins package custom rules and other configuration, allowing you to easily share and reuse them in different projects. @@ -189,9 +193,11 @@ touch enforce-foo-bar.test.js You will use the `eslint` package in the test file. Install it as a development dependency: -```shell -npm install eslint --save-dev -``` +{{ npm_tabs({ + command: "install", + packages: ["eslint"], + args: ["--save-dev"] +}) }} And add a test script to your `package.json` file to run the tests: @@ -345,9 +351,10 @@ Now you're ready to test the custom rule with the locally defined plugin. Run ESLint on `example.js`: -```shell -npx eslint example.js -``` +{{ npx_tabs({ + package: "eslint", + args: ["example.js"] +}) }} This produces the following output in the terminal: @@ -411,9 +418,12 @@ Next, you can use the published plugin. Run the following command in your project to download the package: -```shell -npm install --save-dev eslint-plugin-example # Add your package name here -``` +{{ npm_tabs({ + command: "install", + packages: ["eslint-plugin-example"], + args: ["--save-dev"], + comment: "Add your package name here" +}) }} Update the `eslint.config.js` to use the packaged version of the plugin: @@ -431,9 +441,10 @@ Now you're ready to test the custom rule. Run ESLint on the `example.js` file you created in step 8, now with the downloaded plugin: -```shell -npx eslint example.js -``` +{{ npx_tabs({ + package: "eslint", + args: ["example.js"] +}) }} This produces the following output in the terminal: @@ -449,9 +460,10 @@ As you can see in the above message, you can actually fix the issue with the `-- Run ESLint again with the `--fix` flag: -```shell -npx eslint example.js --fix -``` +{{ npx_tabs({ + package: "eslint", + args: ["example.js", "--fix"] +}) }} There is no error output in the terminal when you run this, but you can see the fix applied in `example.js`. You should see the following: diff --git a/docs/src/extend/stats.md b/docs/src/extend/stats.md index 3e54598ab6f5..1f5541d606f3 100644 --- a/docs/src/extend/stats.md +++ b/docs/src/extend/stats.md @@ -7,6 +7,8 @@ eleventyNavigation: order: 6 --- +{%- from 'components/npx_tabs.macro.html' import npx_tabs %} + While an analysis of the overall rule performance for an ESLint run can be carried out by setting the [TIMING](./custom-rules#profile-rule-performance) environment variable, it can sometimes be useful to acquire more *granular* timing data (lint time per file per rule) or collect other measures of interest. In particular, when developing new [custom plugins](./plugins) and evaluating/benchmarking new languages or rule sets. For these use cases, you can optionally collect runtime statistics from ESLint. ## Enable stats collection @@ -51,9 +53,10 @@ function a() { Run ESLint with `--stats` and output to JSON via the built-in [`json` formatter](../use/formatters/): -```bash -npx eslint file-to-fix.js --fix --stats -f json -``` +{{ npx_tabs({ + package: "eslint", + args: ["file-to-fix.js", "--fix", "--stats", "-f", "json"] +}) }} This yields the following `stats` entry as part of the formatted lint results object: diff --git a/docs/src/integrate/integration-tutorial.md b/docs/src/integrate/integration-tutorial.md index 1644b91528a4..b4115bda1279 100644 --- a/docs/src/integrate/integration-tutorial.md +++ b/docs/src/integrate/integration-tutorial.md @@ -7,6 +7,8 @@ eleventyNavigation: order: 1 --- +{%- from 'components/npm_tabs.macro.html' import npm_tabs with context %} + This guide walks you through integrating the `ESLint` class to lint files and retrieve results, which can be useful for creating integrations with other projects. @@ -65,15 +67,19 @@ cd eslint-integration Initialize the project with a `package.json` file: -```shell -npm init -y -``` +{{ npm_tabs({ + command: "init", + packages: [], + args: ["-y"] +}) }} Install the `eslint` package as a dependency (**not** as a dev dependency): -```shell -npm install eslint -``` +{{ npm_tabs({ + command: "install", + packages: ["eslint"], + args: [] +}) }} Create a new file called `example-eslint-integration.js` in the project root: diff --git a/docs/src/pages/flags.md b/docs/src/pages/flags.md index cad7fe71b102..74f7b00ebdd7 100644 --- a/docs/src/pages/flags.md +++ b/docs/src/pages/flags.md @@ -8,6 +8,8 @@ eleventyNavigation: order: 6 --- +{%- from 'components/npx_tabs.macro.html' import npx_tabs %} + ESLint ships experimental and future breaking changes behind feature flags to let users opt-in to behavior they want. Flags are used in these situations: 1. When a feature is experimental and not ready to be enabled for everyone. @@ -66,9 +68,10 @@ Because feature flags are strictly opt-in, you need to manually enable the flags On the command line, you can specify feature flags using the `--flag` option. You can specify as many flags as you'd like: -```shell -npx eslint --flag flag_one --flag flag_two file.js -``` +{{ npx_tabs({ + package: "eslint", + args: ["--flag", "flag_one", "--flag", "flag_two", "file.js"] +}) }} ### Enable Feature Flags with the API diff --git a/docs/src/use/command-line-interface.md b/docs/src/use/command-line-interface.md index 5f6dba8afb52..7e2680b4dfe9 100644 --- a/docs/src/use/command-line-interface.md +++ b/docs/src/use/command-line-interface.md @@ -8,6 +8,9 @@ eleventyNavigation: --- +{%- from 'components/npm_tabs.macro.html' import npm_tabs with context %} +{%- from 'components/npx_tabs.macro.html' import npx_tabs %} + The ESLint Command Line Interface (CLI) lets you execute linting from the terminal. The CLI has a variety of options that you can pass to configure ESLint. ## Run the CLI @@ -16,32 +19,45 @@ ESLint requires Node.js for installation. Follow the instructions in the [Gettin Most users use [`npx`](https://docs.npmjs.com/cli/v8/commands/npx) to run ESLint on the command line like this: -```shell -npx eslint [options] [file|dir|glob]* -``` +{{ npx_tabs ({ + package: "eslint", + args: ["[options]", "[file|dir|glob]*"] +}) }} Such as: -```shell -# Run on two files -npx eslint file1.js file2.js +{{ npx_tabs ({ + package: "eslint", + args: ["file1.js", "file2.js"], + comment: "Run on two files" +}) }} -# Run on multiple files -npx eslint lib/** -``` +or + +{{ npx_tabs ({ + package: "eslint", + args: ["lib/**"], + comment: "Run on multiple files" +}) }} Please note that when passing a glob as a parameter, it is expanded by your shell. The results of the expansion can vary depending on your shell, and its configuration. If you want to use node `glob` syntax, you have to quote your parameter (using double quotes if you need it to run in Windows), as follows: -```shell -npx eslint "lib/**" -``` +{{ npx_tabs ({ + package: "eslint", + args: ["\"lib/**\""] +}) }} If you are using a [flat configuration file](./configure/configuration-files) (`eslint.config.js`), you can also omit the file arguments and ESLint will use `.`. For instance, these two lines perform the same operation: -```shell -npx eslint . -npx eslint -``` +{{ npx_tabs ({ + package: "eslint", + args: ["."] +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: [] +}) }} If you are not using a flat configuration file, running ESLint without file arguments results in an error. @@ -53,11 +69,17 @@ Options that accept multiple values can be specified by repeating the option or Examples of options that accept multiple values: -```shell -npx eslint --global describe --global it tests/ -# OR -npx eslint --global describe,it tests/ -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--global", "describe", "--global", "it", "tests/"] +}) }} + +OR + +{{ npx_tabs ({ + package: "eslint", + args: ["--global", "describe,it", "tests/"] +}) }} ## Options @@ -139,9 +161,10 @@ Miscellaneous: ##### `--no-eslintrc` example -```shell -npx eslint --no-eslintrc file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--no-eslintrc", "file.js"] +}) }} #### `-c`, `--config` @@ -152,9 +175,10 @@ This option allows you to specify an additional configuration file for ESLint (s ##### `-c`, `--config` example -```shell -npx eslint -c ~/my.eslint.config.js file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["-c", "~/my.eslint.config.js", "file.js"] +}) }} This example uses the configuration file at `~/my.eslint.config.js`, which is used instead of searching for an `eslint.config.js` file. @@ -166,9 +190,10 @@ This example uses the configuration file at `~/my.eslint.config.js`, which is us ##### `--inspect-config` example -```shell -npx eslint --inspect-config -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--inspect-config"] +}) }} #### `--env` @@ -181,10 +206,15 @@ Details about the global variables defined by each environment are available in ##### `--env` example -```shell -npx eslint --env browser,node file.js -npx eslint --env browser --env node file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--env", "browser,node", "file.js"] +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--env", "browser", "--env", "node", "file.js"] +}) }} #### `--ext` @@ -200,16 +230,23 @@ This option allows you to specify which file extensions ESLint uses when searchi ##### `--ext` example -```shell -# Use only .ts extension -npx eslint . --ext .ts +{{ npx_tabs ({ + package: "eslint", + args: [".", "--ext", ".ts"], + comment: "Use only .ts extension" +}) }} -# Use both .js and .ts -npx eslint . --ext .js --ext .ts +{{ npx_tabs ({ + package: "eslint", + args: [".", "--ext", ".js", "--ext", ".ts"], + comment: "Use both .js and .ts" +}) }} -# Also use both .js and .ts -npx eslint . --ext .js,.ts -``` +{{ npx_tabs ({ + package: "eslint", + args: [".", "--ext", ".js,.ts"], + comment: "Also use both .js and .ts" +}) }} #### `--global` @@ -220,10 +257,15 @@ This option defines global variables so that they are not flagged as undefined ##### `--global` example -```shell -npx eslint --global require,exports:true file.js -npx eslint --global require --global exports:true -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--global", "require,exports:true", "file.js"] +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--global", "require", "--global", "exports:true"] +}) }} #### `--parser` @@ -235,10 +277,11 @@ This option allows you to specify a parser to be used by ESLint. ##### `--parser` example -```shell -# Use TypeScript ESLint parser -npx eslint --parser @typescript-eslint/parser file.ts -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--parser", "@typescript-eslint/parser", "file.ts"], + comment: "Use TypeScript ESLint parser" +}) }} #### `--parser-options` @@ -249,10 +292,19 @@ This option allows you to specify parser options to be used by ESLint. The avail ##### `--parser-options` example -```shell -echo '3 ** 4' | npx eslint --stdin --parser-options ecmaVersion:6 # fails with a parsing error -echo '3 ** 4' | npx eslint --stdin --parser-options ecmaVersion:7 # succeeds, yay! -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--stdin", "--parser-options", "ecmaVersion:6"], + comment: "fails with a parsing error", + previousCommands: ["echo \'3 ** 4\'"] +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--stdin", "--parser-options", "ecmaVersion:7"], + comment: "succeds, yay!", + previousCommands: ["echo \'3 ** 4\'"] +}) }} #### `--resolve-plugins-relative-to` @@ -271,10 +323,10 @@ For example: ##### `--resolve-plugins-relative-to` example -```shell -npx eslint --config ~/personal-eslintrc.js \ ---resolve-plugins-relative-to /usr/local/lib/ -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--config", "~/personal-eslintrc.js", "\\", "--resolve-plugins-relative-to", "/usr/local/lib/"] +}) }} ### Specify Rules and Plugins @@ -289,10 +341,15 @@ Before using the plugin, you have to install it using npm. ##### `--plugin` example -```shell -npx eslint --plugin jquery file.js -npx eslint --plugin eslint-plugin-mocha file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--plugin", "jquery", "file.js"] +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--plugin", "eslint-plugin-mocha", "file.js"] +}) }} #### `--rule` @@ -307,16 +364,29 @@ To ignore rules in `.eslintrc` configuration files and only run rules specified ##### `--rule` example -```shell -# Apply single rule -npx eslint --rule 'quotes: [error, double]' -# Apply multiple rules -npx eslint --rule 'guard-for-in: error' --rule 'brace-style: [error, 1tbs]' -# Apply rule from jquery plugin -npx eslint --rule 'jquery/dollar-sign: error' -# Only apply rule from the command line -npx eslint --rule 'quotes: [error, double]' --no-eslintrc -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--rule", "\'quotes: [error, double]\'"], + comment: "Apply single rule" +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--rule", "\'guard-for-in: error\'", "--rule", "\'brace-style: [error, 1tbs]\'"], + comment: "Apply multiple rules" +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--rule", "\'jquery/dollar-sign: error\'"], + comment: "Apply rule from jquery plugin" +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--rule", "\'quotes: [error, double]\'", "-no-eslintrc"], + comment: "Only apply rule from the command line" +}) }} #### `--rulesdir` @@ -331,10 +401,15 @@ Note that, as with core rules and plugin rules, you still need to enable the rul ##### `--rulesdir` example -```shell -npx eslint --rulesdir my-rules/ file.js -npx eslint --rulesdir my-rules/ --rulesdir my-other-rules/ file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--rulesdir", "my-rules/", "file.js"] +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--rulesdir", "my-rules/", "--rulesdir", "my-other-rules/", "file.js"] +}) }} ### Fix Problems @@ -353,9 +428,10 @@ If you want to fix code from `stdin` or otherwise want to get the fixes without ##### `--fix` example -```shell -npx eslint --fix file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--fix", "file.js"] +}) }} #### `--fix-dry-run` @@ -369,9 +445,11 @@ This flag can be useful for integrations (e.g. editor plugins) which need to aut ##### `--fix-dry-run` example -```shell -getSomeText | npx eslint --stdin --fix-dry-run --format json -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--stdin", "--fix-dry-run", "--format", "json"], + previousCommands: ["getSomeText"] +}) }} #### `--fix-type` @@ -388,11 +466,20 @@ This option is helpful if you are using another program to format your code, but ##### `--fix-type` example -```shell -npx eslint --fix --fix-type suggestion . -npx eslint --fix --fix-type suggestion --fix-type problem . -npx eslint --fix --fix-type suggestion,layout . -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--fix", "--fix-type", "suggestion", "."] +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--fix", "--fix-type", "suggestion", "--fix-type", "problem", "."] +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--fix", "--fix-type", "suggestion,layout", "."] +}) }} ### Ignore Files @@ -408,10 +495,15 @@ npx eslint --fix --fix-type suggestion,layout . ##### `--ignore-path` example -```shell -npx eslint --ignore-path tmp/.eslintignore file.js -npx eslint --ignore-path .gitignore file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--ignore-path", "tmp/.eslintignore", "file.js"] +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--ignore-path", ".gitignore", "file.js"] +}) }} #### `--no-ignore` @@ -421,9 +513,10 @@ Disables excluding of files from `.eslintignore` files, `--ignore-path` flags, ` ##### `--no-ignore` example -```shell -npx eslint --no-ignore file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--no-ignore", "file.js"] +}) }} #### `--ignore-pattern` @@ -434,9 +527,10 @@ This option allows you to specify patterns of files to ignore. In eslintrc mode, ##### `--ignore-pattern` example -```shell -npx eslint --ignore-pattern "/lib/" --ignore-pattern "/src/vendor/*" . -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--ignore-pattern", "\"/lib/\"", "--ignore-pattern", "\"/src/vendor/*\"", "."] +}) }} ### Use stdin @@ -448,9 +542,11 @@ This option tells ESLint to read and lint source code from STDIN instead of from ##### `--stdin` example -```shell -cat myfile.js | npx eslint --stdin -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--stdin"], + previousCommands: ["cat myFile.js"] +}) }} #### `--stdin-filename` @@ -463,9 +559,11 @@ This is useful when processing files from STDIN and you have rules which depend ##### `--stdin-filename` example -```shell -cat myfile.js | npx eslint --stdin --stdin-filename myfile.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--stdin", "--stdin-filename", "myfile.js"], + previousCommands: ["cat myFile.js"] +}) }} ### Handle Warnings @@ -477,9 +575,10 @@ This option allows you to disable reporting on warnings and running of rules set ##### `--quiet` example -```shell -npx eslint --quiet file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--quiet", "file.js"] +}) }} #### `--max-warnings` @@ -496,9 +595,10 @@ When used alongside `--quiet`, this will cause rules marked as warn to still be ##### `--max-warnings` example -```shell -npx eslint --max-warnings 10 file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--max-warnings", "10", "file.js"] +}) }} ### Output @@ -511,9 +611,10 @@ Write the output of linting results to a specified file. ##### `-o`, `--output-file` example -```shell -npx eslint -o ./test/test.html -``` +{{ npx_tabs ({ + package: "eslint", + args: ["-o", "./test/test.html"] +}) }} #### `-f`, `--format` @@ -529,35 +630,49 @@ An npm-installed formatter is resolved with or without `eslint-formatter-` prefi When specified, the given format is output to the console. If you'd like to save that output into a file, you can do so on the command line like so: -```shell -# Saves the output into the `results.json` file. -npx eslint -f json file.js > results.json -``` +{{ npx_tabs ({ + package: "eslint", + args: ["-f", "json", "file.js", ">", "results.json"], + comment: "Saves the output into the `results.json` file." +}) }} ##### `-f`, `--format` example Use the built-in `json` formatter: -```shell -npx eslint --format json file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--format", "json", "file.js"] +}) }} Use a local custom formatter: -```shell -npx eslint -f ./customformat.js file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["-f", "./customformat.js", "file.js"] +}) }} Use an npm-installed formatter: -```shell -npm install eslint-formatter-pretty +{{ npm_tabs({ + command: "install", + packages: ["eslint-formatter-pretty"], + args: [] +}) }} -# Then run one of the following commands -npx eslint -f pretty file.js -# or alternatively -npx eslint -f eslint-formatter-pretty file.js -``` +Then run one of the following commands + +{{ npx_tabs ({ + package: "eslint", + args: ["-f", "pretty", "file.js"] +}) }} + +or alternatively + +{{ npx_tabs ({ + package: "eslint", + args: ["-f", "eslint-formatter-pretty", "file.js"] +}) }} #### `--color` and `--no-color` @@ -569,10 +684,15 @@ You can use these options to override the default behavior, which is to enable c ##### `--color` and `--no-color` example -```shell -npx eslint --color file.js | cat -npx eslint --no-color file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--color", "file.js", "|", "cat"] +}) }} + +{{ npx_tabs ({ + package: "eslint", + args: ["--no-color", "file.js"] +}) }} ### Inline Configuration Comments @@ -595,9 +715,10 @@ This allows you to set an ESLint config without files modifying it. All inline c ##### `--no-inline-config` example -```shell -npx eslint --no-inline-config file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--no-inline-config", "file.js"] +}) }} #### `--report-unused-disable-directives` @@ -615,9 +736,10 @@ For example, suppose a rule has a bug that causes it to report a false positive, ##### `--report-unused-disable-directives` example -```shell -npx eslint --report-unused-disable-directives file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--report-unused-disable-directives", "file.js"] +}) }} #### `--report-unused-disable-directives-severity` @@ -632,9 +754,10 @@ Same as [`--report-unused-disable-directives`](#--report-unused-disable-directiv ##### `--report-unused-disable-directives-severity` example -```shell -npx eslint --report-unused-disable-directives-severity warn file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--report-unused-disable-directives-severity", "warn", "file.js"] +}) }} ### Caching @@ -651,9 +774,10 @@ Autofixed files are not placed in the cache. Subsequent linting that does not tr ##### `--cache` example -```shell -npx eslint --cache file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--cache", "file.js"] +}) }} #### `--cache-file` @@ -673,9 +797,10 @@ If the directory for the cache does not exist make sure you add a trailing `/` o ##### `--cache-location` example -```shell -npx eslint "src/**/*.js" --cache --cache-location "/Users/user/.eslintcache/" -``` +{{ npx_tabs ({ + package: "eslint", + args: ["\"src/**/*.js\"", "--cache", "--cache-location", "\"/Users/user/.eslintcache/\""] +}) }} #### `--cache-strategy` @@ -691,9 +816,10 @@ The `content` strategy can be useful in cases where the modification time of you ##### `--cache-strategy` example -```shell -npx eslint "src/**/*.js" --cache --cache-strategy content -``` +{{ npx_tabs ({ + package: "eslint", + args: ["\"src/**/*.js\"", "--cache", "--cache-strategy", "content"] +}) }} ### Miscellaneous @@ -707,9 +833,10 @@ The resulting configuration file is created in the current directory. ##### `--init` example -```shell -npx eslint --init -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--init"] +}) }} #### `--env-info` @@ -721,9 +848,10 @@ The ESLint team may ask for this information to help solve bugs. When you use th ##### `--env-info` example -```shell -npx eslint --env-info -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--env-info"] +}) }} #### `--no-error-on-unmatched-pattern` @@ -733,9 +861,10 @@ This option prevents errors when a quoted glob pattern or `--ext` is unmatched. ##### `--no-error-on-unmatched-pattern` example -```shell -npx eslint --no-error-on-unmatched-pattern --ext .ts "lib/*" -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--no-error-on-unmatched-pattern", "--ext", ".ts", "\"lib/*\""] +}) }} #### `--exit-on-fatal-error` @@ -745,9 +874,10 @@ This option causes ESLint to exit with exit code 2 if one or more fatal parsing ##### `--exit-on-fatal-error` example -```shell -npx eslint --exit-on-fatal-error file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--exit-on-fatal-error", "file.js"] +}) }} #### `--no-warn-ignored` @@ -757,9 +887,10 @@ npx eslint --exit-on-fatal-error file.js ##### `--no-warn-ignored` example -```shell -npx eslint --no-warn-ignored --max-warnings 0 ignored-file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--no-warn-ignored", "--max-warnings", "0", "ignored-file.js"] +}) }} #### `--pass-on-no-patterns` @@ -769,9 +900,10 @@ This option allows ESLint to exit with code 0 when no file or directory patterns ##### `--pass-on-no-patterns` example -```shell -npx eslint --pass-on-no-patterns -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--pass-on-no-patterns"] +}) }} #### `--debug` @@ -783,9 +915,10 @@ This information is useful when you're seeing a problem and having a hard time p ##### `--debug` example -```shell -npx eslint --debug test.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--debug", "test.js"] +}) }} #### `-h`, `--help` @@ -795,9 +928,10 @@ This option outputs the help menu, displaying all of the available options. All ##### `-h`, `--help` example -```shell -npx eslint --help -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--help"] +}) }} #### `-v`, `--version` @@ -807,9 +941,10 @@ This option outputs the current ESLint version onto the console. All other optio ##### `-v`, `--version` example -```shell -npx eslint --version -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--version"] +}) }} #### `--print-config` @@ -820,9 +955,10 @@ This option outputs the configuration to be used for the file passed. When prese ##### `--print-config` example -```shell -npx eslint --print-config file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--print-config", "file.js"] +}) }} #### `--stats` @@ -834,9 +970,10 @@ This option is intended for use with custom formatters that display statistics. ##### `--stats` example -```shell -npx eslint --stats --format json file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--stats", "--format", "json", "file.js"] +}) }} #### `--flag` @@ -847,9 +984,10 @@ This option enables one or more feature flags for ESLint. ##### `--flag` example -```shell -npx eslint --flag x_feature file.js -``` +{{ npx_tabs ({ + package: "eslint", + args: ["--flag", "x_feature", "file.js"] +}) }} ## Exit Codes diff --git a/docs/src/use/configure/configuration-files.md b/docs/src/use/configure/configuration-files.md index 7f71553c9b55..4c3d51d7a78e 100644 --- a/docs/src/use/configure/configuration-files.md +++ b/docs/src/use/configure/configuration-files.md @@ -8,6 +8,9 @@ eleventyNavigation: --- +{%- from 'components/npx_tabs.macro.html' import npx_tabs %} +{%- from 'components/npm_tabs.macro.html' import npm_tabs with context %} + ::: tip This page explains how to use flat config files. For the deprecated eslintrc format, [see the deprecated documentation](configuration-files-deprecated). ::: @@ -493,9 +496,10 @@ When ESLint is run on the command line, it first checks the current working dire You can prevent this search for `eslint.config.js` by using the `-c` or `--config` option on the command line to specify an alternate configuration file, such as: -```shell -npx eslint --config some-other-file.js **/*.js -``` +{{ npx_tabs({ + package: "eslint", + args: ["--config", "some-other-file.js", "**/*.js"] +}) }} In this case, ESLint does not search for `eslint.config.js` and instead uses `some-other-file.js`. @@ -517,15 +521,26 @@ For more information about using feature flags, see [Feature Flags](../../flags/ ## TypeScript Configuration Files +::: warning +This feature is currently experimental and may change in future versions. +::: + +You need to enable this feature through the `unstable_ts_config` feature flag: + +{{ npx_tabs({ + package: "eslint", + args: ["--flag", "unstable_ts_config"] +}) }} + +For more information about using feature flags, see [Feature Flags](../../flags/). + For Deno and Bun, TypeScript configuration files are natively supported; for Node.js, you must install the optional dev dependency [`jiti`](https://github.com/unjs/jiti) in version 2.0.0 or later in your project (this dependency is not automatically installed by ESLint): -```bash -npm install -D jiti -# or -yarn add --dev jiti -# or -pnpm add -D jiti -``` +{{ npm_tabs({ + command: "install", + packages: ["jiti"], + args: ["--save-dev"] +}) }} You can then create a configuration file with a `.ts`, `.mts`, or `.cts` extension, and export an array of [configuration objects](#configuration-objects). Here's an example in ESM format: @@ -578,6 +593,7 @@ If you have multiple ESLint configuration files, ESLint prioritizes JavaScript f To override this behavior, use the `--config` or `-c` command line option to specify a different configuration file: -```bash -npx eslint --config eslint.config.ts -``` +{{ npx_tabs({ + package: "eslint", + args: ["--config", "eslint.config.ts"] +}) }} diff --git a/docs/src/use/configure/debug.md b/docs/src/use/configure/debug.md index bb546e034d27..f9a8f2bd24e8 100644 --- a/docs/src/use/configure/debug.md +++ b/docs/src/use/configure/debug.md @@ -8,6 +8,8 @@ eleventyNavigation: --- +{%- from 'components/npx_tabs.macro.html' import npx_tabs %} + ESLint creates a configuration for each file that is linted based on your configuration file and command line options. The larger the configuration file, the more difficult it can be to determine why a file isn't linted as expected. To aid in debugging your configuration, ESLint provides several tools. ## Run the CLI in Debug Mode @@ -16,9 +18,10 @@ ESLint creates a configuration for each file that is linted based on your config **What To Do:** Run ESLint with the `--debug` command line flag and pass the file to check, like this: -```shell -npx eslint --debug file.js -``` +{{ npx_tabs({ + package: "eslint", + args: ["--debug", "file.js"] +}) }} This outputs all of ESLint's debugging information onto the console. You should copy this output to a file and then search for `eslint.config.js` to see which file is loaded. Here's some example output: @@ -35,9 +38,10 @@ eslint:eslint Config file URL is file:///C:/Users/nzakas/projects/eslint/eslint/ **What To Do:** Run ESLint with the `--print-config` command line flag and pass the file to check, like this: -```shell -npx eslint --print-config file.js -``` +{{ npx_tabs({ + package: "eslint", + args: ["--print-config", "file.js"] +}) }} This outputs a JSON representation of the file's calculated config, such as: @@ -70,9 +74,10 @@ You won't see any entries for `files`, `ignores`, or `name`, because those are o **What To Do:** Run ESLint with the `--inspect-config` command line flag and pass the file to check, like this: -```shell -npx eslint --inspect-config -``` +{{ npx_tabs({ + package: "eslint", + args: ["--inspect-config"] +}) }} This initiates the config inspector by installing and starting [`@eslint/config-inspector`](https://github.com/eslint/config-inspector). You can then type in the filename in question to see which configuration objects will apply. diff --git a/docs/src/use/configure/ignore.md b/docs/src/use/configure/ignore.md index e36bfead5bb3..76e925ad78bb 100644 --- a/docs/src/use/configure/ignore.md +++ b/docs/src/use/configure/ignore.md @@ -8,6 +8,8 @@ eleventyNavigation: --- +{%- from 'components/npx_tabs.macro.html' import npx_tabs %} + ::: tip This page explains how to ignore files using the flat config format. For the deprecated eslintrc format, [see the deprecated documentation](ignore-deprecated). ::: @@ -34,9 +36,10 @@ This configuration specifies that all of the files in the `.config` directory sh You can also ignore files on the command line using `--ignore-pattern`, such as: -```shell -npx eslint . --ignore-pattern ".config/*" -``` +{{ npx_tabs({ + package: "eslint", + args: [".", "--ignore-pattern", "\'.config/*\'"] +}) }} ## Ignoring Directories @@ -116,9 +119,10 @@ Note that only global `ignores` patterns can match directories. You can also unignore files on the command line using `--ignore-pattern`, such as: -```shell -npx eslint . --ignore-pattern "!node_modules/" -``` +{{ npx_tabs({ + package: "eslint", + args: [".", "--ignore-pattern", "\'!node_modules/\'"] +}) }} ## Glob Pattern Resolution @@ -143,9 +147,10 @@ export default [ And then you run: -```shell -npx eslint foo.js -``` +{{ npx_tabs({ + package: "eslint", + args: ["foo.js"] +}) }} You'll see this warning: diff --git a/docs/src/use/configure/migration-guide.md b/docs/src/use/configure/migration-guide.md index ac307daf5f8a..0b83266ddd7c 100644 --- a/docs/src/use/configure/migration-guide.md +++ b/docs/src/use/configure/migration-guide.md @@ -7,6 +7,9 @@ eleventyNavigation: order: 9 --- +{%- from 'components/npm_tabs.macro.html' import npm_tabs with context %} +{%- from 'components/npx_tabs.macro.html' import npx_tabs %} + This guide provides an overview of how you can migrate your ESLint configuration file from the eslintrc format (typically configured in `.eslintrc.js` or `.eslintrc.json` files) to the new flat config format (typically configured in an `eslint.config.js` file). To learn more about the flat config format, refer to [this blog post](https://eslint.org/blog/2022/08/new-config-system-part-2/). @@ -20,9 +23,10 @@ For reference information on these configuration formats, refer to the following To get started, use the [configuration migrator](https://npmjs.com/package/@eslint/migrate-config) on your existing configuration file (`.eslintrc`, `.eslintrc.json`, `.eslintrc.yml`), like this: -```shell -npx @eslint/migrate-config .eslintrc.json -``` +{{ npx_tabs({ + package: null, + args: ["@eslint/migrate-config", ".eslintrc.json"] +}) }} This will create a starting point for your `eslint.config.js` file but is not guaranteed to work immediately without further modification. It will, however, do most of the conversion work mentioned in this guide automatically. @@ -424,9 +428,11 @@ You can also use the `extends` property to extend a shareable config. Shareable In flat config files, predefined configs are imported from separate modules into flat config files. The `recommended` and `all` rules configs are located in the [`@eslint/js`](https://www.npmjs.com/package/@eslint/js) package. You must import this package to use these configs: -```shell -npm install @eslint/js --save-dev -``` +{{ npm_tabs({ + command: "install", + packages: ["@eslint/js"], + args: ["--save-dev"] +}) }} You can add each of these configs to the exported array or expose specific rules from them. You must import the modules for local config files and npm package configs with flat config. @@ -503,9 +509,11 @@ export default [ You may find that there's a shareable config you rely on that hasn't yet been updated to flat config format. In that case, you can use the `FlatCompat` utility to translate the eslintrc format into flat config format. First, install the `@eslint/eslintrc` package: -```shell -npm install @eslint/eslintrc --save-dev -``` +{{ npm_tabs({ + command: "install", + packages: ["@eslint/eslintrc"], + args: ["--save-dev"] +}) }} Then, import `FlatCompat` and create a new instance to convert an existing eslintrc config. For example, if the npm package `eslint-config-my-config` is in eslintrc format, you can write this: diff --git a/docs/src/use/formatters/index.md b/docs/src/use/formatters/index.md index de1397aa475e..069106849656 100644 --- a/docs/src/use/formatters/index.md +++ b/docs/src/use/formatters/index.md @@ -8,6 +8,8 @@ eleventyNavigation: edit_link: https://github.com/eslint/eslint/edit/main/templates/formatter-examples.md.ejs --- +{%- from 'components/npx_tabs.macro.html' import npx_tabs %} + ESLint comes with several built-in formatters to control the appearance of the linting results, and supports third-party formatters as well. You can specify a formatter using the `--format` or `-f` flag in the CLI. For example, `--format json` uses the `json` formatter. @@ -52,9 +54,10 @@ function addOne(i) { Tests the formatters with the CLI: -```shell -npx eslint --format fullOfProblems.js -``` +{{ npx_tabs({ + package: "eslint", + args: ["--format", "", "fullOfProblems.js"] +}) }} ## Built-In Formatter Options diff --git a/docs/src/use/getting-started.md b/docs/src/use/getting-started.md index 5341a813d479..3a96bba6ea99 100644 --- a/docs/src/use/getting-started.md +++ b/docs/src/use/getting-started.md @@ -8,6 +8,9 @@ eleventyNavigation: --- +{%- from 'components/npm_tabs.macro.html' import npm_tabs with context %} +{%- from 'components/npx_tabs.macro.html' import npx_tabs %} + ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs. ESLint is completely pluggable. Every single rule is a plugin and you can add more at runtime. You can also add community plugins, configurations, and parsers to extend the functionality of ESLint. @@ -20,39 +23,29 @@ To use ESLint, you must have [Node.js](https://nodejs.org/en/) (`^18.18.0`, `^20 You can install and configure ESLint using this command: -```shell -npm init @eslint/config@latest - -# or - -yarn create @eslint/config - -# or - -pnpm create @eslint/config@latest -``` +{{ npm_tabs({ + command: "init-create", + packages: ["@eslint/config@latest"], + args: [] +}) }} If you want to use a specific shareable config that is hosted on npm, you can use the `--config` option and specify the package name: -```shell -# use `eslint-config-standard` shared config - -# npm 7+ -npm init @eslint/config@latest -- --config eslint-config-standard - -``` +{{ npm_tabs({ + command: "init-create", + packages: ["@eslint/config@latest", "--", "--config", "eslint-config-standard"], + args: [], + comment: "use `eslint-config-standard` shared config - npm 7+" +}) }} **Note:** `npm init @eslint/config` assumes you have a `package.json` file already. If you don't, make sure to run `npm init` or `yarn init` beforehand. After that, you can run ESLint on any file or directory like this: -```shell -npx eslint yourfile.js - -# or - -yarn run eslint yourfile.js -``` +{{ npx_tabs({ + package: "eslint", + args: ["yourfile.js"] +}) }} ## Configuration @@ -112,9 +105,11 @@ Before you begin, you must already have a `package.json` file. If you don't, mak 1. Install the ESLint packages in your project: - ```shell - npm install --save-dev eslint @eslint/js - ``` +{{ npm_tabs({ + command: "install", + packages: ["eslint", "@eslint/js"], + args: ["--save-dev"] +}) }} 1. Add an `eslint.config.js` file: @@ -142,9 +137,10 @@ Before you begin, you must already have a `package.json` file. If you don't, mak 1. Lint code using the ESLint CLI: - ```shell - npx eslint project-dir/ file1.js - ``` +{{ npx_tabs({ + package: "eslint", + args: ["project-dir/", "file.js"] +}) }} For more information on the available CLI options, refer to [Command Line Interface](./command-line-interface). diff --git a/docs/src/use/migrating-from-jscs.md b/docs/src/use/migrating-from-jscs.md index 54b19683fedd..f119ddd00427 100644 --- a/docs/src/use/migrating-from-jscs.md +++ b/docs/src/use/migrating-from-jscs.md @@ -3,6 +3,8 @@ title: Migrating from JSCS --- +{%- from 'components/npm_tabs.macro.html' import npm_tabs with context %} + In April 2016, we [announced](https://eslint.org/blog/2016/04/welcoming-jscs-to-eslint) that the JSCS project was shutting down and the JSCS team would be joining the ESLint team. This guide is intended to help those who are using JSCS to migrate their settings and projects to use ESLint. We've tried to automate as much of the conversion as possible, but there are some manual changes that are needed. ## Terminology @@ -18,9 +20,11 @@ Before beginning the process of migrating to ESLint, it's helpful to understand To install Polyjuice: -```shell -npm install -g polyjuice -``` +{{ npm_tabs({ + command: "install", + packages: ["polyjuice"], + args: ["--global"] +}) }} Polyjuice works with JSON configuration files, so if you're using a JavaScript or YAML JSCS configuration file, you should first convert it into a JSON configuration file. @@ -44,9 +48,11 @@ polyjuice --jscs .jscsrc.json ./foo/.jscsrc.json > .eslintrc.json If you don't want to convert your JSCS configuration directly into an ESLint configuration, then you can use ESLint's built-in wizard to get you started. Just run: -```shell -npm init @eslint/config -``` +{{ npm_tabs({ + command: "init-create", + packages: ["@eslint/config@latest"], + args: [] +}) }} You'll be guided through a series of questions that will help you setup a basic configuration file to get you started. @@ -77,9 +83,11 @@ As an example, suppose that you are using the `airbnb` preset, so your `.jscsrc` In order to get the same functionality in ESLint, you would first need to install the `eslint-config-airbnb` shareable config package: -```shell -npm install eslint-config-airbnb-base --save-dev -``` +{{ npm_tabs({ + command: "install", + packages: ["eslint-config-airbnb-base"], + args: ["--save-dev"] +}) }} And then you would modify your configuration file like this: From d9c23c55be52a431141f38561c14140ee8b15686 Mon Sep 17 00:00:00 2001 From: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:53:31 +0530 Subject: [PATCH 46/51] docs: replace `var` with `const` in rule examples (#19325) --- docs/src/rules/no-prototype-builtins.md | 12 ++++++------ docs/src/rules/no-setter-return.md | 4 ++-- docs/src/rules/no-sparse-arrays.md | 14 +++++++------- docs/src/rules/no-undef.md | 8 ++++---- docs/src/rules/no-unexpected-multiline.md | 22 +++++++++++----------- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/docs/src/rules/no-prototype-builtins.md b/docs/src/rules/no-prototype-builtins.md index e3da23e9cdc6..81b01999af0d 100644 --- a/docs/src/rules/no-prototype-builtins.md +++ b/docs/src/rules/no-prototype-builtins.md @@ -22,11 +22,11 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-prototype-builtins: "error"*/ -var hasBarProperty = foo.hasOwnProperty("bar"); +const hasBarProperty = foo.hasOwnProperty("bar"); -var isPrototypeOfBar = foo.isPrototypeOf(bar); +const isPrototypeOfBar = foo.isPrototypeOf(bar); -var barIsEnumerable = foo.propertyIsEnumerable("bar"); +const barIsEnumerable = foo.propertyIsEnumerable("bar"); ``` ::: @@ -38,11 +38,11 @@ Examples of **correct** code for this rule: ```js /*eslint no-prototype-builtins: "error"*/ -var hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar"); +const hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar"); -var isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar); +const isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar); -var barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar"); +const barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar"); ``` ::: diff --git a/docs/src/rules/no-setter-return.md b/docs/src/rules/no-setter-return.md index 50353c754dab..bc0ae00b56e9 100644 --- a/docs/src/rules/no-setter-return.md +++ b/docs/src/rules/no-setter-return.md @@ -33,7 +33,7 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-setter-return: "error"*/ -var foo = { +const foo = { set a(value) { this.val = value; return value; @@ -76,7 +76,7 @@ Examples of **correct** code for this rule: ```js /*eslint no-setter-return: "error"*/ -var foo = { +const foo = { set a(value) { this.val = value; } diff --git a/docs/src/rules/no-sparse-arrays.md b/docs/src/rules/no-sparse-arrays.md index ec41bb23df45..ddb619a0eeb6 100644 --- a/docs/src/rules/no-sparse-arrays.md +++ b/docs/src/rules/no-sparse-arrays.md @@ -10,13 +10,13 @@ further_reading: Sparse arrays contain empty slots, most frequently due to multiple commas being used in an array literal, such as: ```js -var items = [,,]; +const items = [,,]; ``` While the `items` array in this example has a `length` of 2, there are actually no values in `items[0]` or `items[1]`. The fact that the array literal is valid with only commas inside, coupled with the `length` being set and actual item values not being set, make sparse arrays confusing for many developers. Consider the following: ```js -var colors = [ "red",, "blue" ]; +const colors = [ "red",, "blue" ]; ``` In this example, the `colors` array has a `length` of 3. But did the developer intend for there to be an empty spot in the middle of the array? Or is it a typo? @@ -34,8 +34,8 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-sparse-arrays: "error"*/ -var items = [,]; -var colors = [ "red",, "blue" ]; +const items = [,]; +const colors = [ "red",, "blue" ]; ``` ::: @@ -47,11 +47,11 @@ Examples of **correct** code for this rule: ```js /*eslint no-sparse-arrays: "error"*/ -var items = []; -var items = new Array(23); +const items = []; +const arr = new Array(23); // trailing comma (after the last element) is not a problem -var colors = [ "red", "blue", ]; +const colors = [ "red", "blue", ]; ``` ::: diff --git a/docs/src/rules/no-undef.md b/docs/src/rules/no-undef.md index c27532c405e4..d9af2902e21a 100644 --- a/docs/src/rules/no-undef.md +++ b/docs/src/rules/no-undef.md @@ -22,8 +22,8 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-undef: "error"*/ -var foo = someFunction(); -var bar = a + 1; +const foo = someFunction(); +const bar = a + 1; ``` ::: @@ -36,8 +36,8 @@ Examples of **correct** code for this rule with `global` declaration: /*global someFunction, a*/ /*eslint no-undef: "error"*/ -var foo = someFunction(); -var bar = a + 1; +const foo = someFunction(); +const bar = a + 1; ``` ::: diff --git a/docs/src/rules/no-unexpected-multiline.md b/docs/src/rules/no-unexpected-multiline.md index b8f3582fb39d..d134fe7f344f 100644 --- a/docs/src/rules/no-unexpected-multiline.md +++ b/docs/src/rules/no-unexpected-multiline.md @@ -31,20 +31,20 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-unexpected-multiline: "error"*/ -var foo = bar +const foo = bar (1 || 2).baz(); -var hello = 'world' +const hello = 'world' [1, 2, 3].forEach(addNumber); -let x = function() {} +const x = function() {} `hello` -let y = function() {} +const y = function() {} y `hello` -let z = foo +const z = foo /regex/g.test(bar) ``` @@ -57,22 +57,22 @@ Examples of **correct** code for this rule: ```js /*eslint no-unexpected-multiline: "error"*/ -var foo = bar; +const foo = bar; (1 || 2).baz(); -var foo = bar +const baz = bar ;(1 || 2).baz() -var hello = 'world'; +const hello = 'world'; [1, 2, 3].forEach(addNumber); -var hello = 'world' +const hi = 'world' void [1, 2, 3].forEach(addNumber); -let x = function() {}; +const x = function() {}; `hello` -let tag = function() {} +const tag = function() {} tag `hello` ``` From 94861418f1573e4e1cbdd0174413d19054553294 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Fri, 10 Jan 2025 22:08:41 +0100 Subject: [PATCH 47/51] deps: upgrade `@eslint/core` and `@eslint/plugin-kit` (#19329) --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bfc38a42c667..95d50c983856 100644 --- a/package.json +++ b/package.json @@ -100,10 +100,10 @@ "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", "@eslint/config-array": "^0.19.0", - "@eslint/core": "^0.9.0", + "@eslint/core": "^0.10.0", "@eslint/eslintrc": "^3.2.0", "@eslint/js": "9.17.0", - "@eslint/plugin-kit": "^0.2.3", + "@eslint/plugin-kit": "^0.2.5", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.1", From 362099c580992b2602316fc417ce3e595b96f28c Mon Sep 17 00:00:00 2001 From: Jenkins Date: Fri, 10 Jan 2025 21:14:49 +0000 Subject: [PATCH 48/51] chore: package.json update for @eslint/js release --- packages/js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/package.json b/packages/js/package.json index d1175fff13a5..185c2eee11f5 100644 --- a/packages/js/package.json +++ b/packages/js/package.json @@ -1,6 +1,6 @@ { "name": "@eslint/js", - "version": "9.17.0", + "version": "9.18.0", "description": "ESLint JavaScript language implementation", "main": "./src/index.js", "types": "./types/index.d.ts", From c52be85c4a916f70807377e1a486adb3a5857347 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Fri, 10 Jan 2025 22:32:24 +0100 Subject: [PATCH 49/51] chore: upgrade to `@eslint/js@9.18.0` (#19330) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 95d50c983856..58b0d8e24c04 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "@eslint/config-array": "^0.19.0", "@eslint/core": "^0.10.0", "@eslint/eslintrc": "^3.2.0", - "@eslint/js": "9.17.0", + "@eslint/js": "9.18.0", "@eslint/plugin-kit": "^0.2.5", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", From 4df3132ae241313b57170edb4fb1354abae840ce Mon Sep 17 00:00:00 2001 From: Jenkins Date: Fri, 10 Jan 2025 21:45:09 +0000 Subject: [PATCH 50/51] Build: changelog update for 9.18.0 --- CHANGELOG.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 277afeceeb1a..d33b786458b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,55 @@ +v9.18.0 - January 10, 2025 + +* [`c52be85`](https://github.com/eslint/eslint/commit/c52be85c4a916f70807377e1a486adb3a5857347) chore: upgrade to `@eslint/js@9.18.0` (#19330) (Francesco Trotta) +* [`362099c`](https://github.com/eslint/eslint/commit/362099c580992b2602316fc417ce3e595b96f28c) chore: package.json update for @eslint/js release (Jenkins) +* [`9486141`](https://github.com/eslint/eslint/commit/94861418f1573e4e1cbdd0174413d19054553294) deps: upgrade `@eslint/core` and `@eslint/plugin-kit` (#19329) (Francesco Trotta) +* [`d9c23c5`](https://github.com/eslint/eslint/commit/d9c23c55be52a431141f38561c14140ee8b15686) docs: replace `var` with `const` in rule examples (#19325) (Tanuj Kanti) +* [`8e1a898`](https://github.com/eslint/eslint/commit/8e1a898411fd16c73332d7a2dd28aff9bac8da01) docs: add tabs to cli code blocks (#18784) (Jay) +* [`f3aeefb`](https://github.com/eslint/eslint/commit/f3aeefbd6547c25d78819ab7e77cf36a2c26611c) docs: rewrite using let and const in rule examples (#19320) (PoloSpark) +* [`0b680b3`](https://github.com/eslint/eslint/commit/0b680b3cc19c1e8d79ab94e7160051177c4adfe7) docs: Update README (GitHub Actions Bot) +* [`98c86a9`](https://github.com/eslint/eslint/commit/98c86a99f7657a2f15ea30a251523446b10a7cad) docs: `Edit this page` button link to different branches (#19228) (Tanuj Kanti) +* [`6947901`](https://github.com/eslint/eslint/commit/6947901d14b18dbb2db259c9769bd8ac4cd04c3c) docs: remove hardcoded edit link (#19323) (Milos Djermanovic) +* [`03f2f44`](https://github.com/eslint/eslint/commit/03f2f442a9a8bec15e89786980c07be5980cdac5) docs: rewrite var with const in rules examples (#19317) (Thiago) +* [`26c3003`](https://github.com/eslint/eslint/commit/26c3003bfca2f7d98950446fdf5b3978d17a3a60) docs: Clarify dangers of eslint:all (#19318) (Nicholas C. Zakas) +* [`c038257`](https://github.com/eslint/eslint/commit/c03825730d277405c357388d62ed48b3973083ba) docs: add `eqeqeq` in related rules to `no-eq-null` (#19310) (루밀LuMir) +* [`89c8fc5`](https://github.com/eslint/eslint/commit/89c8fc54c977ac457d3b5525a87cec1c51e72e23) docs: rewrite examples with var using let and const (#19315) (Amaresh S M) +* [`495aa49`](https://github.com/eslint/eslint/commit/495aa499a7390f99b763cba8f2b8312e3eecfe0d) chore: extract package `name` from `package.json` for public interface (#19314) (루밀LuMir) +* [`db574c4`](https://github.com/eslint/eslint/commit/db574c4d380e2d25b6111a06bd15caa83f75bb2d) docs: add missing backticks to `no-void` (#19313) (루밀LuMir) +* [`8d943c3`](https://github.com/eslint/eslint/commit/8d943c335c528a6a6a631dcbd98506238240ecfb) docs: add missing backticks to `default-case-last` (#19311) (루밀LuMir) +* [`36ef8bb`](https://github.com/eslint/eslint/commit/36ef8bbeab495ef2598a4b1f52e32b4cb50be5e2) docs: rewrite examples with var using let and const (#19298) (Amaresh S M) +* [`1610c9e`](https://github.com/eslint/eslint/commit/1610c9ee1479f23b1bc5a6853d0b42b83dacdb7f) docs: add missing backticks to `no-else-return` (#19309) (루밀LuMir) +* [`df409d8`](https://github.com/eslint/eslint/commit/df409d8f76555c7baa4353d678d5fc460454a4d7) docs: Update README (GitHub Actions Bot) +* [`e84e6e2`](https://github.com/eslint/eslint/commit/e84e6e269c4aefc84952e17a1f967697b02b7ad2) feat: Report allowed methods for `no-console` rule (#19306) (Anna Bocharova) +* [`2e84213`](https://github.com/eslint/eslint/commit/2e842138e689ee5623552e885c3a5ac1b0c2bfcf) docs: Fix Horizontal Scroll Overflow in Rule Description on Mobile View (#19304) (Amaresh S M) +* [`6e7361b`](https://github.com/eslint/eslint/commit/6e7361bb6ae93c87fccdf2219379c7793517f17a) docs: replace `var` with `let` and `const` in rule example (#19302) (Tanuj Kanti) +* [`069af5e`](https://github.com/eslint/eslint/commit/069af5e9ac43c7f33bd2a30abce3d5d94f504465) docs: rewrite `var` using `const` in rule examples (#19303) (Kim GyeonWon) +* [`064e35d`](https://github.com/eslint/eslint/commit/064e35de95339cfedcad467c3c9871d5ff70c1a7) docs: remove 'I hope to' comments from scope-manager-interface (#19300) (Josh Goldberg ✨) +* [`8e00305`](https://github.com/eslint/eslint/commit/8e003056a805468b07bcf4edba83a90a932fb520) docs: replace `var` with `const` in rule examples (#19299) (Tanuj Kanti) +* [`a559009`](https://github.com/eslint/eslint/commit/a559009f51ad9f081bae5252bb2b7a6e23c54767) docs: Add warning about extending core rules (#19295) (Nicholas C. Zakas) +* [`0bfdf6c`](https://github.com/eslint/eslint/commit/0bfdf6caaf3e1553c67a77da900245879c730ad3) docs: Update README (GitHub Actions Bot) +* [`ce0b9ff`](https://github.com/eslint/eslint/commit/ce0b9ff04242f61c8c49fc1ce164eb45eb3c459a) docs: add navigation link for `code explorer` (#19285) (Tanuj Kanti) +* [`e255cc9`](https://github.com/eslint/eslint/commit/e255cc98abef202929112378bfe133f260f2ac9d) docs: add bluesky icon to footer (#19290) (Tanuj Kanti) +* [`5d64851`](https://github.com/eslint/eslint/commit/5d64851955f410f31c159a7097f6cc7d4a01d6a1) docs: remove outdated info about environments (#19296) (Francesco Trotta) +* [`eec01f0`](https://github.com/eslint/eslint/commit/eec01f04ae1c44f7c9a8c6afec59dd72f5a57600) docs: switch rule examples config format to `languageOptions` (#19277) (Milos Djermanovic) +* [`b36ca0a`](https://github.com/eslint/eslint/commit/b36ca0a490829c579358ec7193bde35275000e04) docs: Fixing Focus Order by Rearranging Element Sequence (#19241) (Amaresh S M) +* [`d122c8a`](https://github.com/eslint/eslint/commit/d122c8a756bb8e232ef7c25cca6dcae645094835) docs: add missing backticks to `sort-imports` (#19282) (루밀LuMir) +* [`0367a70`](https://github.com/eslint/eslint/commit/0367a70a43346f1b9df8be75d38f98f9cfe4007c) docs: update custom parser docs (#19288) (Francesco Trotta) +* [`da768d4`](https://github.com/eslint/eslint/commit/da768d4541c4c30bfc33640a07a8d8a485520b18) fix: correct `overrideConfigFile` type (#19289) (Francesco Trotta) +* [`8c07ebb`](https://github.com/eslint/eslint/commit/8c07ebb9004309f8691f972d554e8bbb3eb517bc) docs: add `border-radius` to `hX:target` selector styles (#19270) (루밀LuMir) +* [`eff7c57`](https://github.com/eslint/eslint/commit/eff7c5721c101975a03e7906905f1fe2c9538df0) docs: add limitation section in `no-loop-func` (#19287) (Tanuj Kanti) +* [`8efc2d0`](https://github.com/eslint/eslint/commit/8efc2d0c92dab6099f34c1479cd80bdc5cd1b07b) feat: unflag TypeScript config files (#19266) (Francesco Trotta) +* [`87a9352`](https://github.com/eslint/eslint/commit/87a9352c621e7cd1d5bb77b3c08df7837363ea12) feat: check imports and class names in `no-shadow-restricted-names` (#19272) (Milos Djermanovic) +* [`5db226f`](https://github.com/eslint/eslint/commit/5db226f4da9ad7d53a4505a90290b68d4036c082) docs: add missing backticks in various parts of the documentation (#19269) (루밀LuMir) +* [`789edbb`](https://github.com/eslint/eslint/commit/789edbbae5aeeefc8fee94cd653b0b5f3e2ae3eb) docs: Update README (GitHub Actions Bot) +* [`613c06a`](https://github.com/eslint/eslint/commit/613c06a2c341758739473409a2331074884ec7f8) docs: mark rules that are frozen with ❄️ (#19231) (Amaresh S M) +* [`43172ec`](https://github.com/eslint/eslint/commit/43172ecbd449c13a503cb39539e31106179f5d80) docs: Update README (GitHub Actions Bot) +* [`ac8b3c4`](https://github.com/eslint/eslint/commit/ac8b3c4ca9f7b84f84356137cf23a1ba6dfecf11) docs: fix description of `overrideConfigFile` option (#19262) (Milos Djermanovic) +* [`6fe0e72`](https://github.com/eslint/eslint/commit/6fe0e7244a7e88458ea7fdcebc43794c03793c4b) chore: update dependency @eslint/json to ^0.9.0 (#19263) (renovate[bot]) +* [`bbb9b46`](https://github.com/eslint/eslint/commit/bbb9b46c20662019e98df85dedde9b68719afa1f) docs: Update README (GitHub Actions Bot) +* [`995b492`](https://github.com/eslint/eslint/commit/995b49231a3f0ccddb941663175ce4fead9c9432) docs: fix inconsistent divider in rule categories box (#19249) (Tanuj Kanti) +* [`f76d05d`](https://github.com/eslint/eslint/commit/f76d05da6e745adbea574c32b334638c7ba3c0c8) docs: Refactor search result handling with better event listener cleanup (#19252) (Amaresh S M) +* [`c5f3d7d`](https://github.com/eslint/eslint/commit/c5f3d7dab303468ae33ccfec61bba75a816f832c) docs: Update README (GitHub Actions Bot) + v9.17.0 - December 13, 2024 * [`cc243c9`](https://github.com/eslint/eslint/commit/cc243c948226a585f01d3e68b4cedbabcc5e0e40) chore: upgrade to `@eslint/js@9.17.0` (#19242) (Francesco Trotta) From 1c87b415313b4aacda496b3b26efc4e0b93dc13a Mon Sep 17 00:00:00 2001 From: Jenkins Date: Fri, 10 Jan 2025 21:45:10 +0000 Subject: [PATCH 51/51] 9.18.0 --- docs/package.json | 2 +- docs/src/_data/rules.json | 4 ++-- docs/src/_data/versions.json | 2 +- docs/src/use/formatters/html-formatter-example.html | 2 +- docs/src/use/formatters/index.md | 10 ++++------ package.json | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/package.json b/docs/package.json index be7de1d886f6..8a21941a1b4a 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,7 +1,7 @@ { "name": "docs-eslint", "private": true, - "version": "9.17.0", + "version": "9.18.0", "description": "", "main": "index.js", "keywords": [], diff --git a/docs/src/_data/rules.json b/docs/src/_data/rules.json index 81bd9165d7b0..1df5963ea8c7 100644 --- a/docs/src/_data/rules.json +++ b/docs/src/_data/rules.json @@ -557,7 +557,7 @@ }, { "name": "default-case-last", - "description": "Enforce `default` clauses in switch statements to be last", + "description": "Enforce `default` clauses in `switch` statements to be last", "recommended": false, "fixable": false, "frozen": false, @@ -1517,7 +1517,7 @@ }, { "name": "sort-imports", - "description": "Enforce sorted import declarations within modules", + "description": "Enforce sorted `import` declarations within modules", "recommended": false, "fixable": true, "frozen": true, diff --git a/docs/src/_data/versions.json b/docs/src/_data/versions.json index 0526b1543549..6a4f23e85324 100644 --- a/docs/src/_data/versions.json +++ b/docs/src/_data/versions.json @@ -6,7 +6,7 @@ "path": "/docs/head/" }, { - "version": "9.17.0", + "version": "9.18.0", "branch": "latest", "path": "/docs/latest/" }, diff --git a/docs/src/use/formatters/html-formatter-example.html b/docs/src/use/formatters/html-formatter-example.html index 88ef5d06a123..8c30f29b19de 100644 --- a/docs/src/use/formatters/html-formatter-example.html +++ b/docs/src/use/formatters/html-formatter-example.html @@ -118,7 +118,7 @@

ESLint Report

- 8 problems (4 errors, 4 warnings) - Generated on Fri Dec 13 2024 21:28:30 GMT+0000 (Coordinated Universal Time) + 8 problems (4 errors, 4 warnings) - Generated on Fri Jan 10 2025 21:45:11 GMT+0000 (Coordinated Universal Time)
diff --git a/docs/src/use/formatters/index.md b/docs/src/use/formatters/index.md index 069106849656..ba7496c13ed5 100644 --- a/docs/src/use/formatters/index.md +++ b/docs/src/use/formatters/index.md @@ -8,8 +8,6 @@ eleventyNavigation: edit_link: https://github.com/eslint/eslint/edit/main/templates/formatter-examples.md.ejs --- -{%- from 'components/npx_tabs.macro.html' import npx_tabs %} - ESLint comes with several built-in formatters to control the appearance of the linting results, and supports third-party formatters as well. You can specify a formatter using the `--format` or `-f` flag in the CLI. For example, `--format json` uses the `json` formatter. @@ -54,10 +52,9 @@ function addOne(i) { Tests the formatters with the CLI: -{{ npx_tabs({ - package: "eslint", - args: ["--format", "", "fullOfProblems.js"] -}) }} +```shell +npx eslint --format fullOfProblems.js +``` ## Built-In Formatter Options @@ -268,6 +265,7 @@ Example output (formatted for easier reading): "docs": { "description": "Disallow `else` blocks after `return` statements in `if` statements", "recommended": false, + "frozen": true, "url": "https://eslint.org/docs/latest/rules/no-else-return" }, "schema": [ diff --git a/package.json b/package.json index 58b0d8e24c04..a8b176f6daee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint", - "version": "9.17.0", + "version": "9.18.0", "author": "Nicholas C. Zakas ", "description": "An AST-based pattern checker for JavaScript.", "type": "commonjs", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy