/
index.js
184 lines (166 loc) · 5.13 KB
/
index.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
const confusingBrowserGlobals = require("confusing-browser-globals");
let react = false;
let isNewJsx = false;
try {
require.resolve("react");
react = true;
isNewJsx = parseInt(require("react").version, 10) > 16;
} catch (e) {}
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
isNewJsx && "plugin:react/jsx-runtime",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:jsx-a11y/recommended",
"prettier",
].filter(Boolean),
plugins: ["@typescript-eslint", "jest", "jsx-a11y", "react-hooks", "tsdoc"],
env: {
es6: true,
node: true,
browser: true,
},
settings: {
"import/extensions": [".js", ".jsx", ".ts", ".tsx", ".d.ts"],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/resolver": {
node: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
},
react: {
version: react ? "detect" : "17.0.0",
},
},
rules: {
"no-console": "warn",
"no-use-before-define": "warn",
"no-restricted-globals": ["error", "isFinite", "isNaN"].concat(
confusingBrowserGlobals
),
// too many false positives with aliases/root dirs
"import/no-unresolved": "off",
curly: "error",
"object-shorthand": ["error", "always"],
"no-useless-rename": ["error"],
},
overrides: [
{
files: ["**/*.ts", "**/*.tsx"],
extends: ["plugin:@typescript-eslint/recommended"],
rules: {
"@typescript-eslint/consistent-type-imports": [
"error",
{ fixStyle: "inline-type-imports" },
],
// I want correct tsdoc syntax
"tsdoc/syntax": "warn",
"react/prop-types": "off",
// have to disable since it can report incorrect errors
"no-empty-function": "off",
// I prefer shorthand syntax
"@typescript-eslint/array-type": ["error", { default: "array" }],
// I prefer using `interface` over `type = {}`
"@typescript-eslint/consistent-type-definitions": [
"error",
"interface",
],
// Allow expressions to work with react hooks. Annoying to have to
// typedef each arrow function in a `useEffect` or `useCallback` when
// it can be derived.
"@typescript-eslint/explicit-function-return-type": [
"error",
{
allowExpressions: true,
// allow FC definitions for React
allowTypedFunctionExpressions: true,
},
],
// not a big fan of requiring unknown objects to require the index signature
"@typescript-eslint/ban-types": "off",
// This is a "better" version of the `noUnusedLocals` and
// `noUnusedParameters` from the tsconfig.json since it can catch
// unused vars in rest parameters that weren't meant to be omitted. I
// must manually rename to be _name so I know it was intentionally
// omitted
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": [
"warn",
{ ignoreTypeReferences: true },
],
},
},
{
files: [
"src/setupTests.js",
"src/setupTests.ts",
"**/__tests__/**",
"**/*.test.*",
],
env: {
jest: true,
},
// allow for less strict rules when writing tests
rules: {
"prefer-template": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-empty-function": "off",
"jsx-a11y/anchor-has-content": 0,
"jsx-a11y/anchor-is-valid": "off",
"jsx-a11y/click-events-have-key-events": 0,
"jsx-a11y/control-has-associated-label": "off",
"jsx-a11y/no-autofocus": "off",
"jsx-a11y/no-static-element-interactions": "off",
"react/prop-types": "off",
"react/display-name": "off",
"react/prefer-stateless-function": "off",
},
},
{
files: ["**/__tests__/**", "**/*.test.*"],
extends: ["plugin:jest/recommended", "plugin:testing-library/react"],
rules: {
// it's valid to do @jest-environment or other things in tests
"tsdoc/syntax": 0,
},
},
{
files: ["**/*.js", "**/*.jsx"],
rules: {
"no-unused-vars": [
"error",
{
vars: "all",
varsIgnorePattern: "^_",
args: "after-used",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
},
},
],
};