@luxass/eslint-config 4.3.6 → 4.4.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/README.md CHANGED
@@ -5,9 +5,9 @@
5
5
 
6
6
  ## ✨ Features
7
7
 
8
- - Based on [Antfu's ESLint Config](https://github.com/antfu/eslint-config)
8
+ - Based on [antfu's ESLint Config](https://github.com/antfu/eslint-config) with some modifications
9
9
  - Auto fix for formatting (aimed to be used standalone **without** Prettier)
10
- - Designed to work with TypeScript, JSX, Vue & Astro out-of-box
10
+ - Designed to work with TypeScript, JSX, Vue out-of-box
11
11
  - Lints also for json, yaml, toml, markdown
12
12
  - Sorted imports, dangling commas
13
13
  - Reasonable defaults, best practices, only one-line of config
@@ -15,44 +15,39 @@
15
15
  - [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
16
16
  - Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
17
17
  - Respects `.gitignore` by default
18
+ - Optional [React](#react), [Svelte](#svelte), [Solid](#solid), [UnoCSS](#unocss), [Astro](#astro) support
18
19
  - Optional [formatters](#formatters) support for CSS, HTML, etc.
19
20
 
20
- ## 📦 Install
21
+ ## Usage
21
22
 
22
- ```bash copy
23
+ ```bash
23
24
  npm install -D eslint @luxass/eslint-config
24
25
  ```
25
26
 
26
- ## 🚀 Usage
27
-
28
- With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package.json` (recommended):
27
+ And create a `eslint.config.mjs` in your project root:
29
28
 
30
29
  ```js
31
- // eslint.config.js
30
+ // eslint.config.mjs
32
31
  import luxass from '@luxass/eslint-config'
33
32
 
34
33
  export default luxass()
35
34
  ```
36
35
 
37
- With CJS:
38
-
39
- ```js
40
- // eslint.config.js
41
- const luxass = require('@luxass/eslint-config')
42
-
43
- module.exports = luxass()
44
- ```
45
-
36
+ <details>
37
+ <summary>
46
38
  Combined with legacy config:
39
+ </summary>
40
+
41
+ If you still use some configs from the legacy ESLint RC format, you can use the [`@eslint/eslintrc`](https://www.npmjs.com/package/@eslint/eslintrc) package to convert them to the flat config.
47
42
 
48
43
  ```js
49
- // eslint.config.js
50
- const luxass = require('@luxass/eslint-config')
51
- const { FlatCompat } = require('@eslint/eslintrc')
44
+ // eslint.config.mjs
45
+ import luxass from '@luxass/eslint-config'
46
+ import { FlatCompat } from '@eslint/eslintrc'
52
47
 
53
48
  const compat = new FlatCompat()
54
49
 
55
- module.exports = luxass(
50
+ export default luxass(
56
51
  {
57
52
  ignores: [],
58
53
  },
@@ -71,7 +66,22 @@ module.exports = luxass(
71
66
 
72
67
  > Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
73
68
 
74
- ## Setup for Visual Studio Code
69
+ </details>
70
+
71
+ ### Add script for package.json
72
+
73
+ For example:
74
+
75
+ ```json
76
+ {
77
+ "scripts": {
78
+ "lint": "eslint .",
79
+ "lint:fix": "eslint . --fix"
80
+ }
81
+ }
82
+ ```
83
+
84
+ ## Setup for Visual Studio Code (with auto-fix)
75
85
 
76
86
  Install [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and add the following to your `.vscode/settings.json`:
77
87
 
@@ -118,14 +128,17 @@ Install [ESLint extension](https://marketplace.visualstudio.com/items?itemName=d
118
128
  "markdown",
119
129
  "json",
120
130
  "jsonc",
121
- "yaml"
131
+ "yaml",
132
+ "toml",
133
+ "gql",
134
+ "graphql"
122
135
  ]
123
136
  }
124
137
  ```
125
138
 
126
139
  ## Customization
127
140
 
128
- Normally you would only need to import the `luxass` preset:
141
+ Normally you would only need to import the config and export it:
129
142
 
130
143
  ```js
131
144
  // eslint.config.js
@@ -134,46 +147,67 @@ import luxass from '@luxass/eslint-config'
134
147
  export default luxass()
135
148
  ```
136
149
 
137
- you can also configure each `config` individually:
150
+ And that's it! Or you can configure each integration individually, for example:
138
151
 
139
152
  ```js
140
153
  // eslint.config.js
141
154
  import luxass from '@luxass/eslint-config'
142
155
 
143
156
  export default luxass({
144
- stylistic: true,
157
+ // Enable stylistic formatting rules
158
+ // stylistic: true,
159
+
160
+ // Or customize the stylistic rules
161
+ stylistic: {
162
+ indent: 2, // 4, or 'tab'
163
+ quotes: 'single', // or 'double'
164
+ },
165
+
166
+ // TypeScript and Vue are auto-detected, you can also explicitly enable them:
145
167
  typescript: true,
146
168
  vue: true,
147
- react: false,
148
- astro: true,
149
- unocss: true,
150
169
 
151
- // `.eslintignore` is no longer supported in Flat config, use `ignores` instead.
170
+ // Disable jsonc and yaml support
171
+ jsonc: false,
172
+ yaml: false,
173
+
174
+ // `.eslintignore` is no longer supported in Flat config, use `ignores` instead
152
175
  ignores: [
153
- '**/fixtures'
176
+ '**/fixtures',
177
+ // ...globs
154
178
  ]
155
179
  })
156
180
  ```
157
181
 
158
- The `luxass` function accepts an arbitrary number of `flat configs` overrides:
182
+ The `luxass` factory function also accepts any number of arbitrary custom config overrides:
159
183
 
160
184
  ```js
161
185
  // eslint.config.js
162
186
  import luxass from '@luxass/eslint-config'
163
187
 
164
- export default luxass({
165
- // configuration points for my config
166
- }, {
167
- rules: {}
168
- }, {
169
- rules: {}
170
- })
188
+ export default luxass(
189
+ {
190
+ // Configures for luxass's config
191
+ },
192
+
193
+ // From the second arguments they are ESLint Flat Configs
194
+ // you can have multiple configs
195
+ {
196
+ files: ['**/*.ts'],
197
+ rules: {},
198
+ },
199
+ {
200
+ rules: {},
201
+ },
202
+ )
171
203
  ```
172
204
 
205
+ Going more advanced, you can also import fine-grained configs and compose them as you wish:
206
+
173
207
  <details>
174
208
  <summary>Advanced Example</summary>
175
209
 
176
- We don't recommend using this style in general usages, as there are shared options between configs and might need extra care to make them consistent.
210
+ We wouldn't recommend using this style in general unless you know exactly what they are doing, as there are shared options between configs and might need extra care to make them consistent.
177
211
 
178
212
  ```js
179
213
  // eslint.config.js
@@ -221,16 +255,21 @@ Check out the [configs](https://github.com/luxass/eslint-config/blob/main/src/co
221
255
 
222
256
  ### Plugins Renaming
223
257
 
224
- 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.
225
-
226
- | New Prefix | Original Prefix | Source Plugin |
227
- | ---------- | ---------------------- | ------------------------------------------------------------------------------------------ |
228
- | `import/*` | `import-x/*` | [eslint-plugin-import-x](https://github.com/un-es/eslint-plugin-import-x) |
229
- | `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
230
- | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
231
- | `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
232
- | `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
233
- | `test/*` | `vitest/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
258
+ 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.
259
+
260
+ | New Prefix | Original Prefix | Source Plugin |
261
+ | --------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
262
+ | `import/*` | `import-x/*` | [eslint-plugin-import-x](https://github.com/un-es/eslint-plugin-import-x) |
263
+ | `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
264
+ | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
265
+ | `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
266
+ | `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
267
+ | `test/*` | `vitest/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
268
+ | `react/*` | `@eslint-react/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
269
+ | `react-dom/*` | `@eslint-react/dom/*` | [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) |
270
+ | `react-hooks-extra/*` | `@eslint-react/hooks-extra/*` | [eslint-plugin-react-hooks-extra](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-hooks-extra) |
271
+ | `react-naming-convention/*` | `@eslint-react/naming-convention/*` | [eslint-plugin-react-naming-convention](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-naming-convention) |
272
+ | `nextjs` | `@next/next` | [eslint-plugin-react-refresh](https://github.com/vercel/next.js/tree/canary/packages/eslint-plugin-next) |
234
273
 
235
274
  When you want to override rules, or disable them inline, you need to update to the new prefix:
236
275
 
@@ -240,6 +279,17 @@ When you want to override rules, or disable them inline, you need to update to t
240
279
  type foo = { bar: 2 }
241
280
  ```
242
281
 
282
+ > [!NOTE]
283
+ > About plugin renaming - it is actually rather a dangerous move that might lead to potential naming collisions, pointed out [here](https://github.com/eslint/eslint/discussions/17766) and [here](https://github.com/prettier/eslint-config-prettier#eslintconfigjs-flat-config-plugin-caveat). As this config also very **personal** and **opinionated**, I ambitiously position this config as the only **"top-level"** config per project, that might pivot the taste of how rules are named.
284
+ >
285
+ > This config cares more about the user-facings DX, and try to ease out the implementation details. For example, users could keep using the semantic `import/order` without ever knowing the underlying plugin has migrated twice to `eslint-plugin-i` and then to `eslint-plugin-import-x`. User are also not forced to migrate to the implicit `i/order` halfway only because we swapped the implementation to a fork.
286
+ >
287
+ > That said, it's probably still not a good idea. You might not want to do this if you are maintaining your own ESLint config.
288
+ >
289
+ > Feel free to open issues if you want to combine this config with some other config presets but faced naming collisions. I am happy to figure out a way to make them work. But at this moment I have no plan to revert the renaming.
290
+
291
+ Since v4.3.0, this preset will automatically rename the plugins also for your custom configs. You can use the original prefix to override the rules directly.
292
+
243
293
  ### Rules Overrides
244
294
 
245
295
  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:
@@ -249,7 +299,10 @@ Certain rules would only be enabled in specific files, for example, `ts/*` rules
249
299
  import luxass from '@luxass/eslint-config'
250
300
 
251
301
  export default luxass(
252
- { vue: true, typescript: true },
302
+ {
303
+ vue: true,
304
+ typescript: true
305
+ },
253
306
  {
254
307
  // Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
255
308
  files: ['**/*.vue'],
@@ -266,36 +319,67 @@ export default luxass(
266
319
  )
267
320
  ```
268
321
 
269
- We also provided a `overrides` options to make it easier:
322
+ We also provided a `overrides` options in each integration to make it easier:
270
323
 
271
324
  ```js
272
325
  // eslint.config.js
273
326
  import luxass from '@luxass/eslint-config'
274
327
 
275
328
  export default luxass({
276
- overrides: {
277
- vue: {
329
+ vue: {
330
+ overrides: {
278
331
  'vue/operator-linebreak': ['error', 'before'],
279
332
  },
280
- typescript: {
333
+ },
334
+ typescript: {
335
+ overrides: {
281
336
  'ts/consistent-type-definitions': ['error', 'interface'],
282
337
  },
283
- yaml: {},
284
- // ...
285
- }
338
+ },
339
+ yaml: {
340
+ overrides: {
341
+ // ...
342
+ },
343
+ },
286
344
  })
287
345
  ```
288
346
 
347
+ ### Config Composer
348
+
349
+ Since v4.3.0, the factory function `luxass()` 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.
350
+
351
+ ```js
352
+ // eslint.config.js
353
+ import luxass from '@luxass/eslint-config'
354
+
355
+ export default luxass()
356
+ .prepend(
357
+ // some configs before the main config
358
+ )
359
+ // overrides any named configs
360
+ .override(
361
+ 'luxass/imports',
362
+ {
363
+ rules: {
364
+ 'import/order': ['error', { 'newlines-between': 'always' }],
365
+ }
366
+ }
367
+ )
368
+ // rename plugin prefixes
369
+ .renamePlugins({
370
+ 'old-prefix': 'new-prefix',
371
+ // ...
372
+ })
373
+ // ...
374
+ ```
375
+
289
376
  ### Optional Configs
290
377
 
291
378
  We provide some optional configs for specific use cases, that we don't include their dependencies by default.
292
379
 
293
380
  #### Formatters
294
381
 
295
- > [!WARNING]
296
- > Experimental feature, changes might not follow semver.
297
-
298
- Use external formatters to format files that ESLint cannot handle yet (`.css`, `.html`, etc). Powered by [`eslint-plugin-format`](https://github.com/antfu/eslint-plugin-format).
382
+ Use external formatters to format files that ESLint cannot handle yet (`.css`, `.html`, etc.). Powered by [`eslint-plugin-format`](https://github.com/antfu/eslint-plugin-format).
299
383
 
300
384
  ```js
301
385
  // eslint.config.js
@@ -313,11 +397,6 @@ export default luxass({
313
397
  * By default uses Prettier
314
398
  */
315
399
  html: true,
316
- /**
317
- * Format TOML files
318
- * Currently only supports dprint
319
- */
320
- toml: 'dprint',
321
400
  /**
322
401
  * Format Markdown files
323
402
  * Supports Prettier and dprint
@@ -336,7 +415,7 @@ npm i -D eslint-plugin-format
336
415
 
337
416
  #### React
338
417
 
339
- To enable React support, need to explicitly turn it on:
418
+ To enable React support, you need to explicitly turn it on:
340
419
 
341
420
  ```js
342
421
  // eslint.config.js
@@ -350,7 +429,7 @@ export default luxass({
350
429
  Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
351
430
 
352
431
  ```bash
353
- npm i -D eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refresh
432
+ npm i -D @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugin-react-refresh
354
433
  ```
355
434
 
356
435
  #### Next.JS
@@ -371,12 +450,31 @@ export default luxass({
371
450
  Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
372
451
 
373
452
  ```bash
374
- npm i -D eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refresh @next/eslint-plugin-next
453
+ npm i -D eslint-plugin-react eslint-plugin-react-hooks @next/eslint-plugin-next
454
+ ```
455
+
456
+ #### Astro
457
+
458
+ To enable Astro support, you need to explicitly turn it on:
459
+
460
+ ```js
461
+ // eslint.config.js
462
+ import luxass from '@luxass/eslint-config'
463
+
464
+ export default luxass({
465
+ astro: true,
466
+ })
467
+ ```
468
+
469
+ Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
470
+
471
+ ```bash
472
+ npm i -D eslint-plugin-astro
375
473
  ```
376
474
 
377
475
  #### UnoCSS
378
476
 
379
- To enable UnoCSS support, need to explicitly turn it on:
477
+ To enable UnoCSS support, you need to explicitly turn it on:
380
478
 
381
479
  ```js
382
480
  // eslint.config.js
@@ -431,6 +529,55 @@ export default luxass({
431
529
  })
432
530
  ```
433
531
 
532
+ ### Editor Specific Disables
533
+
534
+ Some rules are disabled when inside ESLint IDE integrations, namely [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports) [`test/no-focused-tests`](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-focused-tests.md)
535
+
536
+ This is to prevent unused imports from getting removed by the IDE during refactoring to get a better developer experience. Those rules will be applied when you run ESLint in the terminal or [Lint Staged](#lint-staged). If you don't want this behavior, you can disable them:
537
+
538
+ ```js
539
+ // eslint.config.js
540
+ import luxass from '@luxass/eslint-config'
541
+
542
+ export default luxass({
543
+ editor: false
544
+ })
545
+ ```
546
+
547
+ ### Lint Staged
548
+
549
+ If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
550
+
551
+ ```json
552
+ {
553
+ "simple-git-hooks": {
554
+ "pre-commit": "pnpm lint-staged"
555
+ },
556
+ "lint-staged": {
557
+ "*": "eslint --fix"
558
+ }
559
+ }
560
+ ```
561
+
562
+ and then
563
+
564
+ ```bash
565
+ npm i -D lint-staged simple-git-hooks
566
+
567
+ // to active the hooks
568
+ npx simple-git-hooks
569
+ ```
570
+
571
+ ## View what rules are enabled
572
+
573
+ [antfu](https://github.com/antfu) built a visual tool to help you view what rules are enabled in your project and apply them to what files, [@eslint/config-inspector](https://github.com/eslint/config-inspector)
574
+
575
+ Go to your project root that contains `eslint.config.js` and run:
576
+
577
+ ```bash
578
+ npx @eslint/config-inspector
579
+ ```
580
+
434
581
  ## Versioning Policy
435
582
 
436
583
  This project follows [Semantic Versioning](https://semver.org/) for releases. However, since this is just a config and involves opinions and many moving parts, we don't treat rules changes as breaking changes.