-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.js
177 lines (164 loc) · 4.14 KB
/
eslint.config.js
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import js from '@eslint/js';
import ts from 'typescript-eslint';
import jsdoc from 'eslint-plugin-jsdoc';
import prettier from 'eslint-plugin-prettier/recommended';
import vitest from 'eslint-plugin-vitest';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import unicorn from 'eslint-plugin-unicorn';
/**
* most of the configurations are glob-based,
* use https://globster.xyz/ to test your glob pattern
*/
/**
* We export an array of different config chunks.
* Eslint will merge them into a single object.
*/
export default [
/**
* single config with eslint recommended rules.
*/
js.configs.recommended,
/**
* ts.config.recommended is array of the configs:
* [0] is typescript-eslint/base
* [1] is typescript-eslint/eslint-recommended
* [2] is typescript-eslint/strict
*
* We want to make sure that we apply these rules only for typescript files.
*/
...ts.configs.recommended.map((config) => ({
...config,
files: ['**/*.{ts,tsx}'],
})),
/**
* single config with jsdoc recommended rules.
*/
jsdoc.configs['flat/recommended-typescript'],
/**
* single config with prettier recommended rules.
*/
prettier,
/**
* single config with vitest recommended rules
*/
{
files: ['**/test/**/*.ts'],
plugins: {
vitest,
},
rules: {
// you can also use vitest.configs.all.rules to enable all rules
...vitest.configs.recommended.rules,
},
},
/**
* list of ignores:
*/
{
ignores: [
'node_modules/**',
'**/node_modules/**',
'**/dist/**',
'**/dist-api-reference/**',
'**/dist-demo/**',
'**/coverage/**',
],
},
/**
* language options
* please define globals or parser options here
*/
{
languageOptions: {
parserOptions: {
project: './tsconfig.json',
ecmaFeatures: {
jsx: true,
},
},
ecmaVersion: 'latest',
sourceType: 'module',
globals: {
...globals.browser,
...globals.node,
},
},
},
/**
* typescript specific rules:
*/
{
files: ['**/*.{ts,tsx}'],
rules: {
'@typescript-eslint/explicit-member-accessibility': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
'@typescript-eslint/consistent-generic-constructors': 'error',
'@typescript-eslint/consistent-indexed-object-style': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/no-base-to-string': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-unused-vars': ['error', { caughtErrors: 'none' }],
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'memberLike',
modifiers: ['private'],
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
trailingUnderscore: 'require',
},
{
selector: 'memberLike',
modifiers: ['protected'],
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
trailingUnderscore: 'require',
},
],
},
},
/**
* TSX rules
* mainly for demo pages
*/
{
files: ['**/*.tsx'],
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
},
},
/**
* Other rules:
*/
{
rules: {
'no-console': 'error',
'no-unused-vars': ['error', { caughtErrors: 'none' }],
'jsdoc/require-returns': 'off',
},
},
{
files: ['**/*.{ts,js}'],
plugins: {
unicorn,
},
rules: {
'unicorn/filename-case': [
'error',
{
case: 'kebabCase',
},
],
},
},
];