Skip to content

Commit 00b32f2

Browse files
authoredAug 9, 2023
feat!: improve esm rules (#270)
1 parent fa17068 commit 00b32f2

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ These are the available configs:
4545
- `@bjerk/eslint-config/base`
4646
- `@bjerk/eslint-config/import`
4747
- `@bjerk/eslint-config/typescript`
48+
- `@bjerk/eslint-config/esm`
4849

4950
**Note**: The main `@bjerk/eslint-config` config includes all the others, but
5051
also `prettier` (and `eslint-config-prettier`).

‎esm.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require('@rushstack/eslint-patch/modern-module-resolution');
2+
3+
/**
4+
* @type {import('eslint').Linter.Config}
5+
**/
6+
const eslintConfigESM = {
7+
plugins: ['unicorn', 'import'],
8+
rules: {
9+
/**
10+
* Prefer using ESM over legacy CommonJS modules
11+
* @see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-module.md
12+
*/
13+
'unicorn/prefer-module': 'error',
14+
15+
/**
16+
* Prefer using the `node:` protocol when importing Node.js builtin modules
17+
* @see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-node-protocol.md
18+
*/
19+
'unicorn/prefer-node-protocol': 'error',
20+
21+
/**
22+
* Prefer top-level await over top-level promises and async function calls
23+
* @see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-top-level-await.md
24+
*/
25+
'unicorn/prefer-top-level-await': 'error',
26+
27+
'import/extensions': ['error', 'always', { ignorePackages: true }],
28+
'import/no-commonjs': 'error',
29+
},
30+
};
31+
32+
// eslint-disable-next-line no-undef
33+
module.exports = eslintConfigESM;

‎import.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
require('@rushstack/eslint-patch/modern-module-resolution');
22

3+
/**
4+
* @type {import('eslint').Linter.Config}
5+
**/
36
const eslintConfigImport = {
47
plugins: ['import'],
58
rules: {
@@ -22,6 +25,12 @@ const eslintConfigImport = {
2225
ignoreDeclarationSort: true,
2326
},
2427
],
28+
'import/no-useless-path-segments': [
29+
'error',
30+
{
31+
noUselessIndex: true,
32+
},
33+
],
2534
},
2635
overrides: [
2736
{

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require('@rushstack/eslint-patch/modern-module-resolution');
22

33
const eslintConfig = {
4-
extends: ['./base', './typescript', './import', 'prettier'],
4+
extends: ['./base', './typescript', './import', './esm', 'prettier'],
55
};
66

77
// eslint-disable-next-line no-undef

0 commit comments

Comments
 (0)
Please sign in to comment.