-
Notifications
You must be signed in to change notification settings - Fork 27
/
.eslintrc.js
144 lines (133 loc) · 5.29 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
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
tsconfigRootDir: __dirname,
},
extends: [
'airbnb',
'plugin:@typescript-eslint/recommended',
// Prettier must come last
'prettier',
],
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {
project: __dirname,
},
},
},
plugins: ['jest', 'react-hooks', 'compat', 'lodash'],
env: {
browser: true,
node: true,
'jest/globals': true,
},
rules: {
// Has many false positives in monorepos
'import/no-extraneous-dependencies': 'off',
// Disabled because some packages contain subcomponents. Our documentation system currently
// requires that they be defined in one file.
'react/no-multi-comp': 'off',
// React hooks
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'error',
// Typescript
'react/jsx-filename-extension': [
'error',
{
extensions: ['.jsx', '.tsx'],
},
],
// Upgrade from warning to error
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/no-explicit-any': 'error',
// We use noop functions in many places, for example as default values for props.
'@typescript-eslint/no-empty-function': 'off',
// Not worth fixing. Just finish converting everything to TS instead.
'react/prop-types': 'off',
// Prop spreading is safe in TS
'react/jsx-props-no-spreading': 'off',
'import/extensions': 'off',
// Disabled to make upgrading easier. TODO(giles): re-enable
'react/function-component-definition': 'off',
'react/jsx-fragments': 'off',
'jsx-a11y/control-has-associated-label': 'off',
'no-use-before-define': 'off',
'arrow-body-style': 'off',
'react/destructuring-assignment': 'off',
},
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
rules: {
// Import plugin is not really needed for TS files, the TS compiler will throw an
// error for missing imports
'import/named': 'off',
'import/export': 'off',
// PropTypes are not needed for TS files
'react/require-default-props': 'off',
},
},
{
files: ['**/*.js', '**/*.jsx'],
rules: {
// TypeScript rules don't apply in JS files
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
},
},
{
files: ['packages/**/*'],
rules: {
// Disabled because rollup requires us to be explicit about the file extension.
// https://github.com/rollup/rollup/issues/1052#issuecomment-260065475
'import/extensions': 'off',
},
},
{
// Rules that should be applied only to code that gets bundled into our thumbprint-react
// client library and shipped to browsers.
// Since this code must run in IE11, it has stricter constraints than other parts of
// this repo.
files: ['packages/thumbprint-react/**/*'],
excludedFiles: ['*test.jsx', '*test.tsx', '*.config.js'],
rules: {
// Check for uses of browser/DOM APIs that are not available in our supported browsers.
'compat/compat': 'error',
// Enable rules that check for erroneous uses of Lodash APIs
'lodash/callback-binding': 'error',
'lodash/collection-method-value': 'error',
'lodash/collection-return': 'error',
'lodash/no-double-unwrap': 'error',
'lodash/no-extra-args': 'error',
'lodash/no-unbound-this': 'error',
'lodash/unwrap': 'error',
// Only allow importing lodash methods like `import map from 'lodash/map'`.
// This prevents accidentally importing the full library which would bloat our distributed bundles.
'lodash/import-scope': ['error', 'method'],
// Prefer Lodash methods to the native ones. This prevents using methods like
// `Object.entries()` or `Array.find()` which will break in IE11.
// We allow using common methods like Array.map which are available in all supported browsers.
'lodash/prefer-lodash-method': [
2,
{ ignoreMethods: ['map', 'filter', 'reduce', 'keys'] },
],
},
},
{
files: ['next/pages/**/*.tsx'],
rules: {
// We can use Next.js's `InferGetStaticPropsType` rather than specifying the return
// type manually.
'@typescript-eslint/explicit-function-return-type': 'off',
},
},
],
};