@coderwyd/eslint-config 1.1.0-beta.1 → 1.1.0-beta.3

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/README.md CHANGED
@@ -6,35 +6,45 @@
6
6
 
7
7
  ## Feature
8
8
 
9
- - Single quotes, no semi
10
- - Auto fix for formatting (aimed to be used standalone **without** Prettier)
11
- - Designed to work with TypeScript, Vue out-of-box
12
- - Lint also for json, yaml, markdown
13
- - Sorted imports, dangling commas
14
- - Reasonable defaults, best practices, only one-line of config
9
+ - Single quotes, no semi
10
+ - 🛠️ Auto fix for formatting (aimed to be used standalone **without** Prettier)
11
+ - 🎯 Designed to work with TypeScript, Vue out-of-box
12
+ - 🔍 Lints also for json, yaml, markdown
13
+ - 🧩 Sorted imports, dangling commas
14
+ - 🏆 Reasonable defaults, best practices, only one-line of config
15
+ - 🚀 [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
16
+ - 🎨 Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
17
+ - 📖 **Style principle**: Minimal for reading, stable for diff, consistent
15
18
 
16
19
  ## Usage
17
20
 
18
21
  ### Install
19
22
 
20
23
  ```bash
21
- pnpm add -D eslint @coderwyd/eslint-config # JavaScript, TypeScript and Vue 3
22
- # Or yarn add eslint @coderwyd/eslint-config -D / npm install eslint @coderwyd/eslint-config -D
23
- pnpm add -D @coderwyd/eslint-config-basic # JavaScript only
24
- pnpm add -D @coderwyd/eslint-config-ts # JavaScript and TypeScript
25
- pnpm add -D @coderwyd/eslint-config-react # JavaScript, TypeScript and React
26
- pnpm add -D @coderwyd/eslint-config-vue # JavaScript, TypeScript and Vue 3
24
+ pnpm i -D eslint @coderwyd/eslint-config
27
25
  ```
28
26
 
29
- ### Config `.eslintrc`
27
+ ### Create config file
30
28
 
31
- ```json
32
- {
33
- "extends": "@coderwyd"
34
- }
29
+ With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package.json` (recommended):
30
+
31
+ ```js
32
+ // eslint.config.js
33
+ import coderwyd from '@coderwyd/eslint-config'
34
+
35
+ export default coderwyd()
36
+ ```
37
+
38
+ With CJS:
39
+
40
+ ```js
41
+ // eslint.config.js
42
+ const coderwyd = require('@coderwyd/eslint-config').default
43
+
44
+ module.exports = coderwyd()
35
45
  ```
36
46
 
37
- > You don't need `.eslintignore` normally as it has been provided by the preset.
47
+ > Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
38
48
 
39
49
  ### Add script for package.json
40
50
 
@@ -49,40 +59,256 @@ For example:
49
59
  }
50
60
  ```
51
61
 
52
- ### VS Code support (auto fix)
62
+ ## VS Code support (auto fix)
63
+
64
+ Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
53
65
 
54
- Add the following settings to your `settings.json`:
66
+ Add the following settings to your `.vscode/settings.json`:
55
67
 
56
68
  ```jsonc
57
69
  {
70
+ // Enable the ESlint flat config support
71
+ "eslint.experimental.useFlatConfig": true,
72
+
73
+ // Disable the default formatter, use eslint instead
58
74
  "prettier.enable": false,
59
75
  "editor.formatOnSave": false,
76
+
77
+ // Auto fix
60
78
  "editor.codeActionsOnSave": {
61
79
  "source.fixAll.eslint": true,
62
80
  "source.organizeImports": false
63
81
  },
64
82
 
65
- // The following is optional.
66
- // It's better to put under project setting `.vscode/settings.json`
67
- // to avoid conflicts with working with different eslint configs
68
- // that does not support all formats.
69
- "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue", "html", "markdown", "json", "jsonc", "yaml"]
83
+ // Silent the stylistic rules in you IDE, but still auto fix them
84
+ "eslint.rules.customizations": [
85
+ { "rule": "style/*", "severity": "off" },
86
+ { "rule": "*-indent", "severity": "off" },
87
+ { "rule": "*-spacing", "severity": "off" },
88
+ { "rule": "*-spaces", "severity": "off" },
89
+ { "rule": "*-order", "severity": "off" },
90
+ { "rule": "*-dangle", "severity": "off" },
91
+ { "rule": "*-newline", "severity": "off" },
92
+ { "rule": "*quotes", "severity": "off" },
93
+ { "rule": "*semi", "severity": "off" }
94
+ ],
95
+
96
+ // Enable eslint for all supported languages
97
+ "eslint.validate": [
98
+ "javascript",
99
+ "javascriptreact",
100
+ "typescript",
101
+ "typescriptreact",
102
+ "vue",
103
+ "html",
104
+ "markdown",
105
+ "json",
106
+ "jsonc",
107
+ "yaml"
108
+ ]
70
109
  }
71
110
  ```
72
111
 
73
- ### TypeScript Aware Rules
112
+ ## Customization
74
113
 
75
- Type aware rules are enabled when a `tsconfig.eslint.json` is found in the project root, which will introduce some stricter rules into your project. If you want to enable it while have no `tsconfig.eslint.json` in the project root, you can change tsconfig name by modifying `ESLINT_TSCONFIG` env.
114
+ Since v1.0, we migrated to [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides a much better organization and composition.
115
+
116
+ Normally you only need to import the `coderwyd` preset:
76
117
 
77
118
  ```js
78
- // .eslintrc.js
79
- const process = require('node:process')
119
+ // eslint.config.js
120
+ import coderwyd from '@coderwyd/eslint-config'
121
+
122
+ export default coderwyd()
123
+ ```
80
124
 
81
- process.env.ESLINT_TSCONFIG = 'tsconfig.json'
125
+ And that's it! Or you can configure each integration individually, for example:
82
126
 
83
- module.exports = {
84
- extends: '@coderwyd',
85
- }
127
+ ```js
128
+ // eslint.config.js
129
+ import coderwyd from '@coderwyd/eslint-config'
130
+
131
+ export default coderwyd({
132
+ stylistic: true, // enable stylistic formatting rules
133
+ typescript: true,
134
+ vue: true,
135
+ jsonc: false, // disable jsonc support
136
+ yaml: false,
137
+
138
+ // `.eslintignore` is no longer supported in Flat config, use `ignores` instead
139
+ ignores: [
140
+ './fixtures',
141
+ // ...globs
142
+ ]
143
+ })
144
+ ```
145
+
146
+ The `coderwyd` factory function also accepts any number of arbitrary custom config overrides:
147
+
148
+ ```js
149
+ // eslint.config.js
150
+ import coderwyd from '@coderwyd/eslint-config'
151
+
152
+ export default coderwyd(
153
+ {
154
+ // Configures for coderwyd's config
155
+ },
156
+
157
+ // From the second arguments they are ESLint Flat Configs
158
+ // you can have multiple configs
159
+ {
160
+ files: ['**/*.ts'],
161
+ rules: {},
162
+ },
163
+ {
164
+ rules: {},
165
+ },
166
+ )
167
+ ```
168
+
169
+ Going more advanced, you can also import fine-grained configs and compose them as you wish:
170
+
171
+ ```js
172
+ // eslint.config.js
173
+ import {
174
+ astro,
175
+ comments,
176
+ ignores,
177
+ imports,
178
+ javascript,
179
+ jsdoc,
180
+ jsonc,
181
+ markdown,
182
+ node,
183
+ react,
184
+ sortPackageJson,
185
+ sortTsconfig,
186
+ stylistic,
187
+ typescript,
188
+ unicorn,
189
+ vue,
190
+ yml,
191
+ } from '@coderwyd/eslint-config'
192
+
193
+ export default [
194
+ ...astro(),
195
+ ...react(),
196
+ ...ignores(),
197
+ ...javascript(),
198
+ ...comments(),
199
+ ...node(),
200
+ ...jsdoc(),
201
+ ...imports(),
202
+ ...unicorn(),
203
+ ...typescript(),
204
+ ...stylistic(),
205
+ ...vue(),
206
+ ...jsonc(),
207
+ ...yml(),
208
+ ...markdown(),
209
+ ]
210
+ ```
211
+
212
+ Check out the [configs](https://github.com/coderwyd/eslint-config/blob/main/src/configs) and [factory](https://github.com/coderwyd/eslint-config/blob/main/src/factory.ts) for more details.
213
+
214
+ ## Plugins Renaming
215
+
216
+ Since flat config requires us to explicitly provide the plugin names (instead of mandatory convention from npm package name), we renamed some plugins to make overall scope more consistent and easier to write.
217
+
218
+ | New Prefix | Original Prefix | Source Plugin |
219
+ | --- | --- | --- |
220
+ | `import/*` | `i/*` | [eslint-plugin-i](https://github.com/un-es/eslint-plugin-i) |
221
+ | `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
222
+ | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
223
+ | `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
224
+ | `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
225
+ | `test/*` | `vitest/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
226
+ | `test/*` | `no-only-tests/*` | [eslint-plugin-no-only-tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests) |
227
+
228
+ When you want to override rules, or disable them inline, you need to update to the new prefix:
229
+
230
+ ```diff
231
+ -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
232
+ +// eslint-disable-next-line ts/consistent-type-definitions
233
+ type foo = { bar: 2 }
234
+ ```
235
+
236
+ ### Rules Overrides
237
+
238
+ 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:
239
+
240
+ ```js
241
+ // eslint.config.js
242
+ import coderwyd from '@coderwyd/eslint-config'
243
+
244
+ export default coderwyd(
245
+ {
246
+ // Enable stylistic formatting rules
247
+ // stylistic: true,
248
+
249
+ // Or customize the stylistic rules
250
+ stylistic: {
251
+ indent: 2, // 4, or 'tab'
252
+ quotes: 'single', // or 'double'
253
+ },
254
+
255
+ // TypeScript and Vue are auto-detected, you can also explicitly enable them:
256
+ typescript: true,
257
+ vue: true,
258
+
259
+ // Disable jsonc and yaml support
260
+ jsonc: false,
261
+ yaml: false,
262
+ },
263
+ {
264
+ // Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
265
+ files: ['**/*.vue'],
266
+ rules: {
267
+ 'vue/operator-linebreak': ['error', 'before'],
268
+ },
269
+ },
270
+ {
271
+ // Without `files`, they are general rules for all files
272
+ rules: {
273
+ 'style/semi': ['error', 'never'],
274
+ },
275
+ }
276
+ )
277
+ ```
278
+
279
+ We also provided an `overrides` options to make it easier:
280
+
281
+ ```js
282
+ // eslint.config.js
283
+ import coderwyd from '@coderwyd/eslint-config'
284
+
285
+ export default coderwyd({
286
+ overrides: {
287
+ vue: {
288
+ 'vue/operator-linebreak': ['error', 'before'],
289
+ },
290
+ typescript: {
291
+ 'ts/consistent-type-definitions': ['error', 'interface'],
292
+ },
293
+ yaml: {},
294
+ // ...
295
+ }
296
+ })
297
+ ```
298
+
299
+ ### Type Aware Rules
300
+
301
+ You can optionally enable the [type aware rules](https://typescript-eslint.io/linting/typed-linting/) by passing the options object to the `typescript` config:
302
+
303
+ ```js
304
+ // eslint.config.js
305
+ import coderwyd from '@coderwyd/eslint-config'
306
+
307
+ export default coderwyd({
308
+ typescript: {
309
+ tsconfigPath: 'tsconfig.json',
310
+ },
311
+ })
86
312
  ```
87
313
 
88
314
  ### Lint Staged
@@ -106,27 +332,10 @@ and then
106
332
  npm i -D lint-staged simple-git-hooks
107
333
  ```
108
334
 
109
- ## FAQ
110
-
111
- ### Customization rules
112
-
113
- add you like rules to your .eslintrc file.
114
-
115
- <!-- eslint-skip -->
116
-
117
- ```jsonc
118
- {
119
- "extends": "@coderwyd",
120
- "rules": {
121
- // your rules...
122
- }
123
- }
124
- ```
125
-
126
335
  ## Thanks
127
336
 
128
337
  This project is based on [@antfu/eslint-config](https://github.com/antfu/eslint-config)
129
338
 
130
339
  ## License
131
340
 
132
- [MIT](./LICENSE) License &copy; 2019-PRESENT [Donny Wang](https://github.com/coderwyd)
341
+ [MIT](./LICENSE) License &copy; 2023-PRESENT [Donny Wang](https://github.com/coderwyd)