Skip to content

Commit 5636389

Browse files
wardpeetascorbic
andauthored
chore: update eslint to fix linting issues (#29988)
* chore: update eslint to fix linting issues * cleanup * remove / * Update packages/gatsby/src/commands/serve.ts Co-authored-by: Matt Kane <[email protected]> * update config * update circle to keep babel-preset-gatsby-package so we can use it in our babel config * fix unit tests * fix snapshot * fix thigns * update gatsby-node Co-authored-by: Matt Kane <[email protected]>
1 parent 7462030 commit 5636389

File tree

157 files changed

+860
-892
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+860
-892
lines changed

.babelrc.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
let ignore = [`**/dist`]
1+
const ignore = [`**/dist`]
22

33
// Jest needs to compile this code, but generally we don't want this copied
44
// to output folders
5-
if (process.env.NODE_ENV !== `test`) {
6-
ignore.push(`**/__tests__`)
7-
}
5+
// if (process.env.NODE_ENV !== `test`) {
6+
// ignore.push(`**/__tests__`)
7+
// }
88

99
module.exports = {
1010
sourceMaps: true,
11-
presets: ["babel-preset-gatsby-package"],
11+
presets: [`babel-preset-gatsby-package`],
1212
ignore,
1313
}

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ jobs:
200200
- run:
201201
name: "remove workspaces from package.json"
202202
command: |
203-
sed -i ':a;N;$!ba;s/,\n\s*"workspaces":\s\[[^]]*]//g' package.json
203+
sed -i ':a;N;$!ba;s/,\n\s*"workspaces":\s\[[^]]*]/,"workspaces":\["packages\/babel-preset-gatsby"\]/g' package.json
204204
- <<: *install_node_modules
205205
- run: yarn lint:code
206206
- run: yarn lint:docs

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ packages/gatsby/cache-dir/commonjs/**/*
2626
packages/gatsby-admin/public
2727
packages/gatsby/gatsby-admin-public
2828
packages/gatsby-codemods/transforms
29+
packages/gatsby-source-graphql/batching
2930

3031
packages/gatsby-source-wordpress/test-site/**
3132
!packages/gatsby-source-wordpress/test-site/__tests__

.eslintrc.js

+115-96
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
const TSEslint = require("@typescript-eslint/eslint-plugin")
2-
31
module.exports = {
4-
parser: "babel-eslint",
2+
parser: `@babel/eslint-parser`,
53
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`,
139
],
14-
plugins: ["flowtype", "prettier", "react", "filenames"],
10+
plugins: [`flowtype`, `prettier`, `react`, `filenames`, `@babel`],
1511
parserOptions: {
1612
ecmaVersion: 2016,
17-
sourceType: "module",
13+
sourceType: `module`,
1814
ecmaFeatures: {
1915
jsx: true,
2016
},
17+
babelOptions: {
18+
configFile: `./.babelrc.js`,
19+
},
2120
},
2221
env: {
2322
browser: true,
@@ -39,43 +38,63 @@ module.exports = {
3938
__ASSET_PREFIX__: true,
4039
},
4140
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`,
4943
{
5044
allowTaggedTemplates: true,
5145
},
5246
],
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`,
5356
"no-unused-vars": [
54-
"warn",
57+
`warn`,
5558
{
56-
varsIgnorePattern: "^_",
57-
argsIgnorePattern: "^_",
59+
varsIgnorePattern: `^_`,
60+
argsIgnorePattern: `^_`,
5861
ignoreRestSiblings: true,
5962
},
6063
],
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+
],
7392
},
7493
overrides: [
7594
{
7695
files: [
77-
"packages/**/gatsby-browser.js",
78-
"packages/gatsby/cache-dir/**/*",
96+
`packages/**/gatsby-browser.js`,
97+
`packages/gatsby/cache-dir/**/*`,
7998
],
8099
env: {
81100
browser: true,
@@ -86,115 +105,115 @@ module.exports = {
86105
},
87106
},
88107
{
89-
files: ["**/cypress/integration/**/*", "**/cypress/support/**/*"],
108+
files: [`**/cypress/integration/**/*`, `**/cypress/support/**/*`],
90109
globals: {
91110
cy: false,
92111
Cypress: false,
93112
},
94113
},
95114
{
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`],
99119
rules: {
100-
...TSEslint.configs.recommended.rules,
101120
// We should absolutely avoid using ts-ignore, but it's not always possible.
102121
// particular when a dependencies types are incorrect.
103122
"@typescript-eslint/ban-ts-comment": [
104-
"warn",
105-
{ "ts-ignore": "allow-with-description" }
123+
`warn`,
124+
{ "ts-ignore": `allow-with-description` },
106125
],
107126
// This rule is great. It helps us not throw on types for areas that are
108127
// easily inferrable. However we have a desire to have all function inputs
109128
// and outputs declaratively typed. So this let's us ignore the parameters
110129
// inferrable lint.
111130
"@typescript-eslint/no-inferrable-types": [
112-
"error",
131+
`error`,
113132
{ ignoreParameters: true },
114133
],
115134
"@typescript-eslint/ban-types": [
116-
"error",
135+
`error`,
117136
{
118137
extendDefaults: true,
119138
types: {
120139
"{}": {
121-
fixWith: "Record<string, unknown>",
140+
fixWith: `Record<string, unknown>`,
122141
},
123142
object: {
124-
fixWith: "Record<string, unknown>",
143+
fixWith: `Record<string, unknown>`,
125144
},
126145
},
127146
},
128147
],
129-
"camelcase": "off",
148+
camelcase: `off`,
130149
// 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
131150
"@typescript-eslint/naming-convention": [
132-
"error",
151+
`error`,
133152
{
134-
selector: "default",
135-
format: ["camelCase"],
153+
selector: `default`,
154+
format: [`camelCase`],
136155
},
137156
{
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`,
142161
},
143162
{
144-
selector: "function",
145-
format: ["camelCase", "PascalCase"],
146-
leadingUnderscore: "allow",
163+
selector: `function`,
164+
format: [`camelCase`, `PascalCase`],
165+
leadingUnderscore: `allow`,
147166
},
148167
{
149-
selector: "parameter",
150-
format: ["camelCase", "PascalCase", "snake_case"],
151-
leadingUnderscore: "allowSingleOrDouble",
168+
selector: `parameter`,
169+
format: [`camelCase`, `PascalCase`, `snake_case`],
170+
leadingUnderscore: `allowSingleOrDouble`,
152171
},
153172
{
154-
selector: "enumMember",
155-
format: ["camelCase", "UPPER_CASE", "PascalCase"]
173+
selector: `enumMember`,
174+
format: [`camelCase`, `UPPER_CASE`, `PascalCase`],
156175
},
157176
{
158-
selector: "typeLike",
159-
format: ["PascalCase"],
177+
selector: `typeLike`,
178+
format: [`PascalCase`],
160179
},
161180
{
162-
selector: "typeAlias",
163-
format: ["camelCase", "PascalCase"]
181+
selector: `typeAlias`,
182+
format: [`camelCase`, `PascalCase`],
164183
},
165184
{
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`,
169188
},
170189
{
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`,
175194
},
176195
{
177-
selector: "enum",
178-
format: ["PascalCase", "UPPER_CASE"]
196+
selector: `enum`,
197+
format: [`PascalCase`, `UPPER_CASE`],
179198
},
180199
{
181-
selector: "method",
182-
format: ["PascalCase", "camelCase"],
183-
leadingUnderscore: "allowSingleOrDouble",
200+
selector: `method`,
201+
format: [`PascalCase`, `camelCase`],
202+
leadingUnderscore: `allowSingleOrDouble`,
184203
},
185204
{
186-
selector: "interface",
187-
format: ["PascalCase"],
188-
prefix: ["I"],
205+
selector: `interface`,
206+
format: [`PascalCase`],
207+
prefix: [`I`],
189208
},
190209
],
191210
// This rule tries to prevent using `require()`. However in node code,
192211
// there are times where this makes sense. And it specifically is causing
193212
// problems in our tests where we often want this functionality for module
194213
// mocking. At this point it's easier to have it off and just encourage
195214
// 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`,
198217
// This rule ensures that typescript types do not have semicolons
199218
// at the end of their lines, since our prettier setup is to have no semicolons
200219
// e.g.,
@@ -203,50 +222,50 @@ module.exports = {
203222
// + baz: string
204223
// }
205224
"@typescript-eslint/member-delimiter-style": [
206-
"error",
225+
`error`,
207226
{
208227
multiline: {
209-
delimiter: "none",
228+
delimiter: `none`,
210229
},
211230
},
212231
],
213-
"@typescript-eslint/no-empty-function": "off",
232+
"@typescript-eslint/no-empty-function": `off`,
214233
// This ensures that we always type the return type of functions
215234
// 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`,
217236
// This forces us to use interfaces over types aliases for object definitions.
218237
// Type is still useful for opaque types
219238
// e.g.,
220239
// type UUID = string
221240
"@typescript-eslint/consistent-type-definitions": [
222-
"error",
223-
"interface",
241+
`error`,
242+
`interface`,
224243
],
225244
"@typescript-eslint/no-use-before-define": [
226-
"error",
245+
`error`,
227246
{ functions: false },
228247
],
229248
// Allows us to write unions like `type Foo = "baz" | "bar"`
230249
// otherwise eslint will want to switch the strings to backticks,
231250
// which then crashes the ts compiler
232-
quotes: "off",
251+
quotes: `off`,
233252
"@typescript-eslint/quotes": [
234253
2,
235-
"backtick",
254+
`backtick`,
236255
{
237256
avoidEscape: true,
238257
},
239258
],
240259
// bump to @typescript-eslint/parser started showing Flow related errors in ts(x) files
241260
// 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` }],
244263
},
245264
},
246265
],
247266
settings: {
248267
react: {
249-
version: "16.9.0",
268+
version: `16.9.0`,
250269
},
251270
},
252271
}

deprecated-packages/gatsby-plugin-guess-js/src/gatsby-ssr.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ exports.onRenderBody = (
4141
matchedPages.forEach(p => {
4242
if (p && p.componentChunkName) {
4343
const fetchKey = `assetsByChunkName[${p.componentChunkName}]`
44-
let chunks = _.get(stats, fetchKey)
44+
const chunks = _.get(stats, fetchKey)
4545
componentUrls = [...componentUrls, ...chunks]
4646
}
4747
})

0 commit comments

Comments
 (0)