Skip to content

Commit 5a975e4

Browse files
b3nk3Maximization
andauthored
Update ESLint to v9, and typescript-eslint to v8
* chore: bump peer dependency version * Update README.md * Upgrade to ESLint v9 - Update supported Node.js versions to conform to ESLint v9 - Replace eslint-config-node (unmaintaned) with eslint-config-n. Also move from peer dependency to dependency - Replace @typescript-eslint/parser & @typescript-eslint/eslint-plugin with typescript-eslint - Mark typescript as optional peer dependency - Merge index.js, node.js, and typescript.js into single file with named exports - Update Installation instructions for Non-TS and TS users - Add migration guide from v2 to v3 - Add ESLint & Node.js version requirements, and direct ESLint v8 users to v2 * Update package-lock.json --------- Co-authored-by: Maxim Orlov <[email protected]>
1 parent 2410515 commit 5a975e4

File tree

6 files changed

+1635
-5706
lines changed

6 files changed

+1635
-5706
lines changed

README.md

Lines changed: 122 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,75 +8,156 @@ Find an overview of what rules are enabled, and why, in this article:
88

99
## Table of contents
1010

11-
- [Installation & usage](#installation--usage)
11+
- [Table of contents](#table-of-contents)
12+
- [Requirements](#requirements)
13+
- [Installation \& usage](#installation--usage)
14+
- [Non-TypeScript users](#non-typescript-users)
15+
- [TypeScript users](#typescript-users)
16+
- [Migrating from v2 to v3](#migrating-from-v2-to-v3)
1217
- [Migrating from v1 to v2](#migrating-from-v1-to-v2)
1318

19+
## Requirements
20+
21+
- ESLint v9
22+
- Node.js ^18.18.0, ^20.9.0, or >=21.1.0 (set by ESLint v9)
23+
24+
If you're using ESLint v8, you should use v2 of this library. [Installation & usage for eslint-config-async v2](https://github.com/Maximization/eslint-config-async/blob/v2.0.3/README.md).
25+
1426
## Installation & usage
1527

16-
### Base rules
28+
### Non-TypeScript users
1729
Install this package and ESLint:
1830

1931
```shell
2032
npm install --save-dev eslint eslint-config-async
2133
```
2234

23-
In your `.eslintrc.js` configuration file:
35+
In your `eslint.config.js` configuration file:
2436

2537
```js
26-
module.exports = {
27-
extends: [
28-
'async'
29-
],
30-
};
38+
const asyncConfig = require("eslint-config-async");
39+
40+
module.exports = [
41+
...asyncConfig.base, // enable base rules
42+
...asyncConfig.node, // enable Node.js specific rules (recommended)
43+
];
3144
```
3245

33-
### Base rules + Node.js specific rules (recommended for non-TypeScript users)
46+
### TypeScript users
3447
Install this package and its peer dependencies:
3548

3649
```shell
37-
npm install --save-dev eslint eslint-config-async eslint-plugin-node
50+
npm install --save-dev eslint eslint-config-async typescript typescript-eslint
3851
```
3952

40-
In your `.eslintrc.js` configuration file:
53+
In your `eslint.config.js` configuration file:
4154

4255
```js
43-
module.exports = {
44-
plugins: [
45-
'eslint-plugin-node'
46-
],
47-
extends: [
48-
'async',
49-
'async/node'
50-
],
51-
};
56+
const tseslint = require("typescript-eslint");
57+
const asyncConfig = require("eslint-config-async");
58+
59+
module.exports = [
60+
// One of tseslint configs must be enabled
61+
// Either the base config
62+
tseslint.configs.base, // adds the parser only, without any rules
63+
// or
64+
...tseslint.configs.recommended, // includes base + a list of recommended rules
65+
// ..and others
66+
67+
...asyncConfig.base, // enable base rules
68+
...asyncConfig.node, // enable Node.js specific rules (recommended)
69+
...asyncConfig.typescript, // enable TypeScript specific rules
70+
{
71+
files: ["*.ts"], // tell ESLint to include TypeScript files
72+
languageOptions: {
73+
parserOptions: {
74+
projectService: true,
75+
tsconfigRootDir: import.meta.dirname,
76+
},
77+
},
78+
},
79+
];
5280
```
5381

54-
### Base rules + Node.js specific rules + TypeScript rules (recommended for TypeScript users)
55-
Install this package and its peer dependencies:
82+
## Migrating from v2 to v3
83+
84+
Version 3 upgrades ESLint to v9. ESLint uses a [flat configuration file](https://eslint.org/docs/latest/use/configure/configuration-files). `.eslintrc.*` has been deprecated and you should rename it to `eslint.config.js` (or .cjs, .mjs):
85+
86+
```diff
87+
- .eslintrc
88+
+ eslint.config.js
89+
```
90+
91+
In your `eslint.config.js` file, make the following changes:
92+
93+
```diff
94+
- module.exports = {
95+
- plugins: [
96+
- 'eslint-plugin-node'
97+
- ],
98+
- extends: [
99+
- 'async',
100+
- 'async/node'
101+
- ],
102+
- };
103+
+ const asyncConfig = require("eslint-config-async");
104+
+
105+
+ module.exports = [
106+
+ ...asyncConfig.base, // enable base rules
107+
+ ...asyncConfig.node, // enable Node.js specific rules (recommended)
108+
+ ];
109+
```
110+
111+
`eslint-plugin-node` is no longer maintained and has been replaced with its fork, `eslint-plugin-n`. `eslint-plugin-n` is not a peer dependency and is included with this library, therefore you no longer need to install it separately:
56112

57113
```shell
58-
npm install --save-dev eslint eslint-config-async eslint-plugin-node typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin
114+
npm remove --save-dev eslint-plugin-node
59115
```
60116

61-
In your `.eslintrc.js` configuration file:
117+
For TypeScript users, change the contents of `eslint.config.js` file as follows:
62118

63-
```js
64-
module.exports = {
65-
plugins: [
66-
'eslint-plugin-node',
67-
'@typescript-eslint'
68-
],
69-
extends: [
70-
'async',
71-
'async/node',
72-
'async/typescript'
73-
],
74-
parser: '@typescript-eslint/parser',
75-
parserOptions: {
76-
tsconfigRootDir: __dirname,
77-
project: ['./tsconfig.json'],
78-
}
79-
};
119+
```diff
120+
- module.exports = {
121+
- plugins: [
122+
- 'eslint-plugin-node',
123+
- '@typescript-eslint'
124+
- ],
125+
- extends: [
126+
- 'async',
127+
- 'async/node',
128+
- 'async/typescript'
129+
- ],
130+
- parser: '@typescript-eslint/parser',
131+
- parserOptions: {
132+
- tsconfigRootDir: __dirname,
133+
- project: ['./tsconfig.json'],
134+
- }
135+
- };
136+
137+
+ const tseslint = require("typescript-eslint");
138+
+ const asyncConfig = require("eslint-config-async");
139+
+
140+
+ module.exports = [
141+
+ tseslint.configs.base,
142+
+ ...asyncConfig.base, // enable base rules
143+
+ ...asyncConfig.node, // enable Node.js specific rules (recommended)
144+
+ ...asyncConfig.typescript, // enable TypeScript specific rules
145+
+ {
146+
+ files: ["*.ts"], // tell ESLint to include TypeScript files
147+
+ languageOptions: {
148+
+ parserOptions: {
149+
+ projectService: true,
150+
+ tsconfigRootDir: __dirname,
151+
+ },
152+
+ },
153+
+ },
154+
+ ];
155+
```
156+
157+
Replace `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin` with `typescript-eslint`:
158+
159+
```shell
160+
npm remove @typescript-eslint/parser @typescript-eslint/eslint-plugin && npm install --save-dev typescript-eslint
80161
```
81162

82163
## Migrating from v1 to v2

index.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
1+
const nodePlugin = require("eslint-plugin-n");
2+
13
module.exports = {
2-
rules: {
3-
// Base rules
4-
"no-async-promise-executor": "error",
5-
"no-await-in-loop": "error",
6-
"no-promise-executor-return": "error",
7-
"require-atomic-updates": "error",
8-
"max-nested-callbacks": ["error", 3],
9-
"no-return-await": "error",
10-
"prefer-promise-reject-errors": "error",
11-
},
4+
// Base rules
5+
base: [
6+
{
7+
rules: {
8+
"no-async-promise-executor": "error",
9+
"no-await-in-loop": "error",
10+
"no-promise-executor-return": "error",
11+
"require-atomic-updates": "error",
12+
"max-nested-callbacks": ["error", 3],
13+
"no-return-await": "error",
14+
"prefer-promise-reject-errors": "error",
15+
},
16+
},
17+
],
18+
19+
// Node.js rules
20+
node: [
21+
{
22+
plugins: { n: nodePlugin },
23+
rules: {
24+
"n/handle-callback-err": ["error", "^(e|err|error)$"],
25+
"n/no-callback-literal": "error",
26+
"n/no-sync": "error",
27+
},
28+
},
29+
],
30+
31+
// TypeScript rules
32+
typescript: [
33+
{
34+
rules: {
35+
"@typescript-eslint/await-thenable": "error",
36+
"@typescript-eslint/no-floating-promises": "error",
37+
"@typescript-eslint/no-misused-promises": "error",
38+
"@typescript-eslint/promise-function-async": "error",
39+
},
40+
},
41+
],
1242
};

node.js

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

0 commit comments

Comments
 (0)