-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
218 lines (209 loc) · 7.5 KB
/
.eslintrc.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
/**
* @type {import("eslint").Linter.Config}
*/
const config = {
root: true,
extends: [
"plugin:import/recommended",
"plugin:import/typescript",
"airbnb-typescript",
"eslint:recommended",
"plugin:react/recommended",
"prettier",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "react", "eslint-plugin-react-hooks"],
env: {
node: true,
},
parserOptions: {
ecmaVersion: 2020,
ecmaFeatures: {
legacyDecorators: true,
jsx: true,
},
},
settings: {
react: {
version: "18",
},
},
rules: {
"consistent-this": ["error", "self"],
curly: ["error", "all"],
// Just as bad as "max components per file"
"max-classes-per-file": "off",
// Too interruptive
"no-alert": "error",
// Stylistic opinion
"arrow-body-style": "off",
// Allow warn and error for dev environments
"no-console": ["error", { allow: ["warn", "error"] }],
"no-param-reassign": "off", // It's fine.
// Airbnb use warn https://github.com/airbnb/javascript/blob/63098cbb6c05376dbefc9a91351f5727540c1ce1/packages/eslint-config-airbnb-base/rules/style.js#L97
// but eslint recommands error
"func-names": "error",
"no-restricted-imports": [
"error",
{
patterns: [
"@mui/*/*/*",
// Begin block: Packages with files instead of packages in the top level
// Importing from the top level pulls in CommonJS instead of ES modules
// Allowing /icons as to reduce cold-start of dev builds significantly.
// There's nothing to tree-shake when importing from /icons this way:
// '@mui/icons-material/*/',
"@mui/system/*",
"@mui/utils/*",
// End block
// Macros are fine since their import path is transpiled away
"!@mui/utils/macros",
"@mui/utils/macros/*",
"!@mui/utils/macros/*.macro",
],
},
],
"no-constant-condition": "error",
// Use the proptype inheritance chain
"no-prototype-builtins": "off",
"no-underscore-dangle": "error",
"nonblock-statement-body-position": "error",
"prefer-arrow-callback": ["error", { allowNamedFunctions: true }],
// Destructuring harm grep potential.
"prefer-destructuring": "off",
"no-undef": "off",
// disabled type-aware linting due to performance considerations
"@typescript-eslint/dot-notation": "off",
"dot-notation": "error",
// disabled type-aware linting due to performance considerations
"@typescript-eslint/no-implied-eval": "off",
"no-implied-eval": "error",
// disabled type-aware linting due to performance considerations
"@typescript-eslint/no-throw-literal": "off",
"no-throw-literal": "error",
// disabled type-aware linting due to performance considerations
"@typescript-eslint/return-await": "off",
"no-return-await": "error",
// Not sure why it doesn't work
"import/named": "off",
// Missing yarn workspace support
"import/no-extraneous-dependencies": "off",
// The code is already coupled to webpack. Prefer explicit coupling.
"import/no-webpack-loader-syntax": "off",
// doesn't work?
// "jsx-a11y/label-has-associated-control": [
// "error",
// {
// // airbnb uses 'both' which requires nesting i.e. <label><input /></label>
// // 'either' allows `htmlFor`
// assert: "either",
// },
// ],
// We are a library, we need to support it too
"jsx-a11y/no-autofocus": "off",
"react-hooks/exhaustive-deps": [
"error",
{ additionalHooks: "useEnhancedEffect" },
],
"react-hooks/rules-of-hooks": "error",
"react/default-props-match-prop-types": [
"error",
{
// Otherwise the rule thinks inner props = outer props
// But in TypeScript we want to know that a certain prop is defined during render
// while it can be ommitted from the callsite.
// Then defaultProps (or default values) will make sure that the prop is defined during render
allowRequiredDefaults: true,
},
],
// Can add verbosity to small functions making them harder to grok.
// Though we have to manually enforce it for function components with default values.
"react/destructuring-assignment": "off",
"react/forbid-prop-types": "off", // Too strict, no time for that
"react/jsx-curly-brace-presence": "off", // broken
// airbnb is using .jsx
"react/jsx-filename-extension": ["error", { extensions: [".js", ".tsx"] }],
// Prefer <React.Fragment> over <>.
"react/jsx-fragments": ["error", "element"],
// Enforces premature optimization
"react/jsx-no-bind": "off",
// We are a UI library.
"react/jsx-props-no-spreading": "off",
// This rule is great for raising people awareness of what a key is and how it works.
"react/no-array-index-key": "off",
"react/no-danger": "error",
"react/no-direct-mutation-state": "error",
// Not always relevant
"react/require-default-props": "off",
"react/sort-prop-types": "error",
// This depends entirely on what you're doing. There's no universal pattern
"react/state-in-constructor": "off",
// stylistic opinion. For conditional assignment we want it outside, otherwise as static
"react/static-property-placement": "off",
},
overrides: [
// Files used for generating TypeScript declaration files (#ts-source-files)
{
files: ["packages/*/src/**/*.tsx"],
excludedFiles: "*.spec.tsx",
rules: {
// "no-restricted-imports": [
// "error",
// {
// paths: [
// {
// name: "@mui/material/styles",
// importNames: ["createStyles"],
// message: forbidCreateStylesMessage,
// },
// {
// name: "@mui/styles",
// importNames: ["createStyles"],
// message: forbidCreateStylesMessage,
// },
// {
// name: "@mui/styles/createStyles",
// message: forbidCreateStylesMessage,
// },
// ],
// patterns: [
// // Allow deeper imports for TypeScript types. TODO?
// "@mui/*/*/*/*",
// // Macros are fine since they're transpiled into something else
// "!@mui/utils/macros/*.macro",
// ],
// },
// ],
"react/prop-types": "off",
},
},
{
files: ["*.spec.tsx", "*.spec.ts"],
rules: {
"no-alert": "off",
"no-console": "off",
"no-empty-pattern": "off",
"no-lone-blocks": "off",
"no-shadow": "off",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-use-before-define": "off",
// Not sure why it doesn't work
"import/export": "off",
"import/prefer-default-export": "off",
"jsx-a11y/anchor-has-content": "off",
"jsx-a11y/anchor-is-valid": "off",
"jsx-a11y/tabindex-no-positive": "off",
"react/default-props-match-prop-types": "off",
"react/no-access-state-in-setstate": "off",
"react/no-unused-prop-types": "off",
"react/prefer-stateless-function": "off",
"react/prop-types": "off",
"react/require-default-props": "off",
"react/state-in-constructor": "off",
"react/static-property-placement": "off",
},
},
],
};
module.exports = config;