diff --git a/package-lock.json b/package-lock.json index 59ef5289dea6e9..49c86363e0d66f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,6 @@ "widgets/*" ], "devDependencies": { - "@eslint/eslintrc": "^3.0.0", "@types/react": "^18.3.27", "@types/react-dom": "^18.3.1", "@typescript/native-preview": "^7.0.0-dev.20260423.1", @@ -31,8 +30,7 @@ "@wordpress/vips": "file:./packages/vips", "concurrently": "^3.5.0", "cross-env": "^7.0.3", - "eslint": "^10.0.0", - "eslint-formatter-compact": "^9.0.1", + "glob": "^7.1.2", "husky": "^7.0.0", "lerna": "^9.0.7", "lint-staged": "^16.4.0", @@ -3791,80 +3789,6 @@ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "license": "MIT" }, - "node_modules/@eslint/eslintrc": { - "version": "3.3.5", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.3.5.tgz", - "integrity": "sha512-4IlJx0X0qftVsN5E+/vGujTRIFtwuLbNsVUe7TO6zYPDR1O6nFwvwhIKEKSrl6dZchmYBITazxKoUYOjdtjlRg==", - "dev": true, - "license": "MIT", - "dependencies": { - "ajv": "^6.14.0", - "debug": "^4.3.2", - "espree": "^10.0.1", - "globals": "^14.0.0", - "ignore": "^5.2.0", - "import-fresh": "^3.2.1", - "js-yaml": "^4.1.1", - "minimatch": "^3.1.5", - "strip-json-comments": "^3.1.1" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/@eslint/eslintrc/node_modules/ajv": { - "version": "6.14.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.14.0.tgz", - "integrity": "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==", - "dev": true, - "license": "MIT", - "dependencies": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/@eslint/eslintrc/node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true, - "license": "Python-2.0" - }, - "node_modules/@eslint/eslintrc/node_modules/js-yaml": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz", - "integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==", - "dev": true, - "license": "MIT", - "dependencies": { - "argparse": "^2.0.1" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" - } - }, - "node_modules/@eslint/eslintrc/node_modules/minimatch": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", - "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", - "dev": true, - "license": "ISC", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, "node_modules/@eslint/js": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-10.0.1.tgz", @@ -24344,7 +24268,6 @@ "version": "9.0.1", "resolved": "https://registry.npmjs.org/eslint-formatter-compact/-/eslint-formatter-compact-9.0.1.tgz", "integrity": "sha512-mBAti2tb403dQGMyilQTYHU80stem3N7jdtKW+tmn5gj3JNF7ki0rgCZtJFw4iMayTH862FTUIqCdp70ug0S0Q==", - "dev": true, "license": "MIT", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -26786,19 +26709,6 @@ "node": ">=6" } }, - "node_modules/globals": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", - "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/globalthis": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.4.tgz", @@ -50399,7 +50309,8 @@ }, "devDependencies": { "@types/eslint": "^9", - "@types/estree": "^1.0.5" + "@types/estree": "^1.0.5", + "eslint": "^10.0.0" }, "engines": { "node": ">=18.12.0", @@ -54534,6 +54445,8 @@ "@eslint/js": "^10.0.0", "@wordpress/eslint-plugin": "file:../../packages/eslint-plugin", "@wordpress/scripts": "file:../../packages/scripts", + "eslint": "^10.0.0", + "eslint-formatter-compact": "^9.0.1", "eslint-import-resolver-typescript": "^4.4.4", "eslint-plugin-import": "^2.31.0", "eslint-plugin-jest": "^28.11.0", diff --git a/package.json b/package.json index 530da9fac08dc3..b152fd9a1fe593 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,6 @@ "IS_GUTENBERG_PLUGIN": true }, "devDependencies": { - "@eslint/eslintrc": "^3.0.0", "@types/react": "^18.3.27", "@types/react-dom": "^18.3.1", "@typescript/native-preview": "^7.0.0-dev.20260423.1", @@ -71,8 +70,7 @@ "@wordpress/vips": "file:./packages/vips", "concurrently": "^3.5.0", "cross-env": "^7.0.3", - "eslint": "^10.0.0", - "eslint-formatter-compact": "^9.0.1", + "glob": "^7.1.2", "husky": "^7.0.0", "lerna": "^9.0.7", "lint-staged": "^16.4.0", diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 2e2bd297370a3e..75cd8fbf40c30a 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -64,7 +64,8 @@ }, "devDependencies": { "@types/eslint": "^9", - "@types/estree": "^1.0.5" + "@types/estree": "^1.0.5", + "eslint": "^10.0.0" }, "peerDependencies": { "@babel/core": ">=7", diff --git a/packages/jest-preset-default/jest-preset.js b/packages/jest-preset-default/jest-preset.js index f78939501c1931..e6211aa19f1ab5 100644 --- a/packages/jest-preset-default/jest-preset.js +++ b/packages/jest-preset-default/jest-preset.js @@ -1,8 +1,6 @@ module.exports = { moduleNameMapper: { '\\.(scss|css)$': require.resolve( './scripts/style-mock.js' ), - // See https://github.com/facebook/jest/issues/11100#issuecomment-967161978 - '@eslint/eslintrc': '@eslint/eslintrc/dist/eslintrc-universal.cjs', }, modulePaths: [ '' ], setupFiles: [ require.resolve( './scripts/setup-globals.js' ) ], diff --git a/test/unit/scripts/resolver.js b/test/unit/scripts/resolver.js index 323001653532f3..275f81f27d56a5 100644 --- a/test/unit/scripts/resolver.js +++ b/test/unit/scripts/resolver.js @@ -21,7 +21,6 @@ module.exports = ( path, options ) => { if ( pkg.name === 'uuid' || pkg.name === 'react-colorful' || - pkg.name === '@eslint/eslintrc' || pkg.name === 'expect' || pkg.name === 'nanoid' || pkg.name?.startsWith( '@wordpress/' ) diff --git a/tools/eslint/lint-js.cjs b/tools/eslint/lint-js.cjs index 082512b4370cbf..da2c588ab6c096 100644 --- a/tools/eslint/lint-js.cjs +++ b/tools/eslint/lint-js.cjs @@ -20,6 +20,45 @@ const args = userArgs.some( ( arg ) => : [ '--suppressions-location', SUPPRESSIONS_FILE, ...userArgs ]; const wpScriptsBin = require.resolve( '@wordpress/scripts/bin/wp-scripts.js' ); +const FORMAT_FLAGS = [ '-f', '--format' ]; + +function resolveFormatter( name ) { + if ( + name.startsWith( '/' ) || + name.startsWith( './' ) || + name.startsWith( '../' ) || + /^[A-Za-z]:\\/.test( name ) + ) { + return name; + } + + for ( const candidate of [ name, `eslint-formatter-${ name }` ] ) { + try { + return require.resolve( candidate, { paths: [ __dirname ] } ); + } catch {} + } + + throw new Error( + `Formatter "${ name }" not found. Install the corresponding eslint-formatter- package in tools/eslint/ or use a built-in formatter (stylish, json, etc.).` + ); +} + +const childArgs = args.map( ( arg, index ) => { + if ( FORMAT_FLAGS.includes( args[ index - 1 ] ) ) { + return resolveFormatter( arg ); + } + + for ( const flag of FORMAT_FLAGS ) { + if ( arg.startsWith( `${ flag }=` ) ) { + return `${ flag }=${ resolveFormatter( + arg.slice( flag.length + 1 ) + ) }`; + } + } + + return arg; +} ); + // Detect stale suppressions by scanning the child's output for ESLint's // own `--prune-suppressions` hint. A small sliding tail buffer is used so // the child's output can be streamed straight to the user instead of being @@ -39,10 +78,14 @@ if ( childEnv.FORCE_COLOR = '1'; } -const child = spawn( process.execPath, [ wpScriptsBin, 'lint-js', ...args ], { - stdio: [ 'inherit', 'pipe', 'pipe' ], - env: childEnv, -} ); +const child = spawn( + process.execPath, + [ wpScriptsBin, 'lint-js', ...childArgs ], + { + stdio: [ 'inherit', 'pipe', 'pipe' ], + env: childEnv, + } +); child.stdout.on( 'data', handleChunk( process.stdout ) ); child.stderr.on( 'data', handleChunk( process.stderr ) ); diff --git a/tools/eslint/package.json b/tools/eslint/package.json index d46dea4b186f82..316a7ae811a4c7 100644 --- a/tools/eslint/package.json +++ b/tools/eslint/package.json @@ -30,6 +30,8 @@ "@eslint/js": "^10.0.0", "@wordpress/eslint-plugin": "file:../../packages/eslint-plugin", "@wordpress/scripts": "file:../../packages/scripts", + "eslint": "^10.0.0", + "eslint-formatter-compact": "^9.0.1", "eslint-import-resolver-typescript": "^4.4.4", "eslint-plugin-import": "^2.31.0", "eslint-plugin-jest": "^28.11.0",