Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
257 lines (228 loc) · 10.9 KB
/
Copy pathindex.js
File metadata and controls
257 lines (228 loc) · 10.9 KB
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
"use strict"
module.exports = {
configs: {
default: {
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
ignorePatterns: [".eslintrc.*js"],
extends: [
// https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/index.js
"airbnb",
// https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/hooks.js
"airbnb/hooks",
// Turns off rules that are enabled by `eslint-config-airbnb` that are not relevant in React 18 or higher: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#eslint
// https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/index.js#L171-L185
"plugin:react/jsx-runtime",
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended.ts
"plugin:@typescript-eslint/recommended",
// https://github.com/prettier/eslint-plugin-prettier/blob/master/eslint-plugin-prettier.js
"plugin:prettier/recommended",
],
plugins: [
// https://github.com/gund/eslint-plugin-deprecation
"deprecation",
],
rules: {
// Enforce explicit function return types
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/explicit-function-return-type.md
"@typescript-eslint/explicit-function-return-type": [
"error",
{
// Allow expressions without explicit function return types
allowExpressions: true,
},
],
// Disallow empty functions
// https://typescript-eslint.io/rules/no-empty-function
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": "error",
// Disallow empty interfaces
// https://typescript-eslint.io/rules/no-empty-interface
"@typescript-eslint/no-empty-interface": "error",
// Disallow inferrable types
// https://typescript-eslint.io/rules/no-inferrable-types
"@typescript-eslint/no-inferrable-types": "error",
// Disallow variable declarations from shadowing variables declared in the outer scope, with support for TypeScript features
// https://typescript-eslint.io/rules/no-shadow
"@typescript-eslint/no-shadow": "error",
// Warn against using deprecated code
// Not disallowed because code can be deprecated at any moment and it should not break CI
// https://github.com/gund/eslint-plugin-deprecation
"deprecation/deprecation": "warn",
// Disallow using file extensions in imports
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md
"import/extensions": [
"error",
"never",
// Enforce file extensions in these file types
{ svg: "always", json: "always", png: "always" },
],
// Forbid default exports
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-default-export.md
"import/no-default-export": "error",
// Disallow using extraneous dependencies
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-extraneous-dependencies.md
"import/no-extraneous-dependencies": [
"error",
{
// Usage of dev dependencies are allowed in these dev related files and folders
devDependencies: [
"src/lib/test.{ts,tsx}", // test helper
"**/__tests__/**", // test folder
"**/*.test.{ts,tsx}", // test file
"**/.eslintrc.js", // eslint config
"**/setupTests.ts", // setup tests file
"**/vite.config.{ts,mts}", // vite config
"**/vitest.config.{ts,mts}", // vitest config
"**/rollup.config.{js,mjs}", // rollup config
"**/*.stories.tsx", // storybook story files
"**/*.cy.ts", // cypress test files
"cypress.config.ts", // cypress config file
],
},
],
// Enabled by `eslint-config-airbnb`: https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/imports.js#L35-L37
// Disabled since we're not using Node or Webpack as module bundler
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unresolved.md
"import/no-unresolved": "off",
// Enforce consistent ordering of imports. Used in conjunction with `sort-imports`.
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md
"import/order": [
"error",
{
// Sort in ascending alphabetical order ignoring letter casing
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
],
// Enabled by `eslint-config-airbnb`: https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/imports.js#L155-L157
// Disabled becaise named imports are always preferred
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/prefer-default-export.md
"import/prefer-default-export": "off",
// Warn against too many levels of nesting of blocks
// Not disallowed because it would be too intrusive, but useful as a hint that it might be time to refactor
// https://eslint.org/docs/latest/rules/max-depth
"max-depth": ["warn", 3],
// Warn against too many levels of nesting of callbacks
// Not disallowed because it would be too intrusive, but useful as a hint that it might be time to refactor
// https://eslint.org/docs/latest/rules/max-nested-callbacks
"max-nested-callbacks": ["warn", 3],
// Enabled by `eslint-config-airbnb`: https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/variables.js#L33-L34
// Disabled in favor of "@typescript-eslint/no-shadow": https://typescript-eslint.io/rules/no-shadow
// https://eslint.org/docs/latest/rules/no-shadow
"no-shadow": "off",
// Disallow dangling underscores in identifiers
// https://eslint.org/docs/latest/rules/no-underscore-dangle
"no-underscore-dangle": [
"error",
{
// Allow dangling underscores in these identifiers
allow: ["__typename"],
},
],
// Enabled by `eslint-config-airbnb`: https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/variables.js#L53-L54
// Disabled because there is no actual problem with using something before it's defined
// https://eslint.org/docs/latest/rules/no-use-before-define
"no-use-before-define": "off",
// Enforce consistent use of quotes
// https://eslint.org/docs/latest/rules/quotes
quotes: [
"error",
"double",
{
// Allow single quotes inside another quote
avoidEscape: true,
},
],
// Enforce a specific function type for function components
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/function-component-definition.md
"react/function-component-definition": [
"error",
{
// Enforce arrow functions in named components
namedComponents: "arrow-function",
// Enforce arrow functions in named components
unnamedComponents: "arrow-function",
},
],
// Disallow JSX generally
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md
"react/jsx-filename-extension": [
"error",
{
// Allow JSX in these file types
extensions: [".tsx"],
},
],
// Validate JSX has key prop when in array or iterator
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-key.md
"react/jsx-key": [
"error",
{
// Check if usage of shorthand fragments require a key
checkFragmentShorthand: true,
},
],
// Disallow unnecessary fragments
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md
"react/jsx-no-useless-fragment": [
"error",
{
// Allow single expressions in fragments for type correctness: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md#allowexpressions
allowExpressions: true,
},
],
// Enabled by `eslint-config-airbnb`: https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/rules/react.js#L220-L226
// Disabled because we're using TypeScript
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prop-types.md
"react/prop-types": "off",
// Enabled by `eslint-config-airbnb`: https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/rules/react.js#L390-L394
// Disabled because we're using TypeScript and don't want to enforce default props
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/require-default-props.md
"react/require-default-props": "off",
// Enforce consistent ordering of import members. Used in conjunction with `import/order`.
// https://eslint.org/docs/latest/rules/sort-imports
"sort-imports": [
"error",
{
// Ignore sorting of import declarations that are already handled by `import/order`: https://eslint.org/docs/latest/rules/sort-imports#ignoredeclarationsort
ignoreDeclarationSort: true,
},
],
},
overrides: [
// Allow default exports in config files that require them
{
files: [
"*.d.ts", // type declaration files might require default exports
"*.stories.tsx", // storybook requires exporting component story metadata as default
"rollup.config.{js,mjs}", // rollup requires exporting config as default
"vite.config.{ts,mts}", // vite requires exporting config as default
"vitest.config.{ts,mts}", // vite requires exporting config as default
"cypress.config.ts", // cypress requires exporting config as default
],
rules: {
"import/no-default-export": "off",
},
},
],
settings: {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/resolver": {
node: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
},
},
env: {
browser: true,
},
},
},
}