From c8c0c715a2964cc1859b99f9d4f542675094d1d5 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Thu, 23 Feb 2023 13:17:14 -0700 Subject: [PATCH] feat: Move all and recommended configs into package. (#16844) * feat: Move all and recommended configs into package. Relocates the "eslint:all" and "eslint:recommended" configs into the @eslint/js package so they can be referenced from there instead of as strings. Fixes #16537 * Update tools/update-eslint-all.js Co-authored-by: Milos Djermanovic * Update package.json Co-authored-by: Milos Djermanovic * Update tools/update-eslint-all.js Co-authored-by: Milos Djermanovic * Update packages/js/package.json Co-authored-by: Mark Friedrich * Update package.json Co-authored-by: Milos Djermanovic * Update packages/js/README.md Co-authored-by: Milos Djermanovic * Update packages/js/LICENSE Co-authored-by: Milos Djermanovic * Update packages/js/package.json Co-authored-by: Milos Djermanovic * Update packages/js/README.md Co-authored-by: Milos Djermanovic * Update packages/js/README.md Co-authored-by: Milos Djermanovic * Update packages/js/README.md Co-authored-by: Milos Djermanovic * Update docs/src/use/configure/configuration-files-new.md Co-authored-by: Milos Djermanovic * Incorporate feedback --------- Co-authored-by: Milos Djermanovic Co-authored-by: Mark Friedrich --- Makefile.js | 6 +- .../use/configure/configuration-files-new.md | 27 +- lib/cli-engine/cli-engine.js | 4 +- lib/cli-engine/file-enumerator.js | 4 +- lib/config/flat-config-array.js | 22 +- package.json | 5 + packages/js/LICENSE | 19 ++ packages/js/README.md | 57 ++++ packages/js/package.json | 32 ++ packages/js/src/configs/eslint-all.js | 279 ++++++++++++++++++ .../js/src/configs}/eslint-recommended.js | 8 +- packages/js/src/index.js | 17 ++ tests/conf/eslint-all.js | 2 +- tests/conf/eslint-recommended.js | 2 +- tests/lib/cli.js | 2 +- tests/lib/config/flat-config-array.js | 6 +- .../update-eslint-all.js | 29 +- 17 files changed, 482 insertions(+), 39 deletions(-) create mode 100644 packages/js/LICENSE create mode 100644 packages/js/README.md create mode 100644 packages/js/package.json create mode 100644 packages/js/src/configs/eslint-all.js rename {conf => packages/js/src/configs}/eslint-recommended.js (97%) create mode 100644 packages/js/src/index.js rename conf/eslint-all.js => tools/update-eslint-all.js (54%) diff --git a/Makefile.js b/Makefile.js index 93fd0476b88..717cc785946 100644 --- a/Makefile.js +++ b/Makefile.js @@ -835,16 +835,16 @@ target.checkRuleFiles = function() { } // check eslint:recommended - const recommended = require("./conf/eslint-recommended"); + const recommended = require("./packages/js").configs.recommended; if (ruleDef.meta.docs.recommended) { if (recommended.rules[basename] !== "error") { - console.error(`Missing rule from eslint:recommended (./conf/eslint-recommended.js): ${basename}. If you just made a rule recommended then add an entry for it in this file.`); + console.error(`Missing rule from eslint:recommended (./packages/js/src/configs/eslint-recommended.js): ${basename}. If you just made a rule recommended then add an entry for it in this file.`); errors++; } } else { if (basename in recommended.rules) { - console.error(`Extra rule in eslint:recommended (./conf/eslint-recommended.js): ${basename}. If you just added a rule then don't add an entry for it in this file.`); + console.error(`Extra rule in eslint:recommended (./packages/js/src/configs/eslint-recommended.js): ${basename}. If you just added a rule then don't add an entry for it in this file.`); errors++; } } diff --git a/docs/src/use/configure/configuration-files-new.md b/docs/src/use/configure/configuration-files-new.md index e9bc207566f..02318bceb76 100644 --- a/docs/src/use/configure/configuration-files-new.md +++ b/docs/src/use/configure/configuration-files-new.md @@ -562,16 +562,18 @@ export default [ ### Using predefined configurations -ESLint has two predefined configurations: +ESLint has two predefined configurations for JavaScript: -* `eslint:recommended` - enables the rules that ESLint recommends everyone use to avoid potential errors -* `eslint:all` - enables all of the rules shipped with ESLint +* `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 -To include these predefined configurations, you can insert the string values into the returned array and then make any modifications to other properties in subsequent configuration objects: +To include these predefined configurations, install the `@eslint/js` package and then make any modifications to other properties in subsequent configuration objects: ```js +import js from "@eslint/js"; + export default [ - "eslint:recommended", + js.configs.recommended, { rules: { semi: ["warn", "always"] @@ -580,7 +582,20 @@ export default [ ]; ``` -Here, the `eslint:recommended` predefined configuration is applied first and then another configuration object adds the desired configuration for `semi`. +Here, the `js.configs.recommended` predefined configuration is applied first and then another configuration object adds the desired configuration for `semi`. + +You can apply these predefined configs to just a subset of files by specifying a config object with a `files` key, like this: + +```js +import js from "@eslint/js"; + +export default [ + { + files: ["**/src/safe/*.js"], + ...js.configs.recommended + } +]; +``` ## Configuration File Resolution diff --git a/lib/cli-engine/cli-engine.js b/lib/cli-engine/cli-engine.js index fdc66198809..5bca1618b94 100644 --- a/lib/cli-engine/cli-engine.js +++ b/lib/cli-engine/cli-engine.js @@ -615,8 +615,8 @@ class CLIEngine { useEslintrc: options.useEslintrc, builtInRules, loadRules, - getEslintRecommendedConfig: () => require("../../conf/eslint-recommended.js"), - getEslintAllConfig: () => require("../../conf/eslint-all.js") + getEslintRecommendedConfig: () => require("@eslint/js").configs.recommended, + getEslintAllConfig: () => require("@eslint/js").configs.all }); const fileEnumerator = new FileEnumerator({ configArrayFactory, diff --git a/lib/cli-engine/file-enumerator.js b/lib/cli-engine/file-enumerator.js index b65d0a20692..9625e4aa701 100644 --- a/lib/cli-engine/file-enumerator.js +++ b/lib/cli-engine/file-enumerator.js @@ -217,8 +217,8 @@ class FileEnumerator { cwd = process.cwd(), configArrayFactory = new CascadingConfigArrayFactory({ cwd, - getEslintRecommendedConfig: () => require("../../conf/eslint-recommended.js"), - getEslintAllConfig: () => require("../../conf/eslint-all.js") + getEslintRecommendedConfig: () => require("@eslint/js").configs.recommended, + getEslintAllConfig: () => require("@eslint/js").configs.all }), extensions = null, globInputPaths = true, diff --git a/lib/config/flat-config-array.js b/lib/config/flat-config-array.js index 24b456da57c..46d436db5cf 100644 --- a/lib/config/flat-config-array.js +++ b/lib/config/flat-config-array.js @@ -13,7 +13,7 @@ const { ConfigArray, ConfigArraySymbol } = require("@humanwhocodes/config-array" const { flatConfigSchema } = require("./flat-config-schema"); const { RuleValidator } = require("./rule-validator"); const { defaultConfig } = require("./default-config"); -const recommendedConfig = require("../../conf/eslint-recommended"); +const jsPlugin = require("@eslint/js"); //----------------------------------------------------------------------------- // Helpers @@ -96,17 +96,23 @@ class FlatConfigArray extends ConfigArray { */ [ConfigArraySymbol.preprocessConfig](config) { if (config === "eslint:recommended") { - return recommendedConfig; + + // if we are in a Node.js environment warn the user + if (typeof process !== "undefined" && process.emitWarning) { + process.emitWarning("The 'eslint:recommended' string configuration is deprecated and will be replaced by the @eslint/js package's 'recommended' config."); + } + + return jsPlugin.configs.recommended; } if (config === "eslint:all") { - /* - * Load `eslint-all.js` here instead of at the top level to avoid loading all rule modules - * when it isn't necessary. `eslint-all.js` reads `meta` of rule objects to filter out deprecated ones, - * so requiring `eslint-all.js` module loads all rule modules as a consequence. - */ - return require("../../conf/eslint-all"); + // if we are in a Node.js environment warn the user + if (typeof process !== "undefined" && process.emitWarning) { + process.emitWarning("The 'eslint:all' string configuration is deprecated and will be replaced by the @eslint/js package's 'all' config."); + } + + return jsPlugin.configs.all; } /* diff --git a/package.json b/package.json index 8d3aeada0af..3ac2e9cb403 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,10 @@ "lint-staged": { "*.js": "eslint --fix", "*.md": "markdownlint --fix", + "lib/rules/*.js": [ + "node tools/update-eslint-all.js", + "git add packages/js/src/configs/eslint-all.js" + ], "docs/src/rules/*.md": [ "node tools/fetch-docs-links.js", "git add docs/src/_data/further_reading_links.json" @@ -57,6 +61,7 @@ "bugs": "https://github.com/eslint/eslint/issues/", "dependencies": { "@eslint/eslintrc": "^1.4.1", + "@eslint/js": "8.33.0", "@humanwhocodes/config-array": "^0.11.8", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", diff --git a/packages/js/LICENSE b/packages/js/LICENSE new file mode 100644 index 00000000000..b607bb36e96 --- /dev/null +++ b/packages/js/LICENSE @@ -0,0 +1,19 @@ +Copyright OpenJS Foundation and other contributors, + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/js/README.md b/packages/js/README.md new file mode 100644 index 00000000000..a8121c3a77b --- /dev/null +++ b/packages/js/README.md @@ -0,0 +1,57 @@ +[![npm version](https://img.shields.io/npm/v/@eslint/js.svg)](https://www.npmjs.com/package/@eslint/js) + +# ESLint JavaScript Plugin + +[Website](https://eslint.org) | [Configure ESLint](https://eslint.org/docs/latest/use/configure) | [Rules](https://eslint.org/docs/rules/) | [Contributing](https://eslint.org/docs/latest/contribute) | [Twitter](https://twitter.com/geteslint) | [Chatroom](https://eslint.org/chat) + +The beginnings of separating out JavaScript-specific functionality from ESLint. + +Right now, this plugin contains two configurations: + +* `recommended` - enables the rules recommended by the ESLint team (the replacement for `"eslint:recommended"`) +* `all` - enables all ESLint rules (the replacement for `"eslint:all"`) + +## Installation + +```shell +npm install @eslint/js -D +``` + +## Usage + +Use in your `eslint.config.js` file anytime you want to extend one of the configs: + +```js +import js from "@eslint/js"; + +export default [ + + // apply recommended rules to JS files + { + files: ["**/*.js"], + rules: js.configs.recommended.rules + }, + + // apply recommended rules to JS files with an override + { + files: ["**/*.js"], + rules: { + ...js.configs.recommended.rules, + "no-unused-vars": "warn" + } + }, + + // apply all rules to JS files + { + files: ["**/*.js"], + rules: { + ...js.configs.all.rules, + "no-unused-vars": "warn" + } + } +] +``` + +## License + +MIT diff --git a/packages/js/package.json b/packages/js/package.json new file mode 100644 index 00000000000..a5a9d0bcbdc --- /dev/null +++ b/packages/js/package.json @@ -0,0 +1,32 @@ +{ + "name": "@eslint/js", + "version": "8.33.0", + "description": "ESLint JavaScript language implementation", + "main": "./src/index.js", + "scripts": { + }, + "files": [ + "LICENSE", + "README.md", + "src" + ], + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "https://github.com/eslint/eslint.git", + "directory": "packages/js" + }, + "homepage": "https://eslint.org", + "bugs": "https://github.com/eslint/eslint/issues/", + "keywords": [ + "javascript", + "eslint-plugin", + "eslint" + ], + "license": "MIT", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } +} diff --git a/packages/js/src/configs/eslint-all.js b/packages/js/src/configs/eslint-all.js new file mode 100644 index 00000000000..f3a415cce5c --- /dev/null +++ b/packages/js/src/configs/eslint-all.js @@ -0,0 +1,279 @@ +/* + * WARNING: This file is autogenerated using the tools/update-eslint-all.js + * script. Do not edit manually. + */ +"use strict"; + +/* eslint quote-props: off -- autogenerated so don't lint */ + +module.exports = Object.freeze({ + "rules": { + "accessor-pairs": "error", + "array-bracket-newline": "error", + "array-bracket-spacing": "error", + "array-callback-return": "error", + "array-element-newline": "error", + "arrow-body-style": "error", + "arrow-parens": "error", + "arrow-spacing": "error", + "block-scoped-var": "error", + "block-spacing": "error", + "brace-style": "error", + "camelcase": "error", + "capitalized-comments": "error", + "class-methods-use-this": "error", + "comma-dangle": "error", + "comma-spacing": "error", + "comma-style": "error", + "complexity": "error", + "computed-property-spacing": "error", + "consistent-return": "error", + "consistent-this": "error", + "constructor-super": "error", + "curly": "error", + "default-case": "error", + "default-case-last": "error", + "default-param-last": "error", + "dot-location": "error", + "dot-notation": "error", + "eol-last": "error", + "eqeqeq": "error", + "for-direction": "error", + "func-call-spacing": "error", + "func-name-matching": "error", + "func-names": "error", + "func-style": "error", + "function-call-argument-newline": "error", + "function-paren-newline": "error", + "generator-star-spacing": "error", + "getter-return": "error", + "grouped-accessor-pairs": "error", + "guard-for-in": "error", + "id-denylist": "error", + "id-length": "error", + "id-match": "error", + "implicit-arrow-linebreak": "error", + "indent": "error", + "init-declarations": "error", + "jsx-quotes": "error", + "key-spacing": "error", + "keyword-spacing": "error", + "line-comment-position": "error", + "linebreak-style": "error", + "lines-around-comment": "error", + "lines-between-class-members": "error", + "logical-assignment-operators": "error", + "max-classes-per-file": "error", + "max-depth": "error", + "max-len": "error", + "max-lines": "error", + "max-lines-per-function": "error", + "max-nested-callbacks": "error", + "max-params": "error", + "max-statements": "error", + "max-statements-per-line": "error", + "multiline-comment-style": "error", + "multiline-ternary": "error", + "new-cap": "error", + "new-parens": "error", + "newline-per-chained-call": "error", + "no-alert": "error", + "no-array-constructor": "error", + "no-async-promise-executor": "error", + "no-await-in-loop": "error", + "no-bitwise": "error", + "no-caller": "error", + "no-case-declarations": "error", + "no-class-assign": "error", + "no-compare-neg-zero": "error", + "no-cond-assign": "error", + "no-confusing-arrow": "error", + "no-console": "error", + "no-const-assign": "error", + "no-constant-binary-expression": "error", + "no-constant-condition": "error", + "no-constructor-return": "error", + "no-continue": "error", + "no-control-regex": "error", + "no-debugger": "error", + "no-delete-var": "error", + "no-div-regex": "error", + "no-dupe-args": "error", + "no-dupe-class-members": "error", + "no-dupe-else-if": "error", + "no-dupe-keys": "error", + "no-duplicate-case": "error", + "no-duplicate-imports": "error", + "no-else-return": "error", + "no-empty": "error", + "no-empty-character-class": "error", + "no-empty-function": "error", + "no-empty-pattern": "error", + "no-empty-static-block": "error", + "no-eq-null": "error", + "no-eval": "error", + "no-ex-assign": "error", + "no-extend-native": "error", + "no-extra-bind": "error", + "no-extra-boolean-cast": "error", + "no-extra-label": "error", + "no-extra-parens": "error", + "no-extra-semi": "error", + "no-fallthrough": "error", + "no-floating-decimal": "error", + "no-func-assign": "error", + "no-global-assign": "error", + "no-implicit-coercion": "error", + "no-implicit-globals": "error", + "no-implied-eval": "error", + "no-import-assign": "error", + "no-inline-comments": "error", + "no-inner-declarations": "error", + "no-invalid-regexp": "error", + "no-invalid-this": "error", + "no-irregular-whitespace": "error", + "no-iterator": "error", + "no-label-var": "error", + "no-labels": "error", + "no-lone-blocks": "error", + "no-lonely-if": "error", + "no-loop-func": "error", + "no-loss-of-precision": "error", + "no-magic-numbers": "error", + "no-misleading-character-class": "error", + "no-mixed-operators": "error", + "no-mixed-spaces-and-tabs": "error", + "no-multi-assign": "error", + "no-multi-spaces": "error", + "no-multi-str": "error", + "no-multiple-empty-lines": "error", + "no-negated-condition": "error", + "no-nested-ternary": "error", + "no-new": "error", + "no-new-func": "error", + "no-new-native-nonconstructor": "error", + "no-new-object": "error", + "no-new-symbol": "error", + "no-new-wrappers": "error", + "no-nonoctal-decimal-escape": "error", + "no-obj-calls": "error", + "no-octal": "error", + "no-octal-escape": "error", + "no-param-reassign": "error", + "no-plusplus": "error", + "no-promise-executor-return": "error", + "no-proto": "error", + "no-prototype-builtins": "error", + "no-redeclare": "error", + "no-regex-spaces": "error", + "no-restricted-exports": "error", + "no-restricted-globals": "error", + "no-restricted-imports": "error", + "no-restricted-properties": "error", + "no-restricted-syntax": "error", + "no-return-assign": "error", + "no-return-await": "error", + "no-script-url": "error", + "no-self-assign": "error", + "no-self-compare": "error", + "no-sequences": "error", + "no-setter-return": "error", + "no-shadow": "error", + "no-shadow-restricted-names": "error", + "no-sparse-arrays": "error", + "no-tabs": "error", + "no-template-curly-in-string": "error", + "no-ternary": "error", + "no-this-before-super": "error", + "no-throw-literal": "error", + "no-trailing-spaces": "error", + "no-undef": "error", + "no-undef-init": "error", + "no-undefined": "error", + "no-underscore-dangle": "error", + "no-unexpected-multiline": "error", + "no-unmodified-loop-condition": "error", + "no-unneeded-ternary": "error", + "no-unreachable": "error", + "no-unreachable-loop": "error", + "no-unsafe-finally": "error", + "no-unsafe-negation": "error", + "no-unsafe-optional-chaining": "error", + "no-unused-expressions": "error", + "no-unused-labels": "error", + "no-unused-private-class-members": "error", + "no-unused-vars": "error", + "no-use-before-define": "error", + "no-useless-backreference": "error", + "no-useless-call": "error", + "no-useless-catch": "error", + "no-useless-computed-key": "error", + "no-useless-concat": "error", + "no-useless-constructor": "error", + "no-useless-escape": "error", + "no-useless-rename": "error", + "no-useless-return": "error", + "no-var": "error", + "no-void": "error", + "no-warning-comments": "error", + "no-whitespace-before-property": "error", + "no-with": "error", + "nonblock-statement-body-position": "error", + "object-curly-newline": "error", + "object-curly-spacing": "error", + "object-property-newline": "error", + "object-shorthand": "error", + "one-var": "error", + "one-var-declaration-per-line": "error", + "operator-assignment": "error", + "operator-linebreak": "error", + "padded-blocks": "error", + "padding-line-between-statements": "error", + "prefer-arrow-callback": "error", + "prefer-const": "error", + "prefer-destructuring": "error", + "prefer-exponentiation-operator": "error", + "prefer-named-capture-group": "error", + "prefer-numeric-literals": "error", + "prefer-object-has-own": "error", + "prefer-object-spread": "error", + "prefer-promise-reject-errors": "error", + "prefer-regex-literals": "error", + "prefer-rest-params": "error", + "prefer-spread": "error", + "prefer-template": "error", + "quote-props": "error", + "quotes": "error", + "radix": "error", + "require-atomic-updates": "error", + "require-await": "error", + "require-unicode-regexp": "error", + "require-yield": "error", + "rest-spread-spacing": "error", + "semi": "error", + "semi-spacing": "error", + "semi-style": "error", + "sort-imports": "error", + "sort-keys": "error", + "sort-vars": "error", + "space-before-blocks": "error", + "space-before-function-paren": "error", + "space-in-parens": "error", + "space-infix-ops": "error", + "space-unary-ops": "error", + "spaced-comment": "error", + "strict": "error", + "switch-colon-spacing": "error", + "symbol-description": "error", + "template-curly-spacing": "error", + "template-tag-spacing": "error", + "unicode-bom": "error", + "use-isnan": "error", + "valid-typeof": "error", + "vars-on-top": "error", + "wrap-iife": "error", + "wrap-regex": "error", + "yield-star-spacing": "error", + "yoda": "error" + } +}); diff --git a/conf/eslint-recommended.js b/packages/js/src/configs/eslint-recommended.js similarity index 97% rename from conf/eslint-recommended.js rename to packages/js/src/configs/eslint-recommended.js index 6f639855a96..248c613caed 100644 --- a/conf/eslint-recommended.js +++ b/packages/js/src/configs/eslint-recommended.js @@ -9,8 +9,8 @@ /* eslint sort-keys: ["error", "asc"] -- Long, so make more readable */ /** @type {import("../lib/shared/types").ConfigData} */ -module.exports = { - rules: { +module.exports = Object.freeze({ + rules: Object.freeze({ "constructor-super": "error", "for-direction": "error", "getter-return": "error", @@ -72,5 +72,5 @@ module.exports = { "require-yield": "error", "use-isnan": "error", "valid-typeof": "error" - } -}; + }) +}); diff --git a/packages/js/src/index.js b/packages/js/src/index.js new file mode 100644 index 00000000000..0d4be486a9b --- /dev/null +++ b/packages/js/src/index.js @@ -0,0 +1,17 @@ +/** + * @fileoverview Main package entrypoint. + * @author Nicholas C. Zakas + */ + +"use strict"; + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +module.exports = { + configs: { + all: require("./configs/eslint-all"), + recommended: require("./configs/eslint-recommended") + } +}; diff --git a/tests/conf/eslint-all.js b/tests/conf/eslint-all.js index 472ac3b25d7..abee0c69b16 100644 --- a/tests/conf/eslint-all.js +++ b/tests/conf/eslint-all.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const assert = require("chai").assert; -const eslintAll = require("../../conf/eslint-all"); +const eslintAll = require("../../packages/js").configs.all; const rules = eslintAll.rules; //------------------------------------------------------------------------------ diff --git a/tests/conf/eslint-recommended.js b/tests/conf/eslint-recommended.js index a3068e14140..59803dce6cf 100644 --- a/tests/conf/eslint-recommended.js +++ b/tests/conf/eslint-recommended.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const assert = require("chai").assert; -const eslintRecommended = require("../../conf/eslint-recommended"); +const eslintRecommended = require("../../packages/js").configs.recommended; const rules = eslintRecommended.rules; //------------------------------------------------------------------------------ diff --git a/tests/lib/cli.js b/tests/lib/cli.js index 93b7680bd77..cef1ab478df 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -1447,7 +1447,7 @@ describe("cli", () => { getFixturePath("globals-node.js") ]; - await cli.execute(`--no-eslintrc --config ./conf/eslint-recommended.js --no-ignore ${files.join(" ")}`); + await cli.execute(`--no-eslintrc --config ./packages/js/src/configs/eslint-recommended.js --no-ignore ${files.join(" ")}`); assert.strictEqual(log.info.args[0][0].split("\n").length, 10); }); diff --git a/tests/lib/config/flat-config-array.js b/tests/lib/config/flat-config-array.js index 0b284f61f07..fc3e455bfe6 100644 --- a/tests/lib/config/flat-config-array.js +++ b/tests/lib/config/flat-config-array.js @@ -11,8 +11,10 @@ const { FlatConfigArray } = require("../../../lib/config/flat-config-array"); const assert = require("chai").assert; -const allConfig = require("../../../conf/eslint-all"); -const recommendedConfig = require("../../../conf/eslint-recommended"); +const { + all: allConfig, + recommended: recommendedConfig +} = require("@eslint/js").configs; const stringify = require("json-stable-stringify-without-jsonify"); //----------------------------------------------------------------------------- diff --git a/conf/eslint-all.js b/tools/update-eslint-all.js similarity index 54% rename from conf/eslint-all.js rename to tools/update-eslint-all.js index 10c5304fd3f..b964876f736 100644 --- a/conf/eslint-all.js +++ b/tools/update-eslint-all.js @@ -1,14 +1,15 @@ /** - * @fileoverview Config to enable all rules. - * @author Robert Fletcher + * @fileoverview Script to update the eslint:all configuration. + * @author Nicholas C. Zakas */ "use strict"; -//------------------------------------------------------------------------------ +//----------------------------------------------------------------------------- // Requirements -//------------------------------------------------------------------------------ +//----------------------------------------------------------------------------- +const fs = require("fs"); const builtInRules = require("../lib/rules"); //------------------------------------------------------------------------------ @@ -23,9 +24,19 @@ for (const [ruleId, rule] of builtInRules) { } } -//------------------------------------------------------------------------------ -// Public Interface -//------------------------------------------------------------------------------ +//----------------------------------------------------------------------------- +// Main +//----------------------------------------------------------------------------- + +const code = `/* + * WARNING: This file is autogenerated using the tools/update-eslint-all.js + * script. Do not edit manually. + */ +"use strict"; + +/* eslint quote-props: off -- autogenerated so don't lint */ + +module.exports = Object.freeze(${JSON.stringify({ rules: allRules }, null, 4)}); +`; -/** @type {import("../lib/shared/types").ConfigData} */ -module.exports = { rules: allRules }; +fs.writeFileSync("./packages/js/src/configs/eslint-all.js", code, "utf8");