-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.js
197 lines (195 loc) · 6.89 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// @ts-check
import eslint from '@eslint/js';
import eslintTS from 'typescript-eslint';
import tsParser from '@typescript-eslint/parser';
import pluginImport from 'eslint-plugin-import';
import pluginSSRFriendly from 'eslint-plugin-ssr-friendly';
import pluginPrettier from 'eslint-plugin-prettier';
import pluginTypescript from '@typescript-eslint/eslint-plugin';
import pluginReactRefresh from 'eslint-plugin-react-refresh';
import configReactRecommended from 'eslint-plugin-react/configs/recommended.js';
import configReactJSXRuntime from 'eslint-plugin-react/configs/jsx-runtime.js';
import pluginReactHooks from 'eslint-plugin-react-hooks';
import {fixupPluginRules} from '@eslint/compat';
import configPrettierRecommended from 'eslint-plugin-prettier/recommended';
import pluginSSR from 'eslint-plugin-ssr-friendly';
export default [
eslint.configs.recommended,
...eslintTS.configs.recommended,
...eslintTS.configs.stylistic,
configReactRecommended,
configReactJSXRuntime,
configPrettierRecommended,
{
files: ['**/*.{js,ts,tsx,cjs}'],
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaFeatures: {modules: true},
ecmaVersion: 'latest',
project: './tsconfig.linter.json',
},
},
settings: {
react: {
version: 'detect',
},
},
plugins: {
import: pluginImport,
prettier: pluginPrettier,
'@typescript-eslint': pluginTypescript,
'react-refresh': pluginReactRefresh,
'react-hooks': fixupPluginRules(pluginReactHooks),
'ssr-friendly': fixupPluginRules(pluginSSRFriendly),
},
rules: {
...pluginReactHooks.configs.recommended.rules,
...pluginSSR.configs.recommended.rules,
/**
* Allow empty arrow functions `() => {}`, while keeping other empty functions restricted
* @see https://eslint.org/docs/latest/rules/no-empty-function#allow-arrowfunctions
*/
'@typescript-eslint/no-empty-function': [
'error',
{allow: ['arrowFunctions']},
],
'@typescript-eslint/ban-ts-comment': 1,
'no-const-assign': 'error',
/** Restrict imports from devDependencies since they are not included in library build. peerDependencies are ok */
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: false,
peerDependencies: true,
},
],
/**
* Enforce import order with empty lines between import group
* @see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md
*/
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
['parent', 'sibling', 'index'],
],
pathGroups: [
{
pattern: '@/**',
group: 'internal',
},
],
'newlines-between': 'always',
},
],
/**
* Disallow combined module and type imports like this `import React, {FC} from 'react'`.
* Eslint will try to split into type and module imports instead
* @see https://typescript-eslint.io/rules/consistent-type-imports/
*/
'@typescript-eslint/consistent-type-imports': 'error',
'import/no-cycle': 'error',
'prettier/prettier': [
'error',
{
semi: true,
singleQuote: true,
jsxSingleQuote: false,
trailingComma: 'es5',
bracketSpacing: false,
jsxBracketSameLine: true,
arrowParens: 'avoid',
},
],
/* Required by vite */
'react-refresh/only-export-components': ['warn', {allowConstantExport: true}],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
/**
* Allow unused variables with names stating with '_'
* @see https://eslint.org/docs/latest/rules/no-unused-vars
* @see https://typescript-eslint.io/rules/no-unused-vars/
*/
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
ignoreRestSiblings: true,
args: 'after-used',
},
],
'react/prop-types': 0,
},
},
/* Allow devDependencies imports for tests and config files */
{
files: [
'**/*.spec.*',
'**/libraryAPITestCase.tsx',
'**/testUtils/*.{js,jsx,ts,tsx}',
'*/*.{js,jsx,ts,tsx}',
'**/setupTests.ts',
'**/*.stories.*',
'*.config.{js,ts}',
'**/env/**/*.*',
],
plugins: {
import: pluginImport,
},
rules: {
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
peerDependencies: true,
},
],
},
},
/* Disable `environment` directory imports for library files */
{
files: ['src/lib/**/*.{js,jsx,ts,tsx}'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['**/environment/**'],
message:
'Imports from environment directory are forbidden in the library files.',
},
],
},
],
},
},
/* Disable `template` directory imports for all files */
{
files: ['src/**/*.{js,jsx,ts,tsx}'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['**/templates/**'],
message: 'Imports from templates directory are forbidden.',
},
],
},
],
},
},
{
ignores: ['**/*.{snap,css,jpg}'],
},
];