Skip to content

Commit c44ea26

Browse files
committed
Move to ESM and flat config
Fixes #2278
1 parent 452c299 commit c44ea26

File tree

709 files changed

+1865
-2242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

709 files changed

+1865
-2242
lines changed

.eslint-doc-generatorrc.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
/** @type {import('eslint-doc-generator').GenerateOptions} */
44
const config = {
5-
ignoreConfig: ['all', 'flat/all', 'flat/recommended'],
6-
ignoreDeprecatedRules: true,
7-
ruleDocTitleFormat: 'desc',
8-
ruleListColumns: [
9-
'name',
10-
'description',
11-
'configsError',
12-
// Omit `configsOff` since we don't intend to convey meaning by setting rules to `off` in the `recommended` config.
13-
'configsWarn',
14-
'fixable',
15-
'hasSuggestions',
16-
'requiresTypeChecking',
17-
],
18-
urlConfigs: 'https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs-eslintconfigjs',
5+
ignoreConfig: [
6+
'all',
7+
'flat/all',
8+
'flat/recommended',
9+
],
10+
ignoreDeprecatedRules: true,
11+
ruleDocTitleFormat: 'desc',
12+
ruleListColumns: [
13+
'name',
14+
'description',
15+
'configsError',
16+
// Omit `configsOff` since we don't intend to convey meaning by setting rules to `off` in the `recommended` config.
17+
'configsWarn',
18+
'fixable',
19+
'hasSuggestions',
20+
'requiresTypeChecking',
21+
],
22+
urlConfigs: 'https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs-eslintconfigjs',
1923
};
2024

21-
module.exports = config;
25+
export default config;

.github/workflows/main.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
node-version:
18-
- 20
19-
- 18
18+
- 23
2019
os:
2120
- ubuntu-latest
2221
- windows-latest
@@ -43,7 +42,7 @@ jobs:
4342
- uses: actions/setup-node@v4
4443
with:
4544
# Locked due to the difference of `zlib.gzipSync()` between Node.js versions
46-
node-version: 20
45+
node-version: 23
4746
- run: npm install
4847
- run: npm run lint
4948
- run: npx del-cli test/snapshots --verbose
@@ -62,6 +61,8 @@ jobs:
6261
steps:
6362
- uses: actions/checkout@v4
6463
- uses: actions/setup-node@v4
64+
with:
65+
node-version: 23
6566
- run: npm install
6667
- run: npm run run-rules-on-codebase
6768
integration:
@@ -85,5 +86,7 @@ jobs:
8586
steps:
8687
- uses: actions/checkout@v4
8788
- uses: actions/setup-node@v4
89+
with:
90+
node-version: 23
8891
- run: npm install
8992
- run: npm run integration -- --group ${{ matrix.group }}

configs/flat-config-base.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
'use strict';
2-
const globals = require('globals');
1+
import globals from 'globals';
32

4-
module.exports = {
3+
const config = {
54
languageOptions: {
65
globals: globals.builtin,
76
},
87
};
8+
9+
export default config;

configs/legacy-config-base.js

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

docs/new-rule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Use the [`astexplorer` site](https://astexplorer.net) with the `espree` parser a
1313
## Steps
1414

1515
- Run `npm run create-rule` to create files for the new rule.
16-
- Open “test/{RULE_ID}.mjs” and [write some tests](./write-tests.md) before implementing the rule.
16+
- Open “test/{RULE_ID}.js” and [write some tests](./write-tests.md) before implementing the rule.
1717
- Open “rules/{RULE_ID}.js” and implement the rule logic.
1818
- Add the correct [`meta.type`](https://eslint.org/docs/developer-guide/working-with-rules#rule-basics) to the rule.
1919
- Open “docs/rules/{RULE_ID}.js” and write some documentation.

docs/rules/no-array-callback-reference.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ Passing functions to iterator methods can cause issues when the function is chan
1212
Suppose you have a `unicorn` module:
1313

1414
```js
15-
module.exports = x => x + 1;
15+
const unicorn = x => x + 1;
16+
17+
export default unicorn;
1618
```
1719

1820
You can then use it like this:
1921

2022
```js
21-
const unicorn = require('unicorn');
23+
import unicorn from 'unicorn';
2224

2325
[1, 2, 3].map(unicorn);
2426
//=> [2, 3, 4]
@@ -27,13 +29,15 @@ const unicorn = require('unicorn');
2729
The `unicorn` module now does a minor version that adds another argument:
2830

2931
```js
30-
module.exports = (x, y) => x + (y ? y : 1);
32+
const unicorn = (x, y) => x + (y ? y : 1);
33+
34+
export default unicorn;
3135
```
3236

3337
Your code will now return something different and probably break for users because it is now passing the index of the item as second argument.
3438

3539
```js
36-
const unicorn = require('unicorn');
40+
import unicorn from 'unicorn';
3741

3842
[1, 2, 3].map(unicorn);
3943
//=> [2, 3, 5]
@@ -42,7 +46,7 @@ const unicorn = require('unicorn');
4246
This rule helps safely call the function with the expected number of parameters:
4347

4448
```js
45-
const unicorn = require('unicorn');
49+
import unicorn from 'unicorn';
4650

4751
[1, 2, 3].map(x => unicorn(x));
4852
//=> [2, 3, 4]

docs/rules/no-unnecessary-polyfills.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ package.json
2626
```
2727

2828
```js
29-
const assign = require('object-assign');
29+
import assign from 'object-assign';
3030
```
3131

3232
## Pass
@@ -42,7 +42,7 @@ package.json
4242
```
4343

4444
```js
45-
const assign = require('object-assign'); // Passes as Object.assign is not supported
45+
import assign from 'object-assign'; // Passes as Object.assign is not supported
4646
```
4747

4848
## Options

docs/rules/prefer-add-event-listener.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ This option lets you specify a list of packages that disable the rule when impor
6969
With `koa`, this would still pass:
7070

7171
```js
72-
const Koa = require('koa');
72+
import Koa from 'koa';
73+
7374
const app = new Koa();
7475

7576
app.onerror = () => {};

docs/rules/prefer-node-protocol.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99

1010
When importing builtin modules, it's better to use the [`node:` protocol](https://nodejs.org/api/esm.html#node-imports) as it makes it perfectly clear that the package is a Node.js builtin module.
1111

12-
Note that Node.js support for this feature began in:
13-
14-
> v16.0.0, v14.18.0 (`require()`)
15-
>
16-
> v14.13.1, v12.20.0 (`import`)
17-
1812
## Fail
1913

2014
```js
@@ -29,14 +23,6 @@ export {strict as default} from 'assert';
2923
import fs from 'fs/promises';
3024
```
3125

32-
```js
33-
const fs = require('fs');
34-
```
35-
36-
```js
37-
const fs = require('fs/promises');
38-
```
39-
4026
## Pass
4127

4228
```js
@@ -58,7 +44,3 @@ import _ from 'lodash';
5844
```js
5945
import fs from './fs.js';
6046
```
61-
62-
```js
63-
const fs = require('node:fs/promises');
64-
```

docs/rules/prevent-abbreviations.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,6 @@ import tempWrite from 'temp-write';
188188
import * as err from 'err';
189189
```
190190

191-
```js
192-
const err = require('err');
193-
```
194-
195191
### checkShorthandImports
196192

197193
Type: `'internal'` | `boolean`\
@@ -222,10 +218,6 @@ Pass `"checkShorthandProperties": true` to check variables declared as shorthand
222218

223219
With this set to `true` the following code will be reported.
224220

225-
```js
226-
const {prop} = require('ramda');
227-
```
228-
229221
```js
230222
const {err} = foo;
231223
```

0 commit comments

Comments
 (0)