@hexadrop/eslint-config 0.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +290 -0
- package/dist/index.cjs +1955 -0
- package/dist/index.d.cts +10819 -0
- package/dist/index.d.ts +10819 -0
- package/dist/index.js +1918 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-2023 hexadrop
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
hexadrop's ESLint configuration
|
|
3
|
+
</h1>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
Opinionated ESLint ruleset designed for large teams and projects considering modern JavaScript best practices and
|
|
7
|
+
providing consistency to your code.
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install --save-dev eslint @hexadrop/eslint-config
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Using bun**
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
bun add eslint @hexadrop/eslint-config --dev
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> [!IMPORTANT]
|
|
23
|
+
> Since v4.0.0, this config is rewritten to the
|
|
24
|
+
> new [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new).
|
|
25
|
+
|
|
26
|
+
## What it does
|
|
27
|
+
|
|
28
|
+
- Auto fix for formatting (aimed to be used standalone **without** Prettier)
|
|
29
|
+
- Respects .gitignore by default
|
|
30
|
+
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
31
|
+
- Sorted imports, dangling commas
|
|
32
|
+
- Single quotes, use of semicolons
|
|
33
|
+
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
34
|
+
- Opinionated, but [very customizable](#customization)
|
|
35
|
+
- Reasonable defaults, best practices, only one line of config
|
|
36
|
+
- Designed to work with TypeScript, JSX, JSON, Markdown, etc. Out-of-box.
|
|
37
|
+
- Supports ESLint v9 or v8.50.0+
|
|
38
|
+
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
|
|
39
|
+
|
|
40
|
+
## How to use
|
|
41
|
+
|
|
42
|
+
1. Create `eslint.config.js` in your project root:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
// eslint.config.js
|
|
46
|
+
import hexadrop from '@hexadrop/eslint-config';
|
|
47
|
+
|
|
48
|
+
export default hexadrop();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
2. Run eslint
|
|
52
|
+
|
|
53
|
+
```shell
|
|
54
|
+
eslint .
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Or adding to your package.json**
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"scripts": {
|
|
62
|
+
"lint": "eslint .",
|
|
63
|
+
"lint:fix": "eslint --fix ."
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
|
|
69
|
+
|
|
70
|
+
## Customization
|
|
71
|
+
|
|
72
|
+
Since v4.0, we migrated to [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides much better organization and composition.
|
|
73
|
+
|
|
74
|
+
Normally you only need to import the `hexadrop` preset:
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
// eslint.config.js
|
|
78
|
+
import hexadrop from '@hexadrop/eslint-config';
|
|
79
|
+
|
|
80
|
+
export default hexadrop();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
And that's it! Or you can configure each integration individually, for example:
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
// eslint.config.js
|
|
87
|
+
import hexadrop from '@hexadrop/eslint-config';
|
|
88
|
+
|
|
89
|
+
export default hexadrop({
|
|
90
|
+
// React are auto-detected, you can also explicitly enable them:
|
|
91
|
+
react: true,
|
|
92
|
+
|
|
93
|
+
// Disable stylistic formatting rules
|
|
94
|
+
// stylistic: false,
|
|
95
|
+
|
|
96
|
+
// Or customize the stylistic rules
|
|
97
|
+
stylistic: {
|
|
98
|
+
indent: 'spaces', // or 'tab'
|
|
99
|
+
quotes: 'single', // or 'double'
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
// TypeScript are auto-detected, you can also explicitly enable them:
|
|
103
|
+
typescript: true,
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The `hexadrop` factory function also accepts any number of arbitrary custom config overrides:
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
// eslint.config.js
|
|
111
|
+
import hexadrop from '@hexadrop/eslint-config';
|
|
112
|
+
|
|
113
|
+
export default hexadrop(
|
|
114
|
+
{
|
|
115
|
+
// Configures for hexadrop's config
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
// From the second arguments they are ESLint Flat Configs
|
|
119
|
+
// you can have multiple configs
|
|
120
|
+
{
|
|
121
|
+
files: ['**/*.ts'],
|
|
122
|
+
rules: {},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
rules: {},
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Check out the [options](https://github.com/hexattol/eslint-config/blob/main/src/options/hexadrop-eslint.options.ts) and [factory](https://github.com/hexadrop/eslint-config/blob/main/src/factory.ts) for more details.
|
|
131
|
+
|
|
132
|
+
### Plugins Renaming
|
|
133
|
+
|
|
134
|
+
Since flat config requires us to explicitly provide the plugin names (instead of the mandatory convention from npm
|
|
135
|
+
package name), we renamed some plugins to make the overall scope more consistent and easier to write.
|
|
136
|
+
|
|
137
|
+
| New Prefix | Original Prefix | Source Plugin |
|
|
138
|
+
|-------------------|------------------------|------------------------------------|
|
|
139
|
+
| `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin] |
|
|
140
|
+
| `typescript/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin] |
|
|
141
|
+
| `import/*` | `import-x/*` | [eslint-plugin-import-x] |
|
|
142
|
+
| `json/*` | `jsonc/*` | [eslint-plugin-jsonc] |
|
|
143
|
+
| `node/*` | `n/*` | [eslint-plugin-n] |
|
|
144
|
+
| `import-sort/*` | `simple-import-sort/*` | [eslint-plugin-simple-import-sort] |
|
|
145
|
+
| `import-unused/*` | `unused-imports/*` | [eslint-plugin-unused-imports] |
|
|
146
|
+
|
|
147
|
+
When you want to override rules, or disable them inline, you need to update to the new prefix:
|
|
148
|
+
|
|
149
|
+
```diff
|
|
150
|
+
-// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
151
|
+
+// eslint-disable-next-line typescript/consistent-type-definitions
|
|
152
|
+
type foo = { bar: 2 }
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
> [!NOTE]
|
|
156
|
+
> About plugin renaming - it is actually rather a dangerous move that might lead to potential naming collisions,
|
|
157
|
+
> pointed out [here](https://github.com/eslint/eslint/discussions/17766)
|
|
158
|
+
> and [here](https://github.com/prettier/eslint-config-prettier#eslintconfigjs-flat-config-plugin-caveat). As this
|
|
159
|
+
> config
|
|
160
|
+
> also very **personal** and **opinionated**, I ambitiously position this config as the only **"top-level"** config per
|
|
161
|
+
> project, that might pivot the taste of how rules are named.
|
|
162
|
+
>
|
|
163
|
+
> This config cares more about the user-facings DX, and try to ease out the implementation details. For example, users
|
|
164
|
+
> could keep using the semantic `import/order` without ever knowing the underlying plugin has migrated twice
|
|
165
|
+
> to `eslint-plugin-i` and then to `eslint-plugin-import-x`. User are also not forced to migrate to the
|
|
166
|
+
> implicit `i/order`
|
|
167
|
+
> halfway only because we swapped the implementation to a fork.
|
|
168
|
+
>
|
|
169
|
+
> That said, it's probably still not a good idea. You might not want to do this if you are maintaining your own
|
|
170
|
+
> eslint config.
|
|
171
|
+
>
|
|
172
|
+
> Feel free to open issues if you want to combine this config with some other config presets but faced naming
|
|
173
|
+
> collisions. I am happy to figure out a way to make them work. But at this moment I have no plan to revert the
|
|
174
|
+
> renaming.
|
|
175
|
+
|
|
176
|
+
### Rules Overrides
|
|
177
|
+
|
|
178
|
+
Certain rules would only be enabled in specific files, for example, `ts/*` rules would only be enabled in `.ts` files and `vue/*` rules would only be enabled in `.vue` files. If you want to override the rules, you need to specify the file extension:
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
// eslint.config.js
|
|
182
|
+
import hexadrop from '@hexadrop/eslint-config';
|
|
183
|
+
|
|
184
|
+
export default hexadrop(
|
|
185
|
+
{
|
|
186
|
+
react: true,
|
|
187
|
+
typescript: true,
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
// Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
|
|
191
|
+
files: ['**/*.jsx'],
|
|
192
|
+
rules: {
|
|
193
|
+
'style/jsx-indent': 'off',
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
// Without `files`, they are general rules for all files
|
|
198
|
+
rules: {
|
|
199
|
+
'style/semi': ['error', 'never'],
|
|
200
|
+
},
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Config Composer
|
|
206
|
+
|
|
207
|
+
Since v2.10.0, the factory function `hexadrop()` returns a [`FlatConfigComposer` object from `eslint-flat-config-utils`](https://github.com/antfu/eslint-flat-config-utils#composer) where you can chain the methods to compose the config even more flexibly.
|
|
208
|
+
|
|
209
|
+
```js
|
|
210
|
+
// eslint.config.js
|
|
211
|
+
import hexadrop from '@hexadrop/eslint-config';
|
|
212
|
+
|
|
213
|
+
export default hexadrop()
|
|
214
|
+
// some configs before the main config
|
|
215
|
+
.prepend()
|
|
216
|
+
// overrides any named configs
|
|
217
|
+
.override('hexadrop/core/rules', {
|
|
218
|
+
rules: {
|
|
219
|
+
'no-console': 'off',
|
|
220
|
+
},
|
|
221
|
+
})
|
|
222
|
+
// directly remove a named config
|
|
223
|
+
.remove('hexadrop/typescript/rules/dts')
|
|
224
|
+
// rename plugin prefixes
|
|
225
|
+
.renamePlugins({
|
|
226
|
+
'old-prefix': 'new-prefix',
|
|
227
|
+
// ...
|
|
228
|
+
});
|
|
229
|
+
// ...
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Lint Staged
|
|
233
|
+
|
|
234
|
+
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
|
|
235
|
+
|
|
236
|
+
```json
|
|
237
|
+
{
|
|
238
|
+
"simple-git-hooks": {
|
|
239
|
+
"pre-commit": "pnpm lint-staged"
|
|
240
|
+
},
|
|
241
|
+
"lint-staged": {
|
|
242
|
+
"*": "eslint --fix"
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
and then
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
npm i -D lint-staged simple-git-hooks
|
|
251
|
+
|
|
252
|
+
// to active the hooks
|
|
253
|
+
npx simple-git-hooks
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## View what rules are enabled
|
|
257
|
+
|
|
258
|
+
There is a [visual tool](https://github.com/eslint/config-inspector) to help you view what rules are enabled in your project and apply them to what files.
|
|
259
|
+
|
|
260
|
+
Go to your project root that contains `eslint.config.js` and run:
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
bunx @eslint/config-inspector
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Inspiration and Credits
|
|
267
|
+
|
|
268
|
+
Here are some inspiration for this package.
|
|
269
|
+
|
|
270
|
+
- [@antfu/eslint-config](https://github.com/antfu/eslint-config)
|
|
271
|
+
- [eslint-config-codely](https://github.com/CodelyTV/eslint-config-codely)
|
|
272
|
+
|
|
273
|
+
## hexadrop Code Quality Standards
|
|
274
|
+
|
|
275
|
+
Publishing this package we are committing ourselves to the following code quality standards:
|
|
276
|
+
|
|
277
|
+
- Respect **Semantic Versioning**: No breaking changes in patch or minor versions
|
|
278
|
+
- No surprises in transitive dependencies: Use the **bare minimum dependencies** needed to meet the purpose
|
|
279
|
+
- **One specific purpose** to meet without having to carry a bunch of unnecessary other utilities
|
|
280
|
+
- **Tests** as documentation and usage examples
|
|
281
|
+
- **Well documented README** showing how to install and use
|
|
282
|
+
- **License favoring Open Source** and collaboration
|
|
283
|
+
|
|
284
|
+
[@stylistic/eslint-plugin]: https://github.com/eslint-stylistic/eslint-stylistic
|
|
285
|
+
[@typescript-eslint/eslint-plugin]: https://github.com/typescript-eslint/typescript-eslint
|
|
286
|
+
[eslint-plugin-jsonc]: https://github.com/ota-meshi/eslint-plugin-jsonc
|
|
287
|
+
[eslint-plugin-import-x]: https://github.com/un-es/eslint-plugin-import-x
|
|
288
|
+
[eslint-plugin-n]: https://github.com/eslint-community/eslint-plugin-n
|
|
289
|
+
[eslint-plugin-simple-import-sort]: https://github.com/lydell/eslint-plugin-simple-import-sort
|
|
290
|
+
[eslint-plugin-unused-imports]: https://github.com/sweepline/eslint-plugin-unused-imports
|