1
- const TSEslint = require ( "@typescript-eslint/eslint-plugin" )
2
-
3
1
module . exports = {
4
- parser : " babel- eslint" ,
2
+ parser : `@ babel/ eslint-parser` ,
5
3
extends : [
6
- "google" ,
7
- "eslint:recommended" ,
8
- "plugin:flowtype/recommended" ,
9
- "plugin:react/recommended" ,
10
- "prettier" ,
11
- "prettier/flowtype" ,
12
- "prettier/react" ,
4
+ `google` ,
5
+ `eslint:recommended` ,
6
+ `plugin:flowtype/recommended` ,
7
+ `plugin:react/recommended` ,
8
+ `prettier` ,
13
9
] ,
14
- plugins : [ " flowtype" , " prettier" , " react" , " filenames" ] ,
10
+ plugins : [ ` flowtype` , ` prettier` , ` react` , ` filenames` , `@babel` ] ,
15
11
parserOptions : {
16
12
ecmaVersion : 2016 ,
17
- sourceType : " module" ,
13
+ sourceType : ` module` ,
18
14
ecmaFeatures : {
19
15
jsx : true ,
20
16
} ,
17
+ babelOptions : {
18
+ configFile : `./.babelrc.js` ,
19
+ } ,
21
20
} ,
22
21
env : {
23
22
browser : true ,
@@ -39,43 +38,63 @@ module.exports = {
39
38
__ASSET_PREFIX__ : true ,
40
39
} ,
41
40
rules : {
42
- "arrow-body-style" : [
43
- "error" ,
44
- "as-needed" ,
45
- { requireReturnForObjectLiteral : true } ,
46
- ] ,
47
- "no-unused-expressions" : [
48
- "error" ,
41
+ "@babel/no-unused-expressions" : [
42
+ `error` ,
49
43
{
50
44
allowTaggedTemplates : true ,
51
45
} ,
52
46
] ,
47
+ "no-unused-expressions" : `off` ,
48
+ "@babel/no-invalid-this" : `error` ,
49
+ "no-invalid-this" : `off` ,
50
+ "arrow-body-style" : [
51
+ `error` ,
52
+ `as-needed` ,
53
+ { requireReturnForObjectLiteral : true } ,
54
+ ] ,
55
+ "new-cap" : `off` ,
53
56
"no-unused-vars" : [
54
- " warn" ,
57
+ ` warn` ,
55
58
{
56
- varsIgnorePattern : "^_" ,
57
- argsIgnorePattern : "^_" ,
59
+ varsIgnorePattern : `^_` ,
60
+ argsIgnorePattern : `^_` ,
58
61
ignoreRestSiblings : true ,
59
62
} ,
60
63
] ,
61
- "consistent-return" : [ "error" ] ,
62
- "filenames/match-regex" : [ "error" , "^[a-z-\\d\\.]+$" , true ] ,
63
- "no-console" : "off" ,
64
- "no-inner-declarations" : "off" ,
65
- "prettier/prettier" : "error" ,
66
- quotes : [ "error" , "backtick" ] ,
67
- "react/display-name" : "off" ,
68
- "react/jsx-key" : "warn" ,
69
- "react/no-unescaped-entities" : "off" ,
70
- "react/prop-types" : "off" ,
71
- "require-jsdoc" : "off" ,
72
- "valid-jsdoc" : "off" ,
64
+ "consistent-return" : [ `error` ] ,
65
+ "filenames/match-regex" : [ `error` , `^[a-z-\\d\\.]+$` , true ] ,
66
+ "no-console" : `off` ,
67
+ "no-inner-declarations" : `off` ,
68
+ "prettier/prettier" : `error` ,
69
+ quotes : [ `error` , `backtick` ] ,
70
+ "react/display-name" : `off` ,
71
+ "react/jsx-key" : `warn` ,
72
+ "react/no-unescaped-entities" : `off` ,
73
+ "react/prop-types" : `off` ,
74
+ "require-jsdoc" : `off` ,
75
+ "valid-jsdoc" : `off` ,
76
+ "prefer-promise-reject-errors" : `warn` ,
77
+ "no-prototype-builtins" : `warn` ,
78
+ "guard-for-in" : `warn` ,
79
+ "spaced-comment" : [
80
+ `error` ,
81
+ `always` ,
82
+ { markers : [ `/` ] , exceptions : [ `*` , `+` ] } ,
83
+ ] ,
84
+ camelcase : [
85
+ `error` ,
86
+ {
87
+ properties : `never` ,
88
+ ignoreDestructuring : true ,
89
+ allow : [ `^unstable_` ] ,
90
+ } ,
91
+ ] ,
73
92
} ,
74
93
overrides : [
75
94
{
76
95
files : [
77
- " packages/**/gatsby-browser.js" ,
78
- " packages/gatsby/cache-dir/**/*" ,
96
+ ` packages/**/gatsby-browser.js` ,
97
+ ` packages/gatsby/cache-dir/**/*` ,
79
98
] ,
80
99
env : {
81
100
browser : true ,
@@ -86,115 +105,115 @@ module.exports = {
86
105
} ,
87
106
} ,
88
107
{
89
- files : [ " **/cypress/integration/**/*" , " **/cypress/support/**/*" ] ,
108
+ files : [ ` **/cypress/integration/**/*` , ` **/cypress/support/**/*` ] ,
90
109
globals : {
91
110
cy : false ,
92
111
Cypress : false ,
93
112
} ,
94
113
} ,
95
114
{
96
- files : [ "*.ts" , "*.tsx" ] ,
97
- parser : "@typescript-eslint/parser" ,
98
- plugins : [ "@typescript-eslint/eslint-plugin" ] ,
115
+ files : [ `*.ts` , `*.tsx` ] ,
116
+ parser : `@typescript-eslint/parser` ,
117
+ plugins : [ `@typescript-eslint/eslint-plugin` ] ,
118
+ extends : [ `plugin:@typescript-eslint/recommended` ] ,
99
119
rules : {
100
- ...TSEslint . configs . recommended . rules ,
101
120
// We should absolutely avoid using ts-ignore, but it's not always possible.
102
121
// particular when a dependencies types are incorrect.
103
122
"@typescript-eslint/ban-ts-comment" : [
104
- " warn" ,
105
- { "ts-ignore" : " allow-with-description" }
123
+ ` warn` ,
124
+ { "ts-ignore" : ` allow-with-description` } ,
106
125
] ,
107
126
// This rule is great. It helps us not throw on types for areas that are
108
127
// easily inferrable. However we have a desire to have all function inputs
109
128
// and outputs declaratively typed. So this let's us ignore the parameters
110
129
// inferrable lint.
111
130
"@typescript-eslint/no-inferrable-types" : [
112
- " error" ,
131
+ ` error` ,
113
132
{ ignoreParameters : true } ,
114
133
] ,
115
134
"@typescript-eslint/ban-types" : [
116
- " error" ,
135
+ ` error` ,
117
136
{
118
137
extendDefaults : true ,
119
138
types : {
120
139
"{}" : {
121
- fixWith : " Record<string, unknown>" ,
140
+ fixWith : ` Record<string, unknown>` ,
122
141
} ,
123
142
object : {
124
- fixWith : " Record<string, unknown>" ,
143
+ fixWith : ` Record<string, unknown>` ,
125
144
} ,
126
145
} ,
127
146
} ,
128
147
] ,
129
- " camelcase" : " off" ,
148
+ camelcase : ` off` ,
130
149
// TODO: These rules allow a lot of stuff and don't really enforce. If we want to apply our styleguide, we'd need to fix a lot of stuff
131
150
"@typescript-eslint/naming-convention" : [
132
- " error" ,
151
+ ` error` ,
133
152
{
134
- selector : " default" ,
135
- format : [ " camelCase" ] ,
153
+ selector : ` default` ,
154
+ format : [ ` camelCase` ] ,
136
155
} ,
137
156
{
138
- selector : " variable" ,
139
- format : [ " camelCase" , " UPPER_CASE" , " PascalCase" ] ,
140
- leadingUnderscore : " allowSingleOrDouble" ,
141
- trailingUnderscore : " allowSingleOrDouble" ,
157
+ selector : ` variable` ,
158
+ format : [ ` camelCase` , ` UPPER_CASE` , ` PascalCase` ] ,
159
+ leadingUnderscore : ` allowSingleOrDouble` ,
160
+ trailingUnderscore : ` allowSingleOrDouble` ,
142
161
} ,
143
162
{
144
- selector : " function" ,
145
- format : [ " camelCase" , " PascalCase" ] ,
146
- leadingUnderscore : " allow" ,
163
+ selector : ` function` ,
164
+ format : [ ` camelCase` , ` PascalCase` ] ,
165
+ leadingUnderscore : ` allow` ,
147
166
} ,
148
167
{
149
- selector : " parameter" ,
150
- format : [ " camelCase" , " PascalCase" , " snake_case" ] ,
151
- leadingUnderscore : " allowSingleOrDouble" ,
168
+ selector : ` parameter` ,
169
+ format : [ ` camelCase` , ` PascalCase` , ` snake_case` ] ,
170
+ leadingUnderscore : ` allowSingleOrDouble` ,
152
171
} ,
153
172
{
154
- selector : " enumMember" ,
155
- format : [ " camelCase" , " UPPER_CASE" , " PascalCase" ]
173
+ selector : ` enumMember` ,
174
+ format : [ ` camelCase` , ` UPPER_CASE` , ` PascalCase` ] ,
156
175
} ,
157
176
{
158
- selector : " typeLike" ,
159
- format : [ " PascalCase" ] ,
177
+ selector : ` typeLike` ,
178
+ format : [ ` PascalCase` ] ,
160
179
} ,
161
180
{
162
- selector : " typeAlias" ,
163
- format : [ " camelCase" , " PascalCase" ]
181
+ selector : ` typeAlias` ,
182
+ format : [ ` camelCase` , ` PascalCase` ] ,
164
183
} ,
165
184
{
166
- selector : " property" ,
167
- format : [ " PascalCase" , " UPPER_CASE" , " camelCase" , " snake_case" ] ,
168
- leadingUnderscore : " allowSingleOrDouble" ,
185
+ selector : ` property` ,
186
+ format : [ ` PascalCase` , ` UPPER_CASE` , ` camelCase` , ` snake_case` ] ,
187
+ leadingUnderscore : ` allowSingleOrDouble` ,
169
188
} ,
170
189
{
171
- selector : " objectLiteralProperty" ,
172
- format : [ " PascalCase" , " UPPER_CASE" , " camelCase" , " snake_case" ] ,
173
- leadingUnderscore : " allowSingleOrDouble" ,
174
- trailingUnderscore : " allowSingleOrDouble" ,
190
+ selector : ` objectLiteralProperty` ,
191
+ format : [ ` PascalCase` , ` UPPER_CASE` , ` camelCase` , ` snake_case` ] ,
192
+ leadingUnderscore : ` allowSingleOrDouble` ,
193
+ trailingUnderscore : ` allowSingleOrDouble` ,
175
194
} ,
176
195
{
177
- selector : " enum" ,
178
- format : [ " PascalCase" , " UPPER_CASE" ]
196
+ selector : ` enum` ,
197
+ format : [ ` PascalCase` , ` UPPER_CASE` ] ,
179
198
} ,
180
199
{
181
- selector : " method" ,
182
- format : [ " PascalCase" , " camelCase" ] ,
183
- leadingUnderscore : " allowSingleOrDouble" ,
200
+ selector : ` method` ,
201
+ format : [ ` PascalCase` , ` camelCase` ] ,
202
+ leadingUnderscore : ` allowSingleOrDouble` ,
184
203
} ,
185
204
{
186
- selector : " interface" ,
187
- format : [ " PascalCase" ] ,
188
- prefix : [ "I" ] ,
205
+ selector : ` interface` ,
206
+ format : [ ` PascalCase` ] ,
207
+ prefix : [ `I` ] ,
189
208
} ,
190
209
] ,
191
210
// This rule tries to prevent using `require()`. However in node code,
192
211
// there are times where this makes sense. And it specifically is causing
193
212
// problems in our tests where we often want this functionality for module
194
213
// mocking. At this point it's easier to have it off and just encourage
195
214
// using top-level imports via code reviews.
196
- "@typescript-eslint/no-var-requires" : " off" ,
197
- "@typescript-eslint/no-extra-semi" : " off" ,
215
+ "@typescript-eslint/no-var-requires" : ` off` ,
216
+ "@typescript-eslint/no-extra-semi" : ` off` ,
198
217
// This rule ensures that typescript types do not have semicolons
199
218
// at the end of their lines, since our prettier setup is to have no semicolons
200
219
// e.g.,
@@ -203,50 +222,50 @@ module.exports = {
203
222
// + baz: string
204
223
// }
205
224
"@typescript-eslint/member-delimiter-style" : [
206
- " error" ,
225
+ ` error` ,
207
226
{
208
227
multiline : {
209
- delimiter : " none" ,
228
+ delimiter : ` none` ,
210
229
} ,
211
230
} ,
212
231
] ,
213
- "@typescript-eslint/no-empty-function" : " off" ,
232
+ "@typescript-eslint/no-empty-function" : ` off` ,
214
233
// This ensures that we always type the return type of functions
215
234
// a high level focus of our TS setup is typing fn inputs and outputs.
216
- "@typescript-eslint/explicit-function-return-type" : " error" ,
235
+ "@typescript-eslint/explicit-function-return-type" : ` error` ,
217
236
// This forces us to use interfaces over types aliases for object definitions.
218
237
// Type is still useful for opaque types
219
238
// e.g.,
220
239
// type UUID = string
221
240
"@typescript-eslint/consistent-type-definitions" : [
222
- " error" ,
223
- " interface" ,
241
+ ` error` ,
242
+ ` interface` ,
224
243
] ,
225
244
"@typescript-eslint/no-use-before-define" : [
226
- " error" ,
245
+ ` error` ,
227
246
{ functions : false } ,
228
247
] ,
229
248
// Allows us to write unions like `type Foo = "baz" | "bar"`
230
249
// otherwise eslint will want to switch the strings to backticks,
231
250
// which then crashes the ts compiler
232
- quotes : " off" ,
251
+ quotes : ` off` ,
233
252
"@typescript-eslint/quotes" : [
234
253
2 ,
235
- " backtick" ,
254
+ ` backtick` ,
236
255
{
237
256
avoidEscape : true ,
238
257
} ,
239
258
] ,
240
259
// bump to @typescript -eslint/parser started showing Flow related errors in ts(x) files
241
260
// so disabling them in .ts(x) files
242
- "flowtype/no-types-missing-file-annotation" : " off" ,
243
- "@typescript-eslint/array-type" : [ " error" , { default : " generic" } ] ,
261
+ "flowtype/no-types-missing-file-annotation" : ` off` ,
262
+ "@typescript-eslint/array-type" : [ ` error` , { default : ` generic` } ] ,
244
263
} ,
245
264
} ,
246
265
] ,
247
266
settings : {
248
267
react : {
249
- version : " 16.9.0" ,
268
+ version : ` 16.9.0` ,
250
269
} ,
251
270
} ,
252
271
}
0 commit comments