8000 feat: Enable eslint.config.js lookup from CLI (#16235) · eslint/eslint@3e5839e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e5839e

Browse files
authored
feat: Enable eslint.config.js lookup from CLI (#16235)
* feat: Enable eslint.config.js lookup from CLI Refs #13481 * Switch to eslint.config.js * Fix lint errors * Restore .eslintrc.js * Add warning to .eslintrc.js file * Add suppressed messages * Add suppressedMessages checks in tests * Remove v8-compile-cache * Fix CLI test * Update comments in config files * Remove --ext option * Fix options tests * Try to fix Windows errors * Try to fix Windows tests again * Try again to fix Windows errors * Fix windows tests again
1 parent 30b1a2d commit 3e5839e

File tree

20 files changed

+1893
-1605
lines changed

20 files changed

+1893
-1605
lines changed

.eslintrc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* IMPORTANT!
3+
*
4+
* Any changes made to this file must also be made to eslint.config.js.
5+
*
6+
* Internally, ESLint is using the eslint.config.js file to lint itself.
7+
* This file is needed too, because:
8+
*
9+
* 1. There are tests that expect .eslintrc.js to be present to actually run.
10+
* 2. ESLint VS Code extension expects eslintrc config files to be
11+
* present to work correctly.
12+
*
13+
* Once we no longer need to support both eslintrc and flat config, we will
14+
* remove this file.
15+
*/
16+
17+
118
"use strict";
219

320
const path = require("path");

bin/eslint.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
"use strict";
1111

12-
// to use V8's code cache to speed up instantiation time
13-
require("v8-compile-cache");
14-
1512
// must do this initialization *before* other requires in order to work
1613
if (process.argv.includes("--debug")) {
1714
require("debug").enable("eslint:*,-eslint:code-path,eslintrc:*");
@@ -137,6 +134,7 @@ ${message}`);
137134
// Otherwise, call the CLI.
138135
process.exitCode = await require("../lib/cli").execute(
139136
process.argv,
140-
process.argv.includes("--stdin") ? await readStdin() : null
137+
process.argv.includes("--stdin") ? await readStdin() : null,
138+
true
141139
);
142140
}()).catch(onFatalError);

docs/src/user-guide/configuring/configuration-files-new.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ eleventyNavigation:
1010
---
1111

1212
::: warning
13-
This is an experimental feature that is not enabled by default. You can use the configuration system described on this page by using the `FlatESLint` class, the `FlatRuleTester` class, or by setting `configType: "flat"` in the `Linter` class.
13+
This is an experimental feature. To opt-in, place a `eslint.config.js` file in the root of your project. If you are using the API, you can use the configuration system described on this page by using the `FlatESLint` class, the `FlatRuleTester` class, or by setting `configType: "flat"` in the `Linter` class.
1414
:::
1515

1616
## Configuration File

eslint.config.js

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,29 @@
55

66
"use strict";
77

8+
/*
9+
* IMPORTANT!
10+
*
11+
* Any changes made to this file must also be made to .eslintrc.js.
12+
*
13+
* Internally, ESLint is using the eslint.config.js file to lint itself.
14+
* The .eslintrc.js file is needed too, because:
15+
*
16+
* 1. There are tests that expect .eslintrc.js to be present to actually run.
17+
* 2. ESLint VS Code extension expects eslintrc config files to be
18+
* present to work correctly.
19+
*
20+
* Once we no longer need to support both eslintrc and flat config, we will
21+
* remove .eslintrc.js.
22+
*/
23+
824
//-----------------------------------------------------------------------------
925
// Requirements
1026
//-----------------------------------------------------------------------------
1127

1228
const path = require("path");
1329
const internalPlugin = require("eslint-plugin-internal-rules");
30+
const eslintPlugin = require("eslint-plugin-eslint-plugin");
1431
const { FlatCompat } = require("@eslint/eslintrc");
1532
const globals = require("globals");
1633

@@ -24,7 +41,6 @@ const compat = new FlatCompat({
2441

2542
const INTERNAL_FILES = {
2643
CLI_ENGINE_PATTERN: "lib/cli-engine/**/*",
27-
INIT_PATTERN: "lib/init/**/*",
2844
LINTER_PATTERN: "lib/linter/**/*",
2945
RULE_TESTER_PATTERN: "lib/rule-tester/**/*",
3046
RULES_PATTERN: "lib/rules/**/*",
@@ -60,11 +76,6 @@ function createInternalFilesPatterns(pattern = null) {
6076
}));
6177
}
6278

63-
64-
//-----------------------------------------------------------------------------
65-
// Config
66-
//-----------------------------------------------------------------------------
67-
6879
module.exports = [
6980
...compat.extends("eslint", "plugin:eslint-plugin/recommended"),
7081
{
@@ -101,13 +112,25 @@ module.exports = [
101112
"eslint-plugin/test-case-shorthand-strings": "error",
102113
"internal-rules/multiline-comment-style": "error"
103114
}
104-
115+
},
116+
{
117+
files: ["tools/*.js"],
118+
rules: {
119+
"no-console": "off"
120+
}
105121
},
106122
{
107123
files: ["lib/rules/*", "tools/internal-rules/*"],
108-
ignores: ["index.js"],
124+
ignores: ["**/index.js"],
109125
rules: {
110-
"eslint-plugin/prefer-object-rule": "error",
126+
...eslintPlugin.configs["rules-recommended"].rules,
127+
"eslint-plugin/no-missing-message-ids": "error",
128+
"eslint-plugin/no-unused-message-ids": "error",
129+
"eslint-plugin/prefer-message-ids": "error",
130+
"eslint-plugin/prefer-placeholders": "error",
131+
"eslint-plugin/prefer-replace-text": "error",
132+
"eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
133+
"eslint-plugin/require-meta-docs-description": ["error", { pattern: "^(Enforce|Require|Disallow)" }],
111134
"internal-rules/no-invalid-meta": "error"
112135
}
113136
},
@@ -119,7 +142,16 @@ module.exports = [
119142
}
120143
},
121144
{
122-
files: ["tests/**/*"],
145+
files: ["tests/lib/rules/*", "tests/tools/internal-rules/*"],
146+
rules: {
147+
...eslintPlugin.configs["tests-recommended"].rules,
148+
"eslint-plugin/prefer-output-null": "error",
149+
"eslint-plugin/test-case-property-ordering": "error",
150+
"eslint-plugin/test-case-shorthand-strings": "error"
151+
}
152+
},
153+
{
154+
files: ["tests/**/*.js"],
123155
languageOptions: {
124156
globals: {
125157
...globals.mocha
@@ -147,17 +179,7 @@ module.exports = [
147179
files: [INTERNAL_FILES.CLI_ENGINE_PATTERN],
148180
rules: {
149181
"n/no-restricted-require": ["error", [
150-
...createInternalFilesPatterns(INTERNAL_FILES.CLI_ENGINE_PATTERN),
151-
resolveAbsolutePath("lib/init/index.js")
152-
]]
153-
}
154-
},
155-
{
156-
files: [INTERNAL_FILES.INIT_PATTERN],
157-
rules: {
158-
"n/no-restricted-require": ["error", [
159-
...createInternalFilesPatterns(INTERNAL_FILES.INIT_PATTERN),
160-
resolveAbsolutePath("lib/rule-tester/index.js")
182+
...createInternalFilesPatterns(INTERNAL_FILES.CLI_ENGINE_PATTERN)
161183
]]
162184
}
163185
},
@@ -168,7 +190,6 @@ module.exports = [
168190
...createInternalFilesPatterns(INTERNAL_FILES.LINTER_PATTERN),
169191
"fs",
170192
resolveAbsolutePath("lib/cli-engine/index.js"),
171-
resolveAbsolutePath("lib/init/index.js"),
172193
resolveAbsolutePath("lib/rule-tester/index.js")
173194
]]
174195
}
@@ -180,7 +201,6 @@ module.exports = [
180201
...createInternalFilesPatterns(INTERNAL_FILES.RULES_PATTERN),
181202
"fs",
182203
resolveAbsolutePath("lib/cli-engine/index.js"),
183-
resolveAbsolutePath("lib/init/index.js"),
184204
resolveAbsolutePath("lib/linter/index.js"),
185205
resolveAbsolutePath("lib/rule-tester/index.js"),
186206
resolveAbsolutePath("lib/source-code/index.js")
@@ -193,7 +213,6 @@ module.exports = [
193213
"n/no-restricted-require": ["error", [
194214
...createInternalFilesPatterns(),
195215
resolveAbsolutePath("lib/cli-engine/index.js"),
196-
resolveAbsolutePath("lib/init/index.js"),
197216
resolveAbsolutePath("lib/linter/index.js"),
198217
resolveAbsolutePath("lib/rule-tester/index.js"),
199218
resolveAbsolutePath("lib/source-code/index.js")
@@ -207,7 +226,6 @@ module.exports = [
207226
...createInternalFilesPatterns(INTERNAL_FILES.SOURCE_CODE_PATTERN),
208227
"fs",
209228
resolveAbsolutePath("lib/cli-engine/index.js"),
210-
resolveAbsolutePath("lib/init/index.js"),
211229
resolveAbsolutePath("lib/linter/index.js"),
212230
resolveAbsolutePath("lib/rule-tester/index.js"),
213231
resolveAbsolutePath("lib/rules/index.js")
@@ -219,8 +237,7 @@ module.exports = [
219237
rules: {
220238
"n/no-restricted-require": ["error", [
221239
...createInternalFilesPatterns(INTERNAL_FILES.RULE_TESTER_PATTERN),
222-
resolveAbsolutePath("lib/cli-engine/index.js"),
223-
resolveAbsolutePath("lib/init/index.js")
240+
resolveAbsolutePath("lib/cli-engine/index.js")
224241
]]
225242
}
226243
}

0 commit comments

Comments
 (0)
0