Skip to content

Commit 51504d2

Browse files
authoredAug 5, 2022
Add new ESM-config (#131)
1 parent 26b9849 commit 51504d2

File tree

5 files changed

+53
-17
lines changed

5 files changed

+53
-17
lines changed
 

Diff for: ‎.github/workflows/external.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ jobs:
8484
- name: build project if needed
8585
run: npm run build-for-test --if-present
8686
working-directory: ./project
87-
- name: modify project eslint
87+
- name: modify project eslint config
8888
run: sed 's/"@voxpelli"/"..\/main\/test.eslintrc"/' .eslintrc > tmp.eslintrc && rm .eslintrc && mv tmp.eslintrc .eslintrc
8989
working-directory: ./project
90+
- name: modify project eslint config (ESM version)
91+
run: sed 's/"@voxpelli\/eslint-config\/esm"/"..\/main\/test-esm.eslintrc"/' .eslintrc > tmp.eslintrc && rm .eslintrc && mv tmp.eslintrc .eslintrc
92+
working-directory: ./project
9093
- name: run eslint
9194
run: ../main/node_modules/.bin/eslint --resolve-plugins-relative-to ../main --ext js --ext cjs --ext mjs --report-unused-disable-directives .
9295
working-directory: ./project

Diff for: ‎README.md

+30-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![npm version](https://img.shields.io/npm/v/@voxpelli/eslint-config.svg?style=flat)](https://www.npmjs.com/package/@voxpelli/eslint-config)
44
[![npm downloads](https://img.shields.io/npm/dm/@voxpelli/eslint-config.svg?style=flat)](https://www.npmjs.com/package/@voxpelli/eslint-config)
5-
[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg)](https://github.com/voxpelli/eslint-config)
5+
[![`js-semistandard-style`](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg)](https://github.com/voxpelli/eslint-config)
66
[![Follow @voxpelli](https://img.shields.io/twitter/follow/voxpelli?style=social)](https://twitter.com/voxpelli)
77

88
My personal ESLint config which extends [standard](https://standardjs.com/) / [semistandard](https://github.com/standard/semistandard) with a couple of extra checks that I find helpful in my projects.
@@ -15,19 +15,21 @@ This package follows [semantic versioning](https://semver.org/). Tightening of a
1515

1616
Absolutely, go ahead! I maintain this project as if multiple people are using it. Be sure to give me feedback and if you like it, give me a ping and say so, would make my day 😄
1717

18-
## Installation
18+
## Usage
1919

20-
Be sure to install versions of peer dependencies that are valid according to the peer dependency specification of this module.
20+
### Install
2121

22-
As ESLint configs and dependencies can and will change their rules with major releases you will likely get an incorrect ruleset otherwise.
22+
Be sure to install the correct versions of peer dependencies that this module requires, else you will likely get an incorrect rule setup.
2323

2424
To easily install all correct peer dependencies, you can use [`install-peerdeps`](https://www.npmjs.com/package/install-peerdeps):
2525

2626
```bash
2727
install-peerdeps --dev @voxpelli/eslint-config
2828
```
2929

30-
Then add a `.eslintrc` with the following:
30+
### Configure
31+
32+
Add an `.eslintrc`, or other [ESLint configuration](https://eslint.org/docs/latest/user-guide/configuring/configuration-files), that extends this config:
3133

3234
```
3335
{
@@ -36,6 +38,12 @@ Then add a `.eslintrc` with the following:
3638
}
3739
```
3840

41+
### Configure, ESM
42+
43+
Instead of simply extending `@voxpelli` you can extend `@voxpelli/eslint-config/esm` and get a version of the rules that enforces ESM best practices as well.
44+
45+
###
46+
3947
## How does this differ from pure [standard](https://standardjs.com/)?
4048

4149
* :stop_sign: = changed to `error` level
@@ -96,7 +104,7 @@ Then add a `.eslintrc` with the following:
96104
* :mute: [`unicorn/numeric-separators-style`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/numeric-separators-style.md)*deactivated* – currently not enough good support for this in engines
97105
* :warning: [`unicorn/prefer-add-event-listener`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-add-event-listener.md)*changed* – set to `warn` instead of `error`
98106
* :warning: [`unicorn/prefer-event-target`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules//prefer-event-target.md)*changed* – set to `warn` instead of `error`
99-
* :warning: [`unicorn/prefer-module`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-module.md)*changed*set to `warn` instead of `error`
107+
* :mute: [`unicorn/prefer-module`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-module.md)*deactivated*only useful when you know you're targetting ESM
100108
* :warning: [`unicorn/prefer-spread`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-spread.md)*changed* – set to `warn` instead of `error`
101109
* :mute: [`unicorn/prevent-abbreviations`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prevent-abbreviations.md)*deactivated* – same as `unicorn/catch-error-name`, I prefer an abbreviated `err` over a non-abbreviated `error`because the latter is too similar to `Error` for my taste
102110

@@ -116,14 +124,24 @@ Then add a `.eslintrc` with the following:
116124

117125
* :stop_sign: [`sort-destructure-keys/sort-destructure-keys`](https://github.com/mthadley/eslint-plugin-sort-destructure-keys)
118126

127+
## Extended ESM config
128+
129+
By extending `@voxpelli/eslint-config/esm` instead of `@voxpelli` you will get these differences:
130+
131+
#### :wrench: Overrides of rules
132+
133+
* :warning: [`func-style`](https://eslint.org/docs/rules/func-style) – enforces function declarations whenever an arrow function isn't used. Better to do `export function foo () {` than `export const foo = function () {`
134+
* :stop_sign: [`unicorn/prefer-module`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-module.md)*changed* – restored to its `plugin:unicorn/recommended` value of `error`
135+
136+
119137
## Alternatives
120138

121-
* [eslint-config-rainbow](https://github.com/rainbow-me/eslint-config-rainbow) by [@bcomnes](https://github.com/bcomnes)
122-
* [semistandard](https://github.com/standard/semistandard)
123-
* [standard](https://standardjs.com/)
139+
* [`eslint-config-rainbow`](https://github.com/rainbow-me/eslint-config-rainbow) by [@bcomnes](https://github.com/bcomnes)
140+
* [`semistandard`](https://github.com/standard/semistandard)
141+
* [`standard`](https://standardjs.com/)
124142

125143
## See also
126144

127-
* [voxpelli/ghatemplates](https://github.com/voxpelli/ghatemplates) – the templates I use with [`ghat`](https://github.com/fregante/ghat) to update GitHub Actions in my projects
128-
* [voxpelli/renovate-config-voxpelli](https://github.com/voxpelli/renovate-config-voxpelli) – the shareable [Renovate setup](https://docs.renovatebot.com/config-presets/) I use in my projects
129-
* [voxpelli/tsconfig](https://github.com/voxpelli/tsconfig) – the shareable `tsconfig.json` setup I use in my projects
145+
* [`voxpelli/ghatemplates`](https://github.com/voxpelli/ghatemplates) – the templates I use with [`ghat`](https://github.com/fregante/ghat) to update GitHub Actions in my projects
146+
* [`voxpelli/renovate-config-voxpelli`](https://github.com/voxpelli/renovate-config-voxpelli) – the shareable [Renovate setup](https://docs.renovatebot.com/config-presets/) I use in my projects
147+
* [`voxpelli/tsconfig`](https://github.com/voxpelli/tsconfig) – the shareable `tsconfig.json` setup I use in my projects

Diff for: ‎esm.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
module.exports = {
4+
'extends': [
5+
'./'
6+
],
7+
root: true,
8+
rules: {
9+
// Overrides of @voxpelli rules
10+
'func-style': ['warn', 'declaration', { 'allowArrowFunctions': true }],
11+
'unicorn/prefer-module': 'error',
12+
}
13+
};

Diff for: ‎index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable unicorn/prefer-module */
2-
31
'use strict';
42

53
module.exports = {
@@ -81,13 +79,13 @@ module.exports = {
8179
'security/detect-object-injection': 'off',
8280
'security/detect-unsafe-regex': 'off',
8381

84-
'unicorn/catch-error-name': ['error', { 'name': 'err' }],
82+
'unicorn/catch-error-name': ['error', { name: 'err', ignore: ['^cause$'] }],
8583
'unicorn/explicit-length-check': 'off',
8684
'unicorn/no-await-expression-member': 'warn',
8785
'unicorn/numeric-separators-style': 'off',
8886
'unicorn/prefer-add-event-listener': 'warn',
8987
'unicorn/prefer-event-target': 'warn',
90-
'unicorn/prefer-module': 'warn',
88+
'unicorn/prefer-module': 'off',
9189
'unicorn/prefer-spread': 'warn',
9290
'unicorn/prevent-abbreviations': 'off',
9391

Diff for: ‎test-esm.eslintrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": ["./esm"],
3+
"root": true
4+
}

0 commit comments

Comments
 (0)