-
Notifications
You must be signed in to change notification settings - Fork 6
/
.eslintrc.js
166 lines (144 loc) · 5.25 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
// Most of this file is based on
// https://dev.to/robertcoopercode/using-eslint-and-prettier-in-a-typescript-project-53jb.
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
// The following based on
// https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md.
//
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
// Note: `recommended-requiring-type-checking` have type-aware rules. This comes
// with a performance penalty. For small projects, this is usually negligible.
// It is recommended to separate the linting into two stagings once the type-aware
// checking becomes a productivity issue. See second half of the "Recommended
// Configs" section at
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#recommended-configs.
'plugin:@typescript-eslint/recommended-requiring-type-checking',
// Disables react-specific linting rules that conflict with prettier.
'prettier/react',
// Uses `eslint-config-prettier` to disable ESLint rules from
// `@typescript-eslint/eslint-plugin` that would conflict with prettier.
'prettier/@typescript-eslint',
// Enables `eslint-plugin-prettier` and displays prettier errors as ESLint errors.
// Make sure this is always the last configuration in the extends array.
// The advantage of having prettier setup as an ESLint rule using
// `eslint-plugin-prettier` is that code can automatically be fixed using ESLint's
// `--fix` option.
'plugin:prettier/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:jsx-a11y/recommended',
'plugin:promise/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
],
plugins: ['@typescript-eslint', 'jsx-a11y', 'promise', 'react-hooks'],
rules: {
// Off because favoring @typescript-eslint/naming-convention instead.
camelcase: 'off',
'comma-dangle': [
'error',
{
arrays: 'always-multiline',
exports: 'always-multiline',
functions: 'ignore',
imports: 'always-multiline',
objects: 'always-multiline',
},
],
'no-multiple-empty-lines': ['error', { max: 2, maxBOF: 1, maxEOF: 1 }],
// Disabling the base rule as it can report incorrect errors and is recommended by
// @typescript-eslint/no-unused-vars.
'no-unused-vars': 'off',
'padded-blocks': 'off',
// Allows to use an `a` element without an `href` attribute inside a `Link`
// component which in our case is a Next.js Link component.
// See https://github.com/evcohen/eslint-plugin-jsx-a11y/issues/402#issuecomment-368305051.
'jsx-a11y/anchor-is-valid': [
'error',
{
aspects: ['invalidHref', 'preferButton'],
components: ['Link'],
specialLink: ['hrefLeft', 'hrefRight'],
},
],
'react/jsx-child-element-spacing': 'warn',
'react/jsx-closing-bracket-location': 'error',
'react/jsx-closing-tag-location': 'error',
'react/jsx-curly-newline': 'error',
'react/jsx-curly-spacing': ['error', { when: 'never', children: true }],
'react/jsx-equals-spacing': 'error',
'react/jsx-indent': ['error', 2],
'react/jsx-indent-props': ['error', 2],
'react/jsx-tag-spacing': 'error',
'react/no-unsafe': ['error', { checkAliases: true }],
// Off because we are using TypeScript which expects us to declare the props.
'react/prop-types': 'off',
// Off because it is deprecated and favoring @typescript-eslint/naming-convention
// instead.
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
// The Experiment API uses snake_case, so we decided to disable enforcing
// camelcase.
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: ['strictCamelCase'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{
selector: 'enumMember',
format: ['StrictPascalCase'],
},
{
selector: 'function',
format: ['strictCamelCase', 'StrictPascalCase'],
},
{
selector: 'parameter',
format: ['strictCamelCase'],
leadingUnderscore: 'allow', // For indicating unused parameter to TypeScript.
},
{
selector: 'property',
format: ['snake_case', 'strictCamelCase', 'StrictPascalCase', 'UPPER_CASE'],
},
{
selector: 'variable',
format: ['strictCamelCase', 'StrictPascalCase', 'UPPER_CASE'],
},
{
selector: 'memberLike',
modifiers: ['private'],
format: ['strictCamelCase'],
leadingUnderscore: 'require',
},
{
selector: 'typeLike',
format: ['StrictPascalCase'],
},
],
'@typescript-eslint/no-unused-vars': 'error',
},
settings: {
'import/resolver': {
alias: {
map: [['@', './']],
extensions: ['.ts', '.json', '.tsx'],
},
},
react: {
version: 'detect',
},
},
}