Skip to content

Commit 78ac75e

Browse files
westonruterclaude
andcommitted
Migrate ESLint to flat config for @wordpress/scripts 32
@wordpress/scripts 32 upgrades the bundled ESLint from v8 to v10, which no longer supports `.eslintrc.*` files or the `--ignore-path` flag. - Replace `.eslintrc.js` with a flat `eslint.config.js` that extends `@wordpress/scripts/config/eslint.config.cjs`, preserving the `jsdoc/valid-types` and `tools/**` `import/no-extraneous-dependencies` tweaks and moving the `.gitignore`-based ignores into the config. - Drop the now-invalid `--ignore-path=.gitignore` from the `lint:js*` scripts and the lint-staged JS task. - Add the `globals` devDependency used by the flat config. - Bump `.nvmrc` to 20.19 (minimum Node for ESLint 10 / @eslint/compat). - Remove the redundant `eslint-disable no-console` in validate-json.js (the flat config disables `no-console` for Node tooling files, so ESLint 10 flags the directive as unused). Adapted from WordPress/performance#2461. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 026cab3 commit 78ac75e

7 files changed

Lines changed: 96 additions & 53 deletions

File tree

.eslintrc.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20
1+
20.19

eslint.config.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* ESLint flat config.
3+
*
4+
* Extends the shared configuration shipped with `@wordpress/scripts` (which is
5+
* based on the WordPress coding standards) and layers the project-specific
6+
* tweaks on top.
7+
*/
8+
9+
/**
10+
* External dependencies
11+
*/
12+
const globals = require( 'globals' );
13+
// @ts-ignore -- No declaration file for this module.
14+
const wpScriptsConfig = require( '@wordpress/scripts/config/eslint.config.cjs' );
15+
16+
// Build tooling, CLI scripts, and root-level config files — Node CommonJS,
17+
// not browser code. Used both to exclude these from the browser-globals block
18+
// and as the target of the dedicated Node tooling override below.
19+
const nodeToolingFiles = [ 'tools/**/*.js', '*.config.js', '.*.js' ];
20+
21+
module.exports = [
22+
...wpScriptsConfig,
23+
{
24+
// Ignore patterns in addition to those provided by @wordpress/scripts.
25+
// Replaces the previous `--ignore-path=.gitignore`, which ESLint's flat
26+
// config no longer supports.
27+
ignores: [ 'vendor/', 'dist/', '**/*.min.js', 'lint-js-report.json' ],
28+
},
29+
{
30+
// Browser globals for client-side scripts (everything but the Node tooling below).
31+
files: [ '**/*.js' ],
32+
ignores: nodeToolingFiles,
33+
languageOptions: {
34+
globals: {
35+
...globals.browser,
36+
},
37+
},
38+
},
39+
{
40+
// Node-based build tooling and CLI scripts (CommonJS).
41+
files: nodeToolingFiles,
42+
languageOptions: {
43+
sourceType: 'commonjs',
44+
globals: {
45+
...globals.node,
46+
},
47+
},
48+
rules: {
49+
'no-console': 'off',
50+
'import/no-extraneous-dependencies': [
51+
'error',
52+
{ devDependencies: true },
53+
],
54+
},
55+
},
56+
{
57+
files: [ '**/*.js' ],
58+
rules: {
59+
'jsdoc/valid-types': 'off',
60+
},
61+
},
62+
];

lint-staged.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
const config = {
55
'*.{js,ts,mjs}': [
6-
'wp-scripts lint-js --ignore-path=.gitignore',
6+
'wp-scripts lint-js',
77
() => 'npx tsc --allowJs --noEmit',
88
],
99
'**/*.json': [ 'npm run lint:json' ],

package-lock.json

Lines changed: 28 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"ajv-draft-04": "^1.0.0",
2020
"ajv-formats": "^3.0.1",
2121
"fast-glob": "^3.3.3",
22+
"globals": "^17.6.0",
2223
"husky": "^9",
2324
"lint-staged": "^16",
2425
"typescript": "^6"
@@ -32,9 +33,9 @@
3233
"lint:composer:fix": "composer normalize",
3334
"lint:css": "wp-scripts lint-style --allow-empty-input --ignore-path=.gitignore",
3435
"lint:css:fix": "wp-scripts lint-style --fix --allow-empty-input --ignore-path=.gitignore",
35-
"lint:js": "wp-scripts lint-js --ignore-path=.gitignore",
36-
"lint:js:fix": "wp-scripts lint-js --fix --ignore-path=.gitignore",
37-
"lint:js:report": "wp-scripts lint-js --ignore-path=.gitignore --output-file=lint-js-report.json --format=json .",
36+
"lint:js": "wp-scripts lint-js",
37+
"lint:js:fix": "wp-scripts lint-js --fix",
38+
"lint:js:report": "wp-scripts lint-js --output-file=lint-js-report.json --format=json .",
3839
"lint:json": "node tools/validate-json.js",
3940
"lint:md": "wp-scripts lint-md-docs --ignore-path=.gitignore",
4041
"lint:php": "composer phpcs",

tools/validate-json.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env node
22

3-
/* eslint-disable no-console */
4-
53
/**
64
* External dependencies
75
*/

0 commit comments

Comments
 (0)