Skip to content

Commit

Permalink
Migrate to eslint v9
Browse files Browse the repository at this point in the history
  • Loading branch information
ben12 committed Dec 1, 2024
1 parent d3d5e6a commit 5aa6de6
Show file tree
Hide file tree
Showing 17 changed files with 594 additions and 425 deletions.
30 changes: 0 additions & 30 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18.x
registry-url: "https://registry.npmjs.org"
Expand Down
26 changes: 18 additions & 8 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with: { node-version: 18.x }
- name: Install Packages
run: npm ci
Expand All @@ -28,28 +28,38 @@ jobs:

strategy:
matrix:
eslint: [8.x]
eslint: [9.x]
typescript-eslint: [8.x]
node: [20.x]
os: [ubuntu-latest]
include:
# On other platforms
- eslint: 8.x
- eslint: 9.x
typescript-eslint: [8.x]
node: 20.x
os: windows-latest
- eslint: 8.x
- eslint: 9.x
typescript-eslint: [8.x]
node: 20.x
os: macos-latest
# On old Node.js versions
- eslint: 8.x
typescript-eslint: [6.x]
node: 18.x
os: ubuntu-latest
- eslint: 8.x
typescript-eslint: [6.x]
node: 16.x
os: ubuntu-latest
# On old ESLint versions
# Other ESLint versions
- eslint: 7.x
typescript-eslint: [6.x]
node: 18.x
os: ubuntu-latest
- eslint: 8.x
typescript-eslint: [6.x]
node: 20.x
os: ubuntu-latest

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -60,10 +70,10 @@ jobs:
with: { node-version: "${{ matrix.node }}" }
- name: Install Packages
run: npm install
- name: Install ESLint ${{ matrix.eslint }}
run: npm install --no-save eslint@${{ matrix.eslint }}
- name: Install ESLint ${{ matrix.eslint }} and TypeScript-ESLint ${{ matrix.typescript-eslint }}
run: npm install --force --no-save eslint@${{ matrix.eslint }} @typescript-eslint/eslint-plugin@${{ matrix.typescript-eslint }}
- name: Test
run: npm run -s test:ci -- --reporter json --reporter-options output=reports/tests.json
run: npm run -s test:ci:${{ matrix.eslint }} -- --reporter json --reporter-options output=reports/tests.json
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
Expand Down
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,49 @@ $ npm install -D @dprint/typescript

Write your ESLint configuration. For example with typescript code:

From eslint v9 (flat configuration)

```mjs
import tsPlugin from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import dprint from "@ben_12/eslint-plugin-dprint";

module.exports = {
files: ["**/*.ts", "**/*.js"],

languageOptions: {
parser: tsParser
},

plugins: {
"@typescript-eslint": tsPlugin,
"@ben_12/dprint": dprint,
},

rules: {
...tsPlugin.configs["eslint-recommended"].rules,
...tsPlugin.configs["recommended"].rules,
...tsPlugin.configs["strict"].rules,
...dprint.configs["typescript-recommended"].rules
"@ben_12/dprint/typescript": [
"error",
{
// Use dprint JSON configuration file (default: "dprint.json")
// It may be created using `dprint init` command
// See also https://dprint.dev/config/
configFile: "dprint.json",
config: {
// The TypeScript configuration of dprint
// See also https://dprint.dev/plugins/typescript/config/
},
},
],
},
};
```

For old eslint (eslintrc configuration)

```js
module.exports = {
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:@ben_12/dprint/typescript-recommended"],
Expand Down
42 changes: 42 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import tsPlugin from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import simpleParser from "@ben_12/eslint-simple-parser";
import dprint from "@ben_12/eslint-plugin-dprint";


export default [{
ignores: ["**/.eslintrc.js", ".nyc_output", "coverage", "dist"],
}, {
files: ["**/*.ts", "**/*.js"],

plugins: {
"@typescript-eslint": tsPlugin,
"@ben_12/dprint": dprint,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: "module",
},

rules: {
...tsPlugin.configs["eslint-recommended"].rules,
...tsPlugin.configs["recommended"].rules,
...tsPlugin.configs["strict"].rules,
...dprint.configs["typescript-recommended"].rules
}
}, {
files: ["**/*.md"],

plugins: {
"@ben_12/dprint": dprint,
},

languageOptions: {
parser: simpleParser,
},

rules: dprint.configs["markdown-recommended"].rules

}];
5 changes: 3 additions & 2 deletions lib/dprint/dprint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */

import { createFromBuffer, Formatter } from "@dprint/formatter"
import * as fs from "fs"
Expand Down Expand Up @@ -35,7 +35,8 @@ for (const module of plugins) {
const formatter = createFromBuffer(buffer)
formatters.push(formatter)
}
} catch (e) {
} // eslint-disable-next-line @typescript-eslint/no-unused-vars
catch (e) {
// plugin unavailable
}
}
Expand Down
Loading

0 comments on commit 5aa6de6

Please sign in to comment.