forked from ethanselzer/react-image-magnify
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path.eslintrc.js
More file actions
222 lines (222 loc) · 7.48 KB
/
Copy path.eslintrc.js
File metadata and controls
222 lines (222 loc) · 7.48 KB
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
module.exports = {
env: {
browser: true,
'jest/globals': true,
},
extends: [
'airbnb',
'airbnb/hooks',
'plugin:@typescript-eslint/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
],
overrides: [
{
files: ['*.spec.ts'],
rules: {
'no-unused-expressions': 'off',
'import/no-extraneous-dependencies': 'off',
},
}, {
files: ['*.js'],
rules: {
'import/no-extraneous-dependencies': 'off',
},
}, {
files: ['*.js', '*.d.ts'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
}, {
// enable the rule specifically for TypeScript files
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/explicit-function-return-type': ['error'],
},
}, {
files: ['src/stories/*.tsx'],
rules: {
'import/no-default-export': 'off',
'import/no-extraneous-dependencies': 'off',
},
},
],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
ecmaVersion: 12,
ecmaFeatures: {
jsx: true,
},
project: './tsconfig.dev.json',
sourceType: 'module',
},
plugins: [
'@typescript-eslint',
'import',
'jest',
'react',
],
rules: {
// For clarity, always require json extensions
'import/extensions': ['error', {
json: 'always',
js: 'never',
ts: 'never',
}],
// Prefer named exports always
'import/no-default-export': 'error',
// Prefer named exports always
'import/no-named-as-default': 'error',
// Prefer named exports always
'import/prefer-default-export': 'off',
// Turn off since we're using typescript's indent
indent: 'off',
// Override airbnb's max line length rule to:
// - increase the line length limit to 120
// - Set tab width to 4 spaces
// - also ignore import statements and class inheritance
'max-len': ['error', 120, 4, {
ignorePattern: '^import [^,]+ from |^export | implements',
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
}],
'newline-after-var': ['error', 'always'],
// A Promise within a promise? How meta, but actually useful
// We disable this and assume developers wield this power responsibly
'no-async-promise-executor': 'off',
'no-debugger': 'warn',
'no-bitwise': 'off',
// Boolean logic is boolean logic. Developers hsould understand order of operations.
'no-mixed-operators': 'off',
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
// This is an old rule that is slowly not applicable anymore (i.e. for-of is ok now)
'no-restricted-syntax': 'off',
// Replaced with typescript rule
'no-shadow': 'off',
'no-underscore-dangle': ['error', { allow: ['_embedded'] }],
// Prefer single quotes and template literals
quotes: ['error', 'single', { allowTemplateLiterals: true }],
'react/function-component-definition': [2, {
namedComponents: 'arrow-function',
unnamedComponents: 'arrow-function',
}],
'react/jsx-filename-extension': ['error', { extensions: ['.jsx', '.tsx'] }],
// Match common indentation
'react/jsx-indent': ['error', 4],
// Match common indentation
'react/jsx-indent-props': ['error', 4],
// This is silly to enable
'react/jsx-props-no-spreading': 'off',
'react/jsx-sort-props': ['error', {
callbacksLast: true,
ignoreCase: true,
noSortAlphabetically: false,
shorthandFirst: true,
}],
'react/no-namespace': 'warn',
'react/prefer-exact-props': 'off',
'react/no-arrow-function-lifecycle': 'off',
'react/no-invalid-html-attribute': 'error',
'react/no-unused-class-component-methods': 'error',
// We use React 17+
'react/jsx-uses-react': 'off',
// Since we do not use prop-types
'react/prop-types': 'off',
// We use React 17+
'react/react-in-jsx-scope': 'off',
// Since we do not use prop-types
'react/require-default-props': 'off',
// Sometimes we just need to
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
// Default to off so we don't type check js
'@typescript-eslint/explicit-function-return-type': 'off',
// Don't enforce the rule that interfaces should not be prefix with `I`
'@typescript-eslint/interface-name-prefix': 'off',
// Override airbnb's typescript indent rule to:
// - increase spacing from 2 to 4
// - disable call expression indentation
// Keep everything else
'@typescript-eslint/indent': ['error', 4, {
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
// MemberExpression: null,
FunctionDeclaration: {
parameters: 1,
body: 1,
},
FunctionExpression: {
parameters: 1,
body: 1,
},
CallExpression: {
arguments: 1,
},
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
// list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
ignoredNodes: [
'JSXElement',
'JSXElement > *',
'JSXAttribute',
'JSXIdentifier',
'JSXNamespacedName',
'JSXMemberExpression',
'JSXSpreadAttribute',
'JSXExpressionContainer',
'JSXOpeningElement',
'JSXClosingElement',
'JSXText',
'JSXEmptyExpression',
'JSXSpreadChild',
],
ignoreComments: false,
}],
'@typescript-eslint/no-shadow': ['error'],
'@typescript-eslint/no-unused-vars': ['error', {
args: 'after-used',
argsIgnorePattern: '^_',
ignoreRestSiblings: true,
}],
'@typescript-eslint/no-use-before-define': ['error'],
'@typescript-eslint/type-annotation-spacing': ['error', {
before: false,
after: true,
overrides: {
arrow: {
before: true,
after: true,
},
},
}],
},
settings: {
react: {
pragma: 'React',
version: 'detect',
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/extensions': [
'.js',
'.jsx',
'.mjs',
'.ts',
'.txs',
],
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
},
};