1
- // @ts -check
2
- import { fixupConfigRules , fixupPluginRules } from '@eslint/compat' ;
3
- import { FlatCompat } from '@eslint/eslintrc' ;
1
+ import cspellPlugin from '@cspell/eslint-plugin' ;
4
2
import eslint from '@eslint/js' ;
3
+ // @ts -expect-error eslint-plugin-next doesn't come with TypeScript definitions
4
+ import nextPlugin from '@next/eslint-plugin-next' ;
5
5
import eslintConfigPrettier from 'eslint-config-prettier' ;
6
- import reactPlugin from 'eslint-plugin-react' ;
6
+ import react from 'eslint-plugin-react' ;
7
7
import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort' ;
8
8
import globals from 'globals' ;
9
9
import tsEslint from 'typescript-eslint' ;
10
10
import { fileURLToPath } from 'url' ;
11
11
12
- const tsconfigRootDir = fileURLToPath ( new URL ( '.' , import . meta. url ) ) ,
13
- flatCompat = new FlatCompat ( ) ;
12
+ /**
13
+ * @see {@link https://github.com/typescript-eslint/typescript-eslint/blob/main/eslint.config.mjs }
14
+ * @see {@link https://github.com/vercel/next.js/issues/71763#issuecomment-2476838298 }
15
+ */
16
+
17
+ const tsconfigRootDir = fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
14
18
15
19
export default tsEslint . config (
16
20
// register all of the plugins up-front
17
21
{
18
22
plugins : {
19
- '@typescript-eslint' : tsEslint . plugin ,
20
- react : fixupPluginRules ( reactPlugin ) ,
21
23
'simple-import-sort' : simpleImportSortPlugin ,
24
+ '@typescript-eslint' : tsEslint . plugin ,
25
+ react,
26
+ '@next/next' : nextPlugin ,
27
+ '@cspell' : cspellPlugin ,
22
28
} ,
23
29
} ,
24
30
{
@@ -29,7 +35,6 @@ export default tsEslint.config(
29
35
// extends ...
30
36
eslint . configs . recommended ,
31
37
...tsEslint . configs . recommended ,
32
- ...fixupConfigRules ( flatCompat . extends ( 'plugin:@next/next/core-web-vitals' ) ) ,
33
38
34
39
// base config
35
40
{
@@ -42,13 +47,33 @@ export default tsEslint.config(
42
47
} ,
43
48
} ,
44
49
rules : {
50
+ ...nextPlugin . configs . recommended . rules ,
51
+ ...nextPlugin . configs [ 'core-web-vitals' ] . rules ,
52
+ 'arrow-body-style' : [ 'error' , 'as-needed' ] ,
45
53
'no-empty-pattern' : 'warn' ,
54
+ 'no-console' : [ 'error' , { allow : [ 'warn' , 'error' , 'info' ] } ] ,
55
+ 'no-restricted-syntax' : [
56
+ 'error' ,
57
+ {
58
+ selector : "TSPropertySignature[key.name='children']" ,
59
+ message : 'Please use PropsWithChildren<T> instead of defining children manually' ,
60
+ } ,
61
+ ] ,
62
+ 'consistent-return' : 'warn' ,
63
+ 'prefer-destructuring' : [ 'error' , { object : true , array : true } ] ,
64
+ // simple-import-sort
46
65
'simple-import-sort/exports' : 'error' ,
47
66
'simple-import-sort/imports' : 'error' ,
67
+ // typescript
48
68
'@typescript-eslint/no-unused-vars' : 'warn' ,
49
69
'@typescript-eslint/no-explicit-any' : 'warn' ,
50
70
'@typescript-eslint/no-empty-object-type' : 'off' ,
51
71
'@typescript-eslint/no-unsafe-declaration-merging' : 'warn' ,
72
+ '@typescript-eslint/consistent-type-definitions' : [ 'error' , 'interface' ] ,
73
+ // react
74
+ 'react/no-unescaped-entities' : 'off' ,
75
+ 'react/self-closing-comp' : [ 'error' , { component : true , html : true } ] ,
76
+ 'react/jsx-curly-brace-presence' : [ 'error' , { props : 'never' , children : 'never' } ] ,
52
77
'react/jsx-no-target-blank' : 'warn' ,
53
78
'react/jsx-sort-props' : [
54
79
'error' ,
@@ -58,18 +83,18 @@ export default tsEslint.config(
58
83
noSortAlphabetically : true ,
59
84
} ,
60
85
] ,
86
+ // next
61
87
'@next/next/no-sync-scripts' : 'warn' ,
62
- } ,
63
- } ,
64
- {
65
- files : [ '**/*.js' ] ,
66
- extends : [ tsEslint . configs . disableTypeChecked ] ,
67
- rules : {
68
- // turn off other type-aware rules
69
- '@typescript-eslint/internal/no-poorly-typed-ts-props' : 'off' ,
70
-
71
- // turn off rules that don't apply to JS code
72
- '@typescript-eslint/explicit-function-return-type' : 'off' ,
88
+ // spellchecker
89
+ '@cspell/spellchecker' : [
90
+ 'warn' ,
91
+ {
92
+ cspell : {
93
+ language : 'en' ,
94
+ dictionaries : [ 'typescript' , 'node' , 'html' , 'css' , 'bash' , 'npm' , 'pnpm' ] ,
95
+ } ,
96
+ } ,
97
+ ] ,
73
98
} ,
74
99
} ,
75
100
eslintConfigPrettier ,
0 commit comments