-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy patheslint.config.mjs
132 lines (127 loc) · 3.98 KB
/
eslint.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import cspellPlugin from '@cspell/eslint-plugin';
import eslint from '@eslint/js';
// @ts-expect-error eslint-plugin-next doesn't come with TypeScript definitions
import nextPlugin from '@next/eslint-plugin-next';
import stylistic from '@stylistic/eslint-plugin';
import eslintConfigPrettier from 'eslint-config-prettier';
import react from 'eslint-plugin-react';
import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort';
import globals from 'globals';
import tsEslint from 'typescript-eslint';
import { fileURLToPath } from 'url';
/**
* @see{@link https://github.com/typescript-eslint/typescript-eslint/blob/main/eslint.config.mjs}
* @see{@link https://github.com/vercel/next.js/issues/71763#issuecomment-2476838298}
*/
const tsconfigRootDir = fileURLToPath(new URL('.', import.meta.url));
export default tsEslint.config(
// register all of the plugins up-front
{
plugins: {
'@cspell': cspellPlugin,
'@stylistic': stylistic,
'simple-import-sort': simpleImportSortPlugin,
'@typescript-eslint': tsEslint.plugin,
react,
'@next/next': nextPlugin,
},
},
{
// config with just ignores is the replacement for `.eslintignore`
ignores: [
'**/node_modules/**',
'**/public/**',
'**/.next/**',
'.github/scripts/**',
],
},
// extends ...
eslint.configs.recommended,
...tsEslint.configs.recommended,
// base config
{
languageOptions: {
globals: { ...globals.es2020, ...globals.browser, ...globals.node },
parserOptions: {
projectService: true,
tsconfigRootDir,
warnOnUnsupportedTypeScriptVersion: false,
},
},
rules: {
// spellchecker
'@cspell/spellchecker': [
'warn',
{
cspell: {
language: 'en',
dictionaries: [
'typescript',
'node',
'html',
'css',
'bash',
'npm',
'pnpm',
],
},
},
],
// stylistic
'@stylistic/padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
{ blankLine: 'always', prev: 'directive', next: '*' },
{ blankLine: 'any', prev: 'directive', next: 'directive' },
{
blankLine: 'always',
prev: '*',
next: ['enum', 'interface', 'type'],
},
],
'arrow-body-style': ['error', 'as-needed'],
'no-empty-pattern': 'warn',
'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
'no-restricted-syntax': [
'error',
{
selector: "TSPropertySignature[key.name='children']",
message:
'Please use PropsWithChildren<T> instead of defining children manually',
},
],
'consistent-return': 'warn',
'prefer-destructuring': ['error', { object: true, array: true }],
// simple-import-sort
'simple-import-sort/exports': 'error',
'simple-import-sort/imports': 'error',
// TypeScript
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'warn',
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
// React
'react/no-unescaped-entities': 'off',
'react/self-closing-comp': ['error', { component: true, html: true }],
'react/jsx-curly-brace-presence': [
'error',
{ props: 'never', children: 'never' },
],
'react/jsx-no-target-blank': 'warn',
'react/jsx-sort-props': [
'error',
{
reservedFirst: true,
callbacksLast: true,
noSortAlphabetically: true,
},
],
// Next.js
...nextPlugin.configs.recommended.rules,
...nextPlugin.configs['core-web-vitals'].rules,
'@next/next/no-sync-scripts': 'warn',
},
},
eslintConfigPrettier,
);