-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
251 lines (250 loc) · 7.72 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
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
const path = require("path");
module.exports = {
root: true,
globals: {
// Trackers loaded globally
newrelic: "readonly",
globalThis: "readonly",
},
env: {
browser: true,
es6: true,
node: true,
jest: true,
},
extends: [
"eslint:recommended",
"plugin:jsdoc/recommended",
"prettier",
"plugin:jsx-a11y/recommended",
"plugin:react/recommended",
"plugin:you-dont-need-lodash-underscore/all",
],
plugins: ["jsdoc", "lodash", "jsx-a11y", "react-hooks"],
parser: "@babel/eslint-parser",
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
overrides: [
{
files: "**/*.+(ts|tsx)",
parser: "@typescript-eslint/parser",
parserOptions: {
project: path.resolve(__dirname, "./tsconfig.json"),
tsconfigRootDir: path.resolve(__dirname),
},
plugins: ["@typescript-eslint/eslint-plugin"],
extends: [
"plugin:@typescript-eslint/eslint-recommended", // removes redundant warnings between TS & ESLint
"plugin:@typescript-eslint/recommended", // rules specific to typescript, e.g., writing interfaces
],
rules: {
// conflicts with @typescript-eslint/no-use-before-define:
"no-use-before-define": "off",
"@typescript-eslint/consistent-indexed-object-style": [
"error",
// Index signature allows us to be more expressive than Record.
// For example { [claim_id: string]: Claim }, compared to Record<string, Claim>
"index-signature",
],
// conflicts with @typescript-eslint/strict-boolean-expressions:
"no-extra-boolean-cast": "off",
"@typescript-eslint/strict-boolean-expressions": [
"error",
{
// These are pretty lax as a starting point, but helps
// catch unneeded boolean expressions, or nullable numbers
// that are accidentally treated as booleans:
allowAny: true,
allowNullableBoolean: true,
allowNullableString: true,
},
],
"jsdoc/check-param-names": "off",
"jsdoc/require-param-type": "off",
"jsdoc/require-property-type": "off",
"jsdoc/require-returns": "off",
"jsdoc/require-returns-type": "off",
"no-restricted-syntax": [
"error",
{
selector: "TSEnumDeclaration",
message:
"Don't use TypeScript enum syntax. Use `as const` instead.",
},
],
},
},
{
files: ["src/components/*"],
rules: {
"no-restricted-imports": [
"error",
{
paths: [
{
name: "next/router",
message: "Components should not be responsibile for routing.",
},
],
patterns: [
{
group: ["*/pages*"],
message:
"Components should not depend on application code. Consider exposing events that clients handle.",
},
],
},
],
},
},
{
files: ["src/components/core/*"],
rules: {
"no-restricted-imports": [
"error",
{
paths: [
{
name: "react-i18next",
message: "Core components shouldn't have any custom strings",
},
{
name: "next/link",
message:
"Core components should not be responsible for routing.",
},
],
patterns: [
{
group: [
"*/pages*",
"*/components*.tsx",
"*/models*",
"*/locales/*",
"*/flows*",
"*/hoc*",
"*/services*",
],
message:
"Core components should not depend on application code.",
},
],
},
],
},
},
{
files: ["src/models/*"],
rules: {
"no-restricted-imports": [
"error",
{
paths: [
{
name: "next/router",
message:
"Models should not have any dependencies. Consider moving routing logic to the app or page level, or check for accidental dependencies.",
},
{
name: "js-cookie",
message:
"Models should not have any dependencies. Consider moving routing logic to the app or page level, or check for accidental dependencies.",
},
],
patterns: [
{
group: ["*/components*"],
message:
"Models should not have any dependencies. Reconsider the software architecture, or check for accidental dependencies.",
},
{
group: ["*/pages*"],
message:
"Models should not have any dependencies. Reconsider the software architecture, or check for accidental dependencies.",
},
{
group: ["*/hooks*"],
message:
"Models should not have any dependencies. Reconsider the software architecture, or check for accidental dependencies.",
},
],
},
],
},
},
{
files: ["lib/**", "src/**", "storybook/**"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["**/tests/*"],
message:
"Test files should not be imported in files outside of the tests/ directory. Code shared between Storybook and Tests should be in the lib/ directory.",
},
],
},
],
},
},
],
rules: {
camelcase: "off",
"import/no-useless-path-segments": "error",
"jest/consistent-test-it": ["error", { fn: "it" }],
"jest/no-conditional-expect": "off",
"jest/no-try-expect": "off",
"jest/valid-title": "off",
"jsdoc/check-param-names": "error",
"jsdoc/newline-after-description": "off",
"jsdoc/require-jsdoc": "off",
"jsdoc/require-param": "off",
"jsdoc/require-param-description": "off",
"jsdoc/require-param-name": "error",
"jsdoc/require-param-type": "error",
"jsdoc/require-returns": "warn",
"jsdoc/require-returns-description": "off",
"jsdoc/no-undefined-types": "off",
"jsdoc/tag-lines": "off",
"jsx-a11y/anchor-has-content": "off",
"jsx-a11y/no-onchange": "off",
"lodash/import-scope": ["error", "member"],
"lodash/path-style": ["error", "string"],
"no-console": ["error", { allow: ["error"] }],
"no-irregular-whitespace": ["error", { skipTemplates: true }],
"no-param-reassign": "error",
"no-prototype-builtins": "off",
"object-shorthand": ["error", "properties", { avoidQuotes: true }],
"promise/no-native": "off",
"react/button-has-type": "error",
"react/jsx-handler-names": "off",
"react/jsx-fragments": ["error", "element"],
"react/jsx-no-target-blank": ["error", { allowReferrer: true }],
"react/no-unescaped-entities": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"require-await": "error",
"sort-imports": "error",
"sort-vars": "error",
// We use _.get() a lot to get deeply nested nullable values
"you-dont-need-lodash-underscore/get": "off",
},
settings: {
jest: {
version: "detect",
},
jsdoc: {
mode: "typescript",
},
react: {
version: "detect",
},
},
};