Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: improve esm rules #270

Merged
merged 4 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ These are the available configs:
- `@bjerk/eslint-config/base`
- `@bjerk/eslint-config/import`
- `@bjerk/eslint-config/typescript`
- `@bjerk/eslint-config/esm`

**Note**: The main `@bjerk/eslint-config` config includes all the others, but
also `prettier` (and `eslint-config-prettier`).
Expand Down
33 changes: 33 additions & 0 deletions esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require('@rushstack/eslint-patch/modern-module-resolution');

/**
* @type {import('eslint').Linter.Config}
**/
const eslintConfigESM = {
plugins: ['unicorn', 'import'],
rules: {
/**
* Prefer using ESM over legacy CommonJS modules
* @see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-module.md
*/
'unicorn/prefer-module': 'error',

/**
* Prefer using the `node:` protocol when importing Node.js builtin modules
* @see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-node-protocol.md
*/
'unicorn/prefer-node-protocol': 'error',

/**
* Prefer top-level await over top-level promises and async function calls
* @see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-top-level-await.md
*/
'unicorn/prefer-top-level-await': 'error',

'import/extensions': ['error', 'always', { ignorePackages: true }],
'import/no-commonjs': 'error',
},
};

// eslint-disable-next-line no-undef
module.exports = eslintConfigESM;
9 changes: 9 additions & 0 deletions import.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require('@rushstack/eslint-patch/modern-module-resolution');

/**
* @type {import('eslint').Linter.Config}
**/
const eslintConfigImport = {
plugins: ['import'],
rules: {
Expand All @@ -22,6 +25,12 @@ const eslintConfigImport = {
ignoreDeclarationSort: true,
},
],
'import/no-useless-path-segments': [
'error',
{
noUselessIndex: true,
},
],
},
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('@rushstack/eslint-patch/modern-module-resolution');

const eslintConfig = {
extends: ['./base', './typescript', './import', 'prettier'],
extends: ['./base', './typescript', './import', './esm', 'prettier'],
};

// eslint-disable-next-line no-undef
Expand Down