Skip to content

Commit

Permalink
add support for eslint-9
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Nov 1, 2024
1 parent 3fe3523 commit a3cf4d4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ jobs:
eslint-version:
- 7
- 8
- 9
node-version:
- 14
- 16
- 18
- 20
exclude:
# eslint@9 requires node 18+
- eslint-version: 9
node-version: 14
- eslint-version: 9
node-version: 16

steps:
- uses: actions/checkout@v4
Expand Down
9 changes: 7 additions & 2 deletions lib/ignore-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ module.exports = async function ignoreAll(cwd = process.cwd()) {

const eslint = importCwd('eslint');

if (semver.intersects(eslintVersion, '8')) {
if (
semver.intersects(eslintVersion, '8') ||
semver.intersects(eslintVersion, '9')
) {
// this won't use the version in the repo but it will still use v8 because
// that is installed in this repo
const { ESLint } = eslint;
cli = new ESLint();
cli = new ESLint({
cwd,
});
results = await cli.lintFiles([cwd]);

// remove warnings
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/eslint-parser": "^7.19.1",
"@eslint/js": "^9.13.0",
"chai": "^4.3.4",
"eslint": "^8.0.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
22 changes: 15 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/ignore.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ async function ignoreTestFile(input, files) {
const project = new Project({
files: {
'.eslintrc.json': '{"extends": "eslint:recommended"}',
//only for eslint 9
'eslint.config.js': `const js = require("@eslint/js");
module.exports = [
js.configs.recommended,
];`,
'index.js': input,
'package.json': `{
"devDependencies": {
Expand All @@ -20,6 +26,7 @@ async function ignoreTestFile(input, files) {
});

project.linkDevDependency('eslint', { baseDir: process.cwd() });
project.linkDevDependency('@eslint/js', { baseDir: process.cwd() });
await project.write();
await ignoreAll(project.baseDir);

Expand Down Expand Up @@ -82,6 +89,13 @@ if (10 === 'false') {
{
'.eslintrc.json':
'{"extends": "eslint:recommended", "rules": { "no-constant-condition": "warn" }}',
//only for eslint 9
'eslint.config.js': `const js = require("@eslint/js");
module.exports = [
js.configs.recommended,
{ rules: { "no-constant-condition": "warn" }}
];`,
},
),
).to.equal(`/* eslint-disable no-debugger */
Expand Down

0 comments on commit a3cf4d4

Please sign in to comment.