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(eslint): supports eslint v9 #1729

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"codecov-lite": "2.0.0",
"conventional-commits-parser": "^3.2.1",
"del-cli": "^5.0.0",
"eslint": "^8.57.0",
"eslint-config-rollup": "^3.0.1",
"esm": "^3.2.25",
"execa": "^5.1.1",
Expand Down
10 changes: 8 additions & 2 deletions packages/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,27 @@
"lint"
],
"peerDependencies": {
"eslint": "^7.12.0||^8.0.0||^9.0.0",
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
},
"eslint": {
"optional": true
}
},
"dependencies": {
"@rollup/pluginutils": "^5.0.1",
"eslint": "^8.24.0"
"eslint": "^9.5.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-typescript": "^9.0.1",
"@types/eslint": "^8.4.6",
"@types/eslint": "^8.56.10",
"rollup": "^4.0.0-24",
"typescript": "^4.8.3"
},
Expand Down
87 changes: 64 additions & 23 deletions packages/eslint/test/test.mjs → packages/eslint/test/legacy.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,74 @@
import fs from 'fs';

import { createRequire } from 'module';

import { resolve } from 'path';

import test from 'ava';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import { rollup } from 'rollup';

import eslint from 'current-package';
import rollupConfig from '../rollup.config.mjs';

const require = createRequire(import.meta.url);
const __dirname = new URL('.', import.meta.url).pathname;
/**
* @type {import('current-package').default}
*/
let eslint;

test.before('bundle @rollup/plugin-eslint for legacy eslint tests', async () => {
const workspaceRoot = resolve(__dirname, '../../../');
const workspaceEslintPath = resolve(workspaceRoot, 'node_modules/eslint');
const { main, devDependencies, dependencies } = JSON.parse(fs.readFileSync(resolve(workspaceEslintPath, 'package.json'), 'utf8'));
const workspaceEslintEntry = resolve(workspaceEslintPath, main)
await rollup({
...rollupConfig,
external: (rollupConfig.external ?? []).filter((id) => id !== 'eslint'),
plugins: [
...(rollupConfig.plugins ?? []),
json(),
nodeResolve({
// glob v7 causes a circular dependency error
resolveOnly: [
...Object.keys(devDependencies ?? {}).filter((id) => id !== 'glob'),
...Object.keys(dependencies ?? {}).filter((id) => id !== 'glob')
]
}),
commonjs(),
{
name: 'resolve-eslint',
// to bundle eslint v8
resolveId(id) {
if (id === 'eslint') {
return workspaceEslintEntry;
}
}
},
{
name: 'hack-commonjs-dynamic-require',
// a hack solution for dynamic requiring eslint formatters
footer: `
function commonjsRequire(path) {
path = path.replace(/^\\/test/, '')
return require(resolve(${JSON.stringify(workspaceEslintPath)}, path))
}
`
}
]
})
.then((b) => b.write({ format: 'cjs', sourcemap: true, file: resolve(__dirname, 'temp.js') }))
eslint = require(resolve(__dirname, 'temp.js'))
});

test.after.always('cleanup', async () => {
[resolve(__dirname, 'temp.js'), resolve(__dirname, 'temp.js.map')].forEach((file) => {
if (fs.existsSync(file)) {
fs.unlinkSync(file);
}
})
});

test('should lint files', async (t) => {
let count = 0;
Expand Down Expand Up @@ -201,24 +263,3 @@ test('should fix source code', async (t) => {

fs.unlinkSync('./test/fixtures/fixable-clone.js');
});

test('works with cjs plugin', async (t) => {
const require = createRequire(import.meta.url);
const eslintPluginCjs = require('current-package');
let count = 0;
await rollup({
input: './test/fixtures/undeclared.js',
plugins: [
eslintPluginCjs({
formatter: (results) => {
count += results[0].messages.length;
// eslint-disable-next-line prefer-destructuring
const { message } = results[0].messages[0];
t.is(message, "'x' is not defined.");
}
})
]
});

t.is(count, 1);
});
Loading
Loading