-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheslint.config.js
278 lines (275 loc) · 8.6 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// @ts-check
/* eslint-disable filename-export/match-default-export */
import {fixupPluginRules} from '@eslint/compat';
import eslint from '@eslint/js';
import pluginTypescript from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import pluginFilenameExport from 'eslint-plugin-filename-export';
import pluginImport from 'eslint-plugin-import';
import pluginNoRelativeImportPaths from 'eslint-plugin-no-relative-import-paths';
import pluginPrettier from 'eslint-plugin-prettier';
import configPrettierRecommended from 'eslint-plugin-prettier/recommended';
import configReactJSXRuntime from 'eslint-plugin-react/configs/jsx-runtime.js';
import configReactRecommended from 'eslint-plugin-react/configs/recommended.js';
import pluginReactHooks from 'eslint-plugin-react-hooks';
import pluginReactRefresh from 'eslint-plugin-react-refresh';
import tailwindPlugin from 'eslint-plugin-tailwindcss';
import eslintTS from 'typescript-eslint';
const eslint_config = [
eslint.configs.recommended,
...eslintTS.configs.recommended,
...eslintTS.configs.stylistic,
...tailwindPlugin.configs['flat/recommended'],
configReactRecommended,
configReactJSXRuntime,
configPrettierRecommended,
{
files: ['**/*.{js,ts,jsx,tsx}'],
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,
'filename-export': pluginFilenameExport,
'no-relative-import-paths': pluginNoRelativeImportPaths,
'react-hooks': fixupPluginRules(pluginReactHooks),
'react-refresh': pluginReactRefresh,
},
rules: {
...pluginReactHooks.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: 'toolbar/**',
group: 'internal',
},
],
'newlines-between': 'always',
alphabetize: {
order: 'asc' /* sort in ascending order. Options: ['ignore', 'asc', 'desc'] */,
caseInsensitive: true /* ignore case. Options: [true, false] */,
},
},
],
/**
* When there is only a single export from a module, prefer using default export over named export.
* @see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/prefer-default-export.md
*/
'import/prefer-default-export': [
'error',
{
target: 'single',
},
],
/**
* Prevent exporting anonymous functions, classes, and objects.
* @see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-anonymous-default-export.md
*/
'import/no-anonymous-default-export': [
'error',
{
allowArray: false,
allowArrowFunction: false,
allowAnonymousClass: false,
allowAnonymousFunction: false,
allowCallExpression: true,
allowLiteral: false,
allowObject: false,
},
],
/**
* Enforces that filenames match the name of the default export.
* @see https://github.com/ekwoka/eslint-plugin-filename-export?tab=readme-ov-file#rules
*/
'filename-export/match-default-export': [
'error',
{
casing: 'strict',
stripextra: false,
},
],
/**
* Reports use of an exported name as the locally imported name of a default export.
* https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-named-as-default.md
*
* TODO: need to update the plugin once it suppots ESLint v9
* Depends on https://github.com/import-js/eslint-plugin-import/pull/2996
*/
// 'import/no-named-as-default': 'error',
/**
* 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', {}],
/**
* Enforce absolute imports within src/lib/*
* https://www.npmjs.com/package/eslint-plugin-no-relative-import-paths
*/
'no-relative-import-paths/no-relative-import-paths': [
'error',
{
rootDir: 'src/lib',
prefix: 'toolbar',
},
],
'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', 'interface'],
/**
* 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',
},
],
},
},
/* Allow devDependencies imports for tests and config files */
{
files: [
'**/*.spec.*',
'**/testUtils/*.{js,jsx,ts,tsx}',
'*/*.{js,jsx,ts,tsx}',
'**/setupTests.ts',
'**/*.stories.*',
'*.config.{js,ts}',
],
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: ['**/env/**'],
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.',
},
],
},
],
},
},
/* Disable `raw` directory imports form any file except types */
{
files: ['src/**/*.{js,jsx,ts,tsx}'],
ignores: ['src/lib/sentryApi/types/**'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['toolbar/sentryApi/raw/**'],
message: 'Imports from `toolbar/sentryApi/types/*` instead.',
},
],
},
],
},
},
/**
* Disable rules of hooks for story files in order to have better story code display.
* @see TemplateName.stories.tsx
*/
{
files: ['**/*.stories.*'],
rules: {
'react-hooks/rules-of-hooks': 'off',
},
},
{
ignores: ['**/*.snap', 'dist/**', 'bin/**', 'mock/**', '*.config.{js,ts}'],
},
];
export default eslint_config;