Skip to content

Commit 5aa6de6

Browse files
committed
Migrate to eslint v9
1 parent d3d5e6a commit 5aa6de6

17 files changed

+594
-425
lines changed

.eslintrc.js

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

.github/workflows/CD.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Checkout
1313
uses: actions/checkout@v4
1414
- name: Install Node.js
15-
uses: actions/setup-node@v3
15+
uses: actions/setup-node@v4
1616
with:
1717
node-version: 18.x
1818
registry-url: "https://registry.npmjs.org"

.github/workflows/CI.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Checkout
1717
uses: actions/checkout@v4
1818
- name: Install Node.js
19-
uses: actions/setup-node@v3
19+
uses: actions/setup-node@v4
2020
with: { node-version: 18.x }
2121
- name: Install Packages
2222
run: npm ci
@@ -28,28 +28,38 @@ jobs:
2828

2929
strategy:
3030
matrix:
31-
eslint: [8.x]
31+
eslint: [9.x]
32+
typescript-eslint: [8.x]
3233
node: [20.x]
3334
os: [ubuntu-latest]
3435
include:
3536
# On other platforms
36-
- eslint: 8.x
37+
- eslint: 9.x
38+
typescript-eslint: [8.x]
3739
node: 20.x
3840
os: windows-latest
39-
- eslint: 8.x
41+
- eslint: 9.x
42+
typescript-eslint: [8.x]
4043
node: 20.x
4144
os: macos-latest
4245
# On old Node.js versions
4346
- eslint: 8.x
47+
typescript-eslint: [6.x]
4448
node: 18.x
4549
os: ubuntu-latest
4650
- eslint: 8.x
51+
typescript-eslint: [6.x]
4752
node: 16.x
4853
os: ubuntu-latest
49-
# On old ESLint versions
54+
# Other ESLint versions
5055
- eslint: 7.x
56+
typescript-eslint: [6.x]
5157
node: 18.x
5258
os: ubuntu-latest
59+
- eslint: 8.x
60+
typescript-eslint: [6.x]
61+
node: 20.x
62+
os: ubuntu-latest
5363

5464
runs-on: ${{ matrix.os }}
5565
steps:
@@ -60,10 +70,10 @@ jobs:
6070
with: { node-version: "${{ matrix.node }}" }
6171
- name: Install Packages
6272
run: npm install
63-
- name: Install ESLint ${{ matrix.eslint }}
64-
run: npm install --no-save eslint@${{ matrix.eslint }}
73+
- name: Install ESLint ${{ matrix.eslint }} and TypeScript-ESLint ${{ matrix.typescript-eslint }}
74+
run: npm install --force --no-save eslint@${{ matrix.eslint }} @typescript-eslint/eslint-plugin@${{ matrix.typescript-eslint }}
6575
- name: Test
66-
run: npm run -s test:ci -- --reporter json --reporter-options output=reports/tests.json
76+
run: npm run -s test:ci:${{ matrix.eslint }} -- --reporter json --reporter-options output=reports/tests.json
6777
- name: Test Report
6878
uses: dorny/test-reporter@v1
6979
if: success() || failure()

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,49 @@ $ npm install -D @dprint/typescript
3838

3939
Write your ESLint configuration. For example with typescript code:
4040

41+
From eslint v9 (flat configuration)
42+
43+
```mjs
44+
import tsPlugin from "@typescript-eslint/eslint-plugin";
45+
import tsParser from "@typescript-eslint/parser";
46+
import dprint from "@ben_12/eslint-plugin-dprint";
47+
48+
module.exports = {
49+
files: ["**/*.ts", "**/*.js"],
50+
51+
languageOptions: {
52+
parser: tsParser
53+
},
54+
55+
plugins: {
56+
"@typescript-eslint": tsPlugin,
57+
"@ben_12/dprint": dprint,
58+
},
59+
60+
rules: {
61+
...tsPlugin.configs["eslint-recommended"].rules,
62+
...tsPlugin.configs["recommended"].rules,
63+
...tsPlugin.configs["strict"].rules,
64+
...dprint.configs["typescript-recommended"].rules
65+
"@ben_12/dprint/typescript": [
66+
"error",
67+
{
68+
// Use dprint JSON configuration file (default: "dprint.json")
69+
// It may be created using `dprint init` command
70+
// See also https://dprint.dev/config/
71+
configFile: "dprint.json",
72+
config: {
73+
// The TypeScript configuration of dprint
74+
// See also https://dprint.dev/plugins/typescript/config/
75+
},
76+
},
77+
],
78+
},
79+
};
80+
```
81+
82+
For old eslint (eslintrc configuration)
83+
4184
```js
4285
module.exports = {
4386
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:@ben_12/dprint/typescript-recommended"],

eslint.config.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import tsPlugin from "@typescript-eslint/eslint-plugin";
2+
import tsParser from "@typescript-eslint/parser";
3+
import simpleParser from "@ben_12/eslint-simple-parser";
4+
import dprint from "@ben_12/eslint-plugin-dprint";
5+
6+
7+
export default [{
8+
ignores: ["**/.eslintrc.js", ".nyc_output", "coverage", "dist"],
9+
}, {
10+
files: ["**/*.ts", "**/*.js"],
11+
12+
plugins: {
13+
"@typescript-eslint": tsPlugin,
14+
"@ben_12/dprint": dprint,
15+
},
16+
17+
languageOptions: {
18+
parser: tsParser,
19+
ecmaVersion: 5,
20+
sourceType: "module",
21+
},
22+
23+
rules: {
24+
...tsPlugin.configs["eslint-recommended"].rules,
25+
...tsPlugin.configs["recommended"].rules,
26+
...tsPlugin.configs["strict"].rules,
27+
...dprint.configs["typescript-recommended"].rules
28+
}
29+
}, {
30+
files: ["**/*.md"],
31+
32+
plugins: {
33+
"@ben_12/dprint": dprint,
34+
},
35+
36+
languageOptions: {
37+
parser: simpleParser,
38+
},
39+
40+
rules: dprint.configs["markdown-recommended"].rules
41+
42+
}];

lib/dprint/dprint.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-var-requires */
1+
/* eslint-disable @typescript-eslint/no-require-imports */
22

33
import { createFromBuffer, Formatter } from "@dprint/formatter"
44
import * as fs from "fs"
@@ -35,7 +35,8 @@ for (const module of plugins) {
3535
const formatter = createFromBuffer(buffer)
3636
formatters.push(formatter)
3737
}
38-
} catch (e) {
38+
} // eslint-disable-next-line @typescript-eslint/no-unused-vars
39+
catch (e) {
3940
// plugin unavailable
4041
}
4142
}

0 commit comments

Comments
 (0)