Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Move all and recommended configs into package. #16844

Merged
merged 14 commits into from Feb 23, 2023
2 changes: 1 addition & 1 deletion Makefile.js
Expand Up @@ -835,7 +835,7 @@ target.checkRuleFiles = function() {
}

// check eslint:recommended
const recommended = require("./conf/eslint-recommended");
const recommended = require("./packages/js").configs.recommended;
nzakas marked this conversation as resolved.
Show resolved Hide resolved

if (ruleDef.meta.docs.recommended) {
if (recommended.rules[basename] !== "error") {
Expand Down
27 changes: 21 additions & 6 deletions docs/src/use/configure/configuration-files-new.md
Expand Up @@ -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"]
Expand All @@ -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 but specifying a config object with a `files` key, like this:
nzakas marked this conversation as resolved.
Show resolved Hide resolved

```js
import js from "@eslint/js";

export default [
{
files: ["**/src/safe/*.js"],
...js.configs.recommended
}
];
```

## Configuration File Resolution

Expand Down
4 changes: 2 additions & 2 deletions lib/cli-engine/cli-engine.js
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/cli-engine/file-enumerator.js
Expand Up @@ -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,
Expand Down
22 changes: 14 additions & 8 deletions lib/config/flat-config-array.js
Expand Up @@ -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
Expand Down Expand Up @@ -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.");
nzakas marked this conversation as resolved.
Show resolved Hide resolved
}

return jsPlugin.configs.all;
}

/*
Expand Down
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -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/all.js"
nzakas marked this conversation as resolved.
Show resolved Hide resolved
],
"docs/src/rules/*.md": [
"node tools/fetch-docs-links.js",
"git add docs/src/_data/further_reading_links.json"
Expand All @@ -57,6 +61,7 @@
"bugs": "https://github.com/eslint/eslint/issues/",
"dependencies": {
"@eslint/eslintrc": "^1.4.1",
"@eslint/js": "^8.0.0",
nzakas marked this conversation as resolved.
Show resolved Hide resolved
"@humanwhocodes/config-array": "^0.11.8",
"@humanwhocodes/module-importer": "^1.0.1",
"@nodelib/fs.walk": "^1.2.8",
Expand Down
20 changes: 20 additions & 0 deletions packages/js/LICENSE
@@ -0,0 +1,20 @@
ESLint
Copyright JS Foundation and other contributors, https://js.foundation
nzakas marked this conversation as resolved.
Show resolved Hide resolved

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.
57 changes: 57 additions & 0 deletions packages/js/README.md
@@ -0,0 +1,57 @@
[![npm version][npm-image]][npm-url]
nzakas marked this conversation as resolved.
Show resolved Hide resolved

# 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
nzakas marked this conversation as resolved.
Show resolved Hide resolved
},

// apply recommended rules to JS files with an override
{
files: ["**/*.js"],
rules: {
...js.configs.recommended
nzakas marked this conversation as resolved.
Show resolved Hide resolved
"no-unused-vars": "warn"
}
},

// apply all rules to JS files
{
files: ["**/*.js"],
rules: {
...js.configs.all
nzakas marked this conversation as resolved.
Show resolved Hide resolved
"no-unused-vars": "warn"
}
}
]
```

## License

MIT
31 changes: 31 additions & 0 deletions packages/js/package.json
@@ -0,0 +1,31 @@
{
"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"
nzakas marked this conversation as resolved.
Show resolved Hide resolved
},
"homepage": "https://eslint.org",
"bugs": "https://github.com/eslint/eslint/issues/",
"keywords": [
"javascript",
"eslint-plugin",
"eslint"
],
"license": "MIT",
"engines": {
"node": "^10.12.0 || >=12.0.0"
nzakas marked this conversation as resolved.
Show resolved Hide resolved
}
}