@moso/eslint-config 3.0.4 → 3.1.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.
Files changed (4) hide show
  1. package/README.md +155 -62
  2. package/dist/index.d.mts +3903 -594
  3. package/dist/index.mjs +1015 -850
  4. package/package.json +54 -46
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # @moso/eslint-config
2
2
 
3
- [![npm](https://img.shields.io/npm/v/@moso/eslint-config.svg)](https://npmjs.com/package/@moso/eslint-config)
3
+ [![npm](https://img.shields.io/npm/v/@moso/eslint-config.svg)](https://npmx.dev/package/@moso/eslint-config)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@moso/eslint-config?color=000080)](https://npmx.dev/package/@moso/eslint-config)
4
5
 
5
6
  Flat ESLint config for JavaScript, TypeScript, Vue, React, and more.
6
7
 
@@ -15,7 +16,8 @@ Flat ESLint config for JavaScript, TypeScript, Vue, React, and more.
15
16
  - Ships its own small [`@moso`](#custom-rules)-ruleset with security and hygiene rules
16
17
  - Every config can be enabled/disabled
17
18
  - Respects `.gitignore` by default
18
- - Requires Node.js >= v22.23.x/v24.18.x, ESLint v10+
19
+ - Requires Node.js >= v22.22.3/v24.x, ESLint v10+
20
+ - Enhanced security by [Socket's Bun Security Scanner](https://npmx.dev/package/@socketsecurity/bun-security-scanner)
19
21
 
20
22
  > [!NOTE]
21
23
  > **Note regarding TypeScript v7**
@@ -31,7 +33,7 @@ This section contains a list of the plugins used in the named configs that ships
31
33
  \- 🟨 Can be enabled manually
32
34
  \- 🎨 Stylistic rules enabled
33
35
  \- 💭 Type-aware rules available by setting the path to your `tsconfig.json`
34
- \- â„šī¸ Accessibility rules available with `a11y: true`
36
+ \- â„šī¸ Accessibility rules available with `a11y: true`
35
37
 
36
38
  <table>
37
39
  <thead>
@@ -56,6 +58,17 @@ This section contains a list of the plugins used in the named configs that ships
56
58
  </tr>
57
59
  <tr>
58
60
  <td valign="top">
61
+ <details><summary><strong>Baseline</strong></summary>
62
+
63
+ [`eslint-plugin-baseline-js`](https://github.com/3ru/eslint-plugin-baseline-js)
64
+
65
+ </details></td>
66
+ <td valign="top">✅</td>
67
+ <td valign="top"></td>
68
+ <td valign="top">💭</td>
69
+ </tr>
70
+ <tr>
71
+ <td valign="top">
59
72
  <details><summary><strong>e18e</strong></summary>
60
73
 
61
74
  [`@e18e/eslint-plugin`](https://github.com/e18e/eslint-plugin)
@@ -222,6 +235,17 @@ This section contains a list of the plugins used in the named configs that ships
222
235
  </tr>
223
236
  <tr>
224
237
  <td valign="top">
238
+ <details><summary><strong>TailwindCSS</strong></summary>
239
+
240
+ [`eslint-plugin-better-tailwindcss`](https://github.com/schoero/eslint-plugin-better-tailwindcss)
241
+
242
+ </details></td>
243
+ <td valign="top">â˜‘ī¸</td>
244
+ <td valign="top">🎨</td>
245
+ <td valign="top"></td>
246
+ </tr>
247
+ <tr>
248
+ <td valign="top">
225
249
  <details><summary><strong>Test</strong></summary>
226
250
 
227
251
  [`@vitest/eslint-plugin`](https://github.com/vitest-dev/eslint-plugin-vitest), [`eslint-plugin-no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests)
@@ -309,22 +333,40 @@ This config ships its own small plugin, registered as `@moso`. Each rule has ful
309
333
  | [`prefer-early-return`](./src/rules/prefer-early-return/prefer-early-return.md) | Prefer guard clauses over wrapped function bodies | | 🔧 |
310
334
  | [`prefer-fetch`](./src/rules/prefer-fetch/prefer-fetch.md) | Enforce `fetch` over legacy HTTP clients | | |
311
335
  | [`prefer-reduce-over-chaining`](./src/rules/prefer-reduce-over-chaining/prefer-reduce-over-chaining.md) | Prefer one `.reduce()` pass over `.map().filter()` chains | ✅ | |
336
+ | [`prefer-strict-number-guards`](./src/rules/prefer-strict-number-guards/prefer-strict-number-guards.md) | Enforce the syntactic patterns that keep numeric code analyzable | | |
312
337
 
313
338
  ## Usage
314
339
 
315
340
  ### Install
316
341
 
317
- > [!NOTE]
318
- > I like to use [Bun](https://bun.sh) because it's hella fast. Thus all the install instructions are with Bun. If you use something else, check the syntax with your favorite package manager.
342
+ ```shell
343
+ # npm
344
+ npm install -D eslint @moso/eslint-config
345
+
346
+ # pnpm
347
+ pnpm add -D eslint @moso/eslint-config
319
348
 
320
- ```bash
349
+ # bun
321
350
  bun add -d eslint @moso/eslint-config
322
351
  ```
323
352
 
324
- Create `eslint.config.js` in the root of your project:
353
+ Create a `eslint.config.*` in the root of your project. You can use `.js` or `.ts`; `.mjs`/`.cjs` also works.
325
354
 
326
- ```js
327
- // eslint.config.js
355
+ > [!NOTE]
356
+ > If you use `.ts`, you will need to install [`jiti`](https://unjs.io/packages/jiti) as a developer dependency:
357
+ > ```shell
358
+ > # npm
359
+ > npm install -D jiti
360
+ >
361
+ > # pnpm
362
+ > pnpm add -D jiti
363
+ >
364
+ > # bun
365
+ > bun add -d jiti
366
+ > ```
367
+
368
+ ```ts
369
+ // eslint.config.*
328
370
  import moso from '@moso/eslint-config';
329
371
 
330
372
  export default moso();
@@ -335,10 +377,10 @@ export default moso();
335
377
  Combine with legacy config:
336
378
  </summary>
337
379
 
338
- If you still use some configs from the legacy `eslintrc` format, you can use the [`@eslint/eslintrc`](https://npmjs.com/package/@eslint/eslintrc) package to convert them to the flat config.
380
+ If you still use some configs from the legacy `.eslintrc` format, you can use the [`@eslint/eslintrc`](https://npmjs.com/package/@eslint/eslintrc) package to convert them to the flat config.
339
381
 
340
- ```js
341
- // eslint.config.js
382
+ ```ts
383
+ // eslint.config.*
342
384
  import moso from '@moso/eslint-config';
343
385
  import { FlatCompat } from '@eslint/eslintrc';
344
386
 
@@ -434,8 +476,8 @@ Since v1.0.0, this config has been migrated to [ESLint Flat config](https://esli
434
476
 
435
477
  Normally you only need to import the `moso` preset:
436
478
 
437
- ```js
438
- // eslint.config.js
479
+ ```ts
480
+ // eslint.config.*
439
481
  import moso from '@moso/eslint-config';
440
482
 
441
483
  export default moso();
@@ -445,8 +487,8 @@ export default moso();
445
487
 
446
488
  Configure integrations by passing options to the main function:
447
489
 
448
- ```js
449
- // eslint.config.js
490
+ ```ts
491
+ // eslint.config.*
450
492
  import moso from '@moso/eslint-config';
451
493
 
452
494
  export default moso({
@@ -465,6 +507,14 @@ export default moso({
465
507
  typescript: true,
466
508
  vue: true,
467
509
 
510
+ // JavaScript Baseline (enabled by default, reported as warnings)
511
+ baseline: false, // disable entirely
512
+ baseline: 'newly', // 'widely' (default), 'newly', or a year like 2023
513
+ baseline: {
514
+ baseline: 'widely',
515
+ ignoreFeatures: [], // skip web-features by ID, supports RegExp via '/.../'
516
+ },
517
+
468
518
  // JSDoc support
469
519
  jsdoc: true, // enable explicitly with reasonable defaults
470
520
 
@@ -484,8 +534,8 @@ export default moso({
484
534
 
485
535
  Pass additional flat config objects as arguments. Rules are scoped to specific file types:
486
536
 
487
- ```js
488
- // eslint.config.js
537
+ ```ts
538
+ // eslint.config.*
489
539
  import moso from '@moso/eslint-config';
490
540
 
491
541
  export default moso(
@@ -515,8 +565,8 @@ export default moso(
515
565
 
516
566
  The config returns a `FlatConfigComposer` object from [`eslint-flat-config-utils`](https://github.com/antfu/eslint-flat-config-utils#composer), enabling chainable methods:
517
567
 
518
- ```js
519
- // eslint.config.js
568
+ ```ts
569
+ // eslint.config.*
520
570
  import moso from '@moso/eslint-config';
521
571
 
522
572
  export default moso()
@@ -539,7 +589,7 @@ export default moso()
539
589
 
540
590
  You can import and compose individual configs directly. Only use this if you need granular control:
541
591
 
542
- ```js
592
+ ```ts
543
593
  import {
544
594
  combine,
545
595
  comments,
@@ -584,8 +634,8 @@ Disabled by default, will have to be enabled manually.
584
634
 
585
635
  There are many ways JSDoc support can be configured. However, the most simple way is just enabling it which will use very reasonable defaults:
586
636
 
587
- ```js
588
- // eslint.config.js
637
+ ```ts
638
+ // eslint.config.*
589
639
  import moso from '@moso/eslint-config';
590
640
 
591
641
  export default moso({
@@ -597,7 +647,7 @@ This will enable the preset `recommended`, which is recommended starting rules f
597
647
 
598
648
  Individual rules can be tweaked with the `overrides` property:
599
649
 
600
- ```js
650
+ ```ts
601
651
  {
602
652
  jsdoc: {
603
653
  overrides: {
@@ -618,8 +668,8 @@ Framework support is auto-detected based on installed packages, but can be enabl
618
668
 
619
669
  Auto-detected if you have [Astro](https://astro.build) installed. Enable explicitly:
620
670
 
621
- ```js
622
- // eslint.config.js
671
+ ```ts
672
+ // eslint.config.*
623
673
  import moso from '@moso/eslint-config';
624
674
 
625
675
  export default moso({
@@ -629,8 +679,15 @@ export default moso({
629
679
 
630
680
  Install dependencies when prompted, or manually:
631
681
 
632
- ```bash
633
- bun add --dev eslint-plugin-astro astro-eslint-parser
682
+ ```shell
683
+ # npm
684
+ npm install -D eslint-plugin-astro astro-eslint-parser
685
+
686
+ # pnpm
687
+ pnpm add -D eslint-plugin-astro astro-eslint-parser
688
+
689
+ # Bun
690
+ bun add -d eslint-plugin-astro astro-eslint-parser
634
691
  ```
635
692
 
636
693
  > [!NOTE]
@@ -641,8 +698,8 @@ bun add --dev eslint-plugin-astro astro-eslint-parser
641
698
 
642
699
  Auto-detected if you have React, Next.js, Nextra, Remix, Gatsby, or the `@astrojs/react` Astro framework integration installed. Enable explicitly:
643
700
 
644
- ```js
645
- // eslint.config.js
701
+ ```ts
702
+ // eslint.config.*
646
703
  import moso from '@moso/eslint-config';
647
704
 
648
705
  export default moso({
@@ -652,7 +709,14 @@ export default moso({
652
709
 
653
710
  Install dependencies when prompted, or manually:
654
711
 
655
- ```bash
712
+ ```shell
713
+ # npm
714
+ npm install -D @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugin-react-refresh eslint-plugin-react-you-might-not-need-an-effect
715
+
716
+ # pnpm
717
+ pnpm add -D @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugin-react-refresh eslint-plugin-react-you-might-not-need-an-effect
718
+
719
+ # Bun
656
720
  bun add --dev @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugin-react-refresh eslint-plugin-react-you-might-not-need-an-effect
657
721
  ```
658
722
 
@@ -660,8 +724,8 @@ bun add --dev @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugi
660
724
 
661
725
  Auto-detected if you have Vue, Nuxt, VitePress, or the `@astrojs/vue` Astro framework intefration installed. Enable explicitly:
662
726
 
663
- ```js
664
- // eslint.config.js
727
+ ```ts
728
+ // eslint.config.*
665
729
  import moso from '@moso/eslint-config';
666
730
 
667
731
  export default moso({
@@ -671,7 +735,14 @@ export default moso({
671
735
 
672
736
  Install dependencies when prompted, or manually (the Vue parser and SFC processors are already bundled as dependencies):
673
737
 
674
- ```bash
738
+ ```shell
739
+ # npm
740
+ npm install -D eslint-plugin-vue
741
+
742
+ # pnpm
743
+ pnpm add -D eslint-plugin-vue
744
+
745
+ # Bun
675
746
  bun add --dev eslint-plugin-vue
676
747
  ```
677
748
 
@@ -682,23 +753,23 @@ bun add --dev eslint-plugin-vue
682
753
 
683
754
  You can optionally enable [typed linting](https://typescript-eslint.io/getting-started/typed-linting). These are also known as "rules that require types", or simply "type-aware rules". This enables for much deeper insight into your code.
684
755
 
685
- You enable them by passing the path of your `tsconfig.json` to the `projectRoot` option.
756
+ You enable them by passing your project's root directory to the `projectRoot` option inside `typescript`.
686
757
 
687
758
  > [!WARNING]
688
759
  > Enabling these rules will come with a slight performance cost, [explained here](https://typescript-eslint.io/getting-started/typed-linting/#performance).
689
760
  >
690
761
  > To make things even more complicated, if you have enabled typed linting but disabled [`@stylistic`](https://eslint.style), it will also disable the type-aware rules [considered stylistic](https://typescript-eslint.io/rules/?=stylistic-typeInformation).
691
762
 
692
- ```js
693
- // eslint.config.js
763
+ ```ts
764
+ // eslint.config.*
694
765
  import moso from '@moso/eslint-config';
695
766
 
696
767
  export default moso(
697
768
  {
698
- projectRoot: import.meta.dirname,
699
-
700
- // If you wish to override any of these rules, use `overridesTypeAware`:
701
769
  typescript: {
770
+ projectRoot: import.meta.dirname,
771
+
772
+ // If you wish to override any of these rules, use `overridesTypeAware`:
702
773
  overridesTypeAware: {
703
774
  '@typescript-eslint/no-deprecated': 'off',
704
775
  },
@@ -714,14 +785,14 @@ export default moso(
714
785
 
715
786
  You can disable the type-aware layer entirely, or exclude certain globs or specific files from it:
716
787
 
717
- ```js
718
- // eslint.config.js
788
+ ```ts
789
+ // eslint.config.*
719
790
  import moso from '@moso/eslint-config';
720
791
 
721
792
  export default moso({
722
- projectRoot: import.meta.dirname,
723
-
724
793
  typescript: {
794
+ projectRoot: import.meta.dirname,
795
+
725
796
  // Kill switch: keep regular TypeScript rules, drop the type-aware layer
726
797
  disableTypeAwareRules: true,
727
798
 
@@ -744,8 +815,8 @@ Some rules are deemed as 'non-fixable' when inside your editor with ESLint integ
744
815
 
745
816
  Before v1.0.0, they used to be hard disabled. But with a [helper](https://github.com/antfu/eslint-flat-config-utils#composerdisablerulesfix), they are now just marked as 'non-fixable'. They are re-applied when you're linting through a terminal, or by using [Lint Staged](#lint-staged).
746
817
 
747
- ```js
748
- // eslint.config.js
818
+ ```ts
819
+ // eslint.config.*
749
820
  import moso from '@moso/eslint-config';
750
821
 
751
822
  export default moso({
@@ -757,10 +828,10 @@ export default moso({
757
828
 
758
829
  Linting and auto-fixing before every commit is easy, you just add the following to your `package.json`:
759
830
 
760
- ```json
831
+ ```jsonc
761
832
  {
762
833
  "simple-git-hooks": {
763
- "pre-commit": "bunx lint-staged"
834
+ "pre-commit": "npmx lint-staged" // or pnx/bunx
764
835
  },
765
836
  "nano-staged": {
766
837
  "*": "eslint --fix"
@@ -770,11 +841,23 @@ Linting and auto-fixing before every commit is easy, you just add the following
770
841
 
771
842
  and then
772
843
 
773
- ```bash
774
- bun add --dev nano-staged simple-git-hooks
844
+ ```shell
845
+ # npm
846
+ npm install -D nano-staged simple-git-hooks
847
+
848
+ # pnpm
849
+ pnpm add -D nano-staged simple-git-hooks
850
+
851
+ # Bun
852
+ bun add -d nano-staged simple-git-hooks
853
+
854
+
855
+ # to activate the hooks:
856
+ npmx simple-git-hooks # npm
857
+
858
+ pnx simple-git-hooks # pnpm
775
859
 
776
- # to activate the hooks
777
- bunx simple-git-hooks
860
+ bunx simple-git-hooks # npm
778
861
  ```
779
862
 
780
863
  ## FAQ
@@ -789,17 +872,24 @@ Even though ESLint v10 supports Node.js `v20.19.0` (as of current status), this
789
872
 
790
873
  TypeScript 7.0 [does not ship a compiler API](https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/) (a new one supposedly arrives in 7.1), so [`typescript-eslint`](https://typescript-eslint.io) - and therefore all TypeScript linting in this config - cannot run against it. TypeScript's supported setup is running TypeScript 6 side-by-side through the [`@typescript/typescript6`](https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/#running-side-by-side-with-typescript-6.0) compatibility package, aliased so tooling that imports `typescript` keeps working:
791
874
 
792
- ```bash
793
- bun add --dev typescript@npm:@typescript/typescript6
875
+ ```shell
876
+ # npm
877
+ npm install -D typescript@npm:@typescript/typescript6
878
+
879
+ # pnpm
880
+ pnpm add -D typescript@npm:@typescript/typescript6
881
+
882
+ # Bun
883
+ bun add -d typescript@npm:@typescript/typescript6
794
884
  ```
795
885
 
796
886
  Optionally keep TypeScript 7's own `tsc` around as well:
797
887
 
798
- ```jsonc
888
+ ```json
799
889
  {
800
890
  "devDependencies": {
801
891
  "@typescript/native": "npm:typescript@^7.0.2",
802
- "typescript": "npm:@typescript/typescript6@^6.0.2"
892
+ "typescript": "npm:@typescript/typescript6@^6.0.3"
803
893
  }
804
894
  }
805
895
  ```
@@ -808,12 +898,15 @@ With the alias in place, this config works unchanged. Without it, the config det
808
898
 
809
899
  **Keep in mind**, this is temporary until an API is provided by TypeScript for v7.
810
900
 
901
+ > [!NOTE]
902
+ > As per v8.65.0, `@typescript-eslint` will also display a warning if TypeScript v7 is detected.
903
+
811
904
  ### I want it less opinionated
812
905
 
813
906
  No problem. I've extracted the things that I've deemed *very opinionated* in each integration, and made a setting that helps you disable all of it in one go.
814
907
 
815
- ```js
816
- // eslint.config.js
908
+ ```ts
909
+ // eslint.config.*
817
910
  import moso from '@moso/eslint-config';
818
911
 
819
912
  export default moso({
@@ -824,7 +917,7 @@ export default moso({
824
917
  > [!NOTE]
825
918
  > The above will also disable `functional` and `perfectionist` completely. If you want to keep these enabled, you'll have to re-enable them explicitly, as demonstrated below
826
919
 
827
- ```js
920
+ ```ts
828
921
  {
829
922
  // Disable opinionated rules
830
923
  lessOpinionated: true,
@@ -860,9 +953,9 @@ No worries, you can always override the rules locally in your project to fit you
860
953
 
861
954
  This ESLint config is heavily inspired by (and uses some of the same logic of):
862
955
 
863
- \- [@antfu/eslint-config](https://github.com/antfu/eslint-config)
864
- \- [@rebeccastevens/eslint-config](https://github.com/RebeccaStevens/eslint-config-rebeccastevens)
865
- \- [@eslint-sukka/eslint-config](https://github.com/SukkaW/eslint-config-sukka)
956
+ \- [@antfu/eslint-config](https://github.com/antfu/eslint-config)
957
+ \- [@rebeccastevens/eslint-config](https://github.com/RebeccaStevens/eslint-config-rebeccastevens)
958
+ \- [@eslint-sukka/eslint-config](https://github.com/SukkaW/eslint-config-sukka)
866
959
 
867
960
  [Anthony Fu](https://github.com/antfu)'s config inspired me to take the journey, but this project has since evolved into a personal project. Especially Rebecca's config and strict(er) approach to coding has pushed me towards a stricter coding environment, with [Functional](https://github.com/eslint-functional/eslint-plugin-functional) and [Azat](https://github.com/azat-io)'s [Perfectionist](https://perfectionist.dev) and [De Morgan](https://github.com/azat-io/eslint-plugin-de-morgan) enabled.
868
961