Skip to content

Commit cdc3511

Browse files
committed
feat(eslint): add support for ESLint v9
Update package.json to make eslint a peerDependency, so that the user has control over which version to pick. Move the existing eslint dependency to devDependencies so that tests work as expected. Introduce a new test to ensure the plugin works with ESLint v9. To do so without breaking v8 tests, install ESLint v9 under a different alias, and use an ESM import mocking library to override the "eslint" import. The current directory needs to be changed during the ESLint v9 test so that ESLint finds its config file properly. This requires ava workerThreads to be disabled: TypeError [ERR_WORKER_UNSUPPORTED_OPERATION]: process.chdir() is not supported in workers
1 parent feea7e5 commit cdc3511

File tree

3 files changed

+292
-15
lines changed

3 files changed

+292
-15
lines changed

packages/eslint/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"lint"
5555
],
5656
"peerDependencies": {
57+
"eslint": "^8.57.1||^9.0.0",
5758
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
5859
},
5960
"peerDependenciesMeta": {
@@ -62,18 +63,21 @@
6263
}
6364
},
6465
"dependencies": {
65-
"@rollup/pluginutils": "^5.0.1",
66-
"eslint": "^8.57.1"
66+
"@rollup/pluginutils": "^5.0.1"
6767
},
6868
"devDependencies": {
6969
"@rollup/plugin-node-resolve": "^15.0.0",
7070
"@rollup/plugin-typescript": "^9.0.1",
7171
"@types/eslint": "^8.56.12",
72+
"eslint": "^8.57.1",
73+
"eslint9": "npm:eslint@^9.37.0",
74+
"esmock": "^2.7.3",
7275
"rollup": "^4.0.0-24",
7376
"typescript": "^4.8.3"
7477
},
7578
"types": "./types/index.d.ts",
7679
"ava": {
80+
"workerThreads": false,
7781
"files": [
7882
"!**/fixtures/**",
7983
"!**/helpers/**",

packages/eslint/test/test.mjs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import fs from 'fs';
2-
32
import { createRequire } from 'module';
3+
import process from 'process';
4+
import path from 'path';
5+
import { fileURLToPath } from 'url';
46

7+
import eslint9 from 'eslint9';
8+
import esmock from 'esmock';
59
import test from 'ava';
610
import nodeResolve from '@rollup/plugin-node-resolve';
711
import { rollup } from 'rollup';
@@ -241,3 +245,36 @@ test('works with flat config', async (t) => {
241245

242246
t.is(count, 1);
243247
});
248+
249+
test.serial('works with ESLint v9', async (t) => {
250+
// Load the plugin with an override to route 'eslint' imports to ESLint v9
251+
const eslint = await esmock('current-package', {
252+
eslint: eslint9
253+
});
254+
255+
// ESLint v9 needs to be invoked with a flat config file in the current dir
256+
const cwd = process.cwd();
257+
const testDir = path.dirname(fileURLToPath(import.meta.url));
258+
process.chdir(path.join(testDir, 'fixtures', 'flat-config'));
259+
260+
let count = 0;
261+
try {
262+
await rollup({
263+
input: './undeclared.js',
264+
plugins: [
265+
eslint({
266+
formatter: (results) => {
267+
count += results[0].messages.length;
268+
// eslint-disable-next-line prefer-destructuring
269+
const { message } = results[0].messages[0];
270+
t.is(message, "'x' is not defined.");
271+
}
272+
})
273+
]
274+
});
275+
} finally {
276+
process.chdir(cwd);
277+
}
278+
279+
t.is(count, 1);
280+
});

0 commit comments

Comments
 (0)