-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eslintrc.js
197 lines (182 loc) · 5.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
const prettierConfig = require('./.prettierrc.js')
module.exports = {
extends: [
// AirBnb
'airbnb',
// React
'plugin:react/recommended',
// Prettier
// recommended rules
'plugin:prettier/recommended',
// Jest
'plugin:jest/all'
],
env: {
node: true,
es6: true,
browser: true,
jest: true
},
globals: {
React: 'readonly',
JSX: 'readonly',
RequestInfo: 'readonly',
RequestInit: 'readonly'
},
// to parse future JS features (e.g. dynamic imports)
parser: '@typescript-eslint/parser',
plugins: [
// enables custom react-hooks/* rules
'react-hooks',
'@typescript-eslint'
],
rules: {
// Airbnb + @typescript-eslint conflicts
// Replace airbnb 'camel' with '@typescript-eslint' equivalent
// Ensures consistent argument/variable casing
camelcase: 'off',
'react/jsx-props-no-spreading': 0,
'react/require-default-props': 0,
// Replace airbnb 'no-unused-expressions' with '@typescript-eslint' equivalent
// Ensures all expressions are used
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'error',
// Replace airbnb 'no-unused-vars' with '@typescript-eslint' equivalent
// Ensures all variables are used
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
// Replace airbnb 'no-use-before-define' with '@typescript-eslint' equivalent
// Enables us to use functions before they are defined
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'off',
// @typescript-eslint
// Allow return statements to have no TS type
'@typescript-eslint/explicit-function-return-type': 'off',
// Disallow all uses of `any`
'@typescript-eslint/no-explicit-any': 'error',
// Enforce PascalCase types and interfaces
'@typescript-eslint/naming-convention': [
'error',
{ selector: 'typeLike', format: ['PascalCase'] }
],
'@typescript-eslint/no-non-null-assertion': 'off',
// React rules
// Allow JSX in js files
'react/jsx-filename-extension': 'off',
// Allow nextJs JSX templates
'react/react-in-jsx-scope': 'off',
// No use of react prop types
'react/prop-types': 'off',
// Consistently sort props
'react/jsx-sort-props': [
'error',
{ ignoreCase: true, reservedFirst: true, shorthandLast: true }
],
// Enforce all rules-of-hooks
'react-hooks/rules-of-hooks': 'error',
// Ensure all dependencies are passed to react hooks
'react-hooks/exhaustive-deps': 'error',
// A11y
// Warn when click events to have no key events
'jsx-a11y/click-events-have-key-events': 'warn',
// Make sure all labels have associated inputs
'jsx-a11y/label-has-for': 'off', // deprecated
'jsx-a11y/label-has-associated-control': [
'error',
{
assert: 'either'
}
],
// Import rules
// Allow for a single named export without it being default
'import/prefer-default-export': 'off',
// Allow nextJS imports
'import/no-unresolved': 'off',
// Group module and relative imports
'import/order': [
'error',
{
// Imports are grouped as follows:
groups: [
// 1: built-in node modules (fs, path)
'builtin',
// 2: dependencies in node_modules
'external',
// 3: internal aliases. See pathGroups below.
'internal',
// 4. relative imports
'parent',
// 5. relative imports in the same directory
'sibling'
],
pathGroups: [
{
// @shared imports are classed as 'internal'
pattern: '@shared/**',
group: 'internal'
},
{
// @pages imports come after internal
pattern: '@pages/**',
group: 'internal',
position: 'after'
},
{
// @assets imports come after internal
pattern: '@assets/**',
group: 'internal',
position: 'after'
}
],
// Required for pathGroups to work.
pathGroupsExcludedImportTypes: ['builtin'],
// Add an empty line between import groups.
'newlines-between': 'always'
}
],
// Prevent import of dependencies not listed in package.json
'import/no-extraneous-dependencies': [
'error',
{
// Allow importing from devDependencies in...
devDependencies: [
'**/**/*.test.{js,ts,tsx}', // ...tests
'**/tests/*.{js,ts,tsx}' // ...test setup
]
}
],
// Don't requre file type in imports. TS already enforces this.
'import/extensions': 0,
// Jest rules
// Ensures consistent naming in test declarations
'jest/lowercase-name': [
'error',
{
// Allow describe block name to be uppercase
// This is so that we can describe('ComponentName')
ignore: ['describe']
}
],
// Allow any expect assertions
'jest/prefer-expect-assertions': 'off',
// Allow global beforeAll, beforeEach etc hooks
'jest/no-hooks': 'off',
// Allow snapshots in external files
'jest/prefer-inline-snapshots': 'off',
// Enforce "it" instead of "test" inside describe blocks
'jest/consistent-test-it': ['error', { fn: 'it' }],
// Override no-restricted-syntax to allow for..of loops
// but keep the other constructs forbidden
'no-restricted-syntax': [
'error',
'ForInStatement',
'LabeledStatement',
'WithStatement'
],
// Disallow console logs.
// Prefer reportError() to log errors.
'no-console': 'error',
// prettier rules
'prettier/prettier': ['error', prettierConfig]
}
}