Skip to content

Commit 7de6e62

Browse files
authored
chore: migrate packages/errors to modern eslint (#32313)
1 parent b944511 commit 7de6e62

File tree

9 files changed

+48
-42
lines changed

9 files changed

+48
-42
lines changed

guides/eslint-migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
- [ ] packages/socket
4141
- [ ] packages/telemetry
4242
- [ ] packages/launchpad
43-
- [ ] packages/errors
43+
- [x] packages/errors
4444
- [ ] packages/data-context
4545
- [ ] packages/app
4646

packages/errors/.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/errors/.mocharc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
extension: ['ts'],
66
reporter: 'mocha-multi-reporters',
77
reporterOptions: {
8-
configFile: '../../mocha-reporter-config.json'
8+
configFile: '../../mocha-reporter-config.json',
99
},
10-
exit: true
11-
}
10+
exit: true,
11+
}

packages/errors/eslint.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { baseConfig } from '@packages/eslint-config'
2+
3+
export default baseConfig

packages/errors/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"clean": "rimraf ./src/*.js ./src/**/*.js ./src/**/**/*.js ./test/**/*.js || echo 'cleaned'",
1212
"clean-deps": "rimraf node_modules",
1313
"comparison": "node -r @packages/ts/register test/support/error-comparison-tool.ts",
14-
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json, .",
14+
"lint": "eslint",
1515
"test": "yarn test-unit",
1616
"test-electron": "HTML_IMAGE_CONVERSION=1 xvfb-maybe electron --no-sandbox ./node_modules/.bin/_mocha",
1717
"pretest-unit": "yarn clean",
@@ -27,6 +27,7 @@
2727
"strip-ansi": "6.0.1"
2828
},
2929
"devDependencies": {
30+
"@packages/eslint-config": "0.0.0-development",
3031
"@packages/server": "0.0.0-development",
3132
"@packages/ts": "0.0.0-development",
3233
"@packages/types": "0.0.0-development",
@@ -37,7 +38,9 @@
3738
"ansi-styles": "^5",
3839
"chai": "4.2.0",
3940
"ci-info": "^4.1.0",
41+
"eslint": "^9.31.0",
4042
"globby": "^11.1.0",
43+
"jiti": "^2.4.2",
4144
"mocha": "7.0.1",
4245
"pngjs": "^7.0.0",
4346
"rimraf": "5.0.10",
@@ -50,5 +53,8 @@
5053
"dist"
5154
],
5255
"types": "src/index.ts",
56+
"lint-staged": {
57+
"**/*.{js,jsx,ts,tsx,json}": "eslint --fix"
58+
},
5359
"nx": {}
5460
}

packages/errors/src/errors.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import AU from 'ansi_up'
22
import os from 'os'
3-
/* eslint-disable no-console */
3+
44
import chalk from 'chalk'
55
import _ from 'lodash'
66
import path from 'path'
@@ -145,7 +145,7 @@ export const AllCypressErrors = {
145145
return errTemplate`${fmt.off(`\n `)}This spec and its tests were skipped because the run has been canceled.`
146146
},
147147
CLOUD_API_RESPONSE_FAILED_RETRYING: (
148-
arg1: {tries: number, delayMs: number, response: Error },
148+
arg1: { tries: number, delayMs: number, response: Error },
149149
) => {
150150
const time = pluralize('time', arg1.tries)
151151
const delay = humanTime.long(arg1.delayMs, false)
@@ -160,9 +160,8 @@ export const AllCypressErrors = {
160160
We will retry ${fmt.off(arg1.tries)} more ${fmt.off(time)} in ${fmt.off(delay)}...
161161
`
162162
/* Because of fmt.listFlags() and fmt.listItems() */
163-
/* eslint-disable indent */
164163
},
165-
CLOUD_CANNOT_PROCEED_IN_PARALLEL: (arg1: {flags: any, response: Error}) => {
164+
CLOUD_CANNOT_PROCEED_IN_PARALLEL: (arg1: { flags: any, response: Error }) => {
166165
const message = normalizeNetworkErrorMessage(arg1.response)
167166

168167
return errTemplate`\
@@ -177,7 +176,7 @@ export const AllCypressErrors = {
177176
ciBuildId: '--ciBuildId',
178177
})}`
179178
},
180-
CLOUD_CANNOT_PROCEED_IN_SERIAL: (arg1: {flags: any, response: Error}) => {
179+
CLOUD_CANNOT_PROCEED_IN_SERIAL: (arg1: { flags: any, response: Error }) => {
181180
const message = normalizeNetworkErrorMessage(arg1.response)
182181

183182
return errTemplate`\
@@ -192,7 +191,7 @@ export const AllCypressErrors = {
192191
ciBuildId: '--ciBuildId',
193192
})}`
194193
},
195-
CLOUD_UNKNOWN_INVALID_REQUEST: (arg1: {flags: any, response: Error}) => {
194+
CLOUD_UNKNOWN_INVALID_REQUEST: (arg1: { flags: any, response: Error }) => {
196195
const message = normalizeNetworkErrorMessage(arg1.response)
197196

198197
return errTemplate`\
@@ -209,7 +208,7 @@ export const AllCypressErrors = {
209208
ciBuildId: '--ciBuildId',
210209
})}`
211210
},
212-
CLOUD_UNKNOWN_CREATE_RUN_WARNING: (arg1: {props?: any, message: string}) => {
211+
CLOUD_UNKNOWN_CREATE_RUN_WARNING: (arg1: { props?: any, message: string }) => {
213212
if (!Object.keys(arg1.props).length) {
214213
return errTemplate`\
215214
Warning from Cypress Cloud: ${fmt.highlight(arg1.message)}
@@ -222,7 +221,7 @@ export const AllCypressErrors = {
222221
Details:
223222
${fmt.meta(arg1.props)}`
224223
},
225-
CLOUD_STALE_RUN: (arg1: {runUrl: string, [key: string]: any}) => {
224+
CLOUD_STALE_RUN: (arg1: { runUrl: string, [key: string]: any }) => {
226225
return errTemplate`\
227226
You are attempting to pass the ${fmt.flag(`--parallel`)} flag to a run that was completed over 24 hours ago.
228227
@@ -239,7 +238,7 @@ export const AllCypressErrors = {
239238
240239
https://on.cypress.io/stale-run`
241240
},
242-
CLOUD_ALREADY_COMPLETE: (props: {runUrl: string, tags: string, group: string, parallel: string, ciBuildId: string}) => {
241+
CLOUD_ALREADY_COMPLETE: (props: { runUrl: string, tags: string, group: string, parallel: string, ciBuildId: string }) => {
243242
return errTemplate`\
244243
The run you are attempting to access is already complete and will not accept new groups.
245244
@@ -256,7 +255,7 @@ export const AllCypressErrors = {
256255
257256
https://on.cypress.io/already-complete`
258257
},
259-
CLOUD_PARALLEL_REQUIRED: (arg1: {tags: string, group: string, runUrl: string, ciBuildId: string }) => {
258+
CLOUD_PARALLEL_REQUIRED: (arg1: { tags: string, group: string, runUrl: string, ciBuildId: string }) => {
260259
return errTemplate`\
261260
You did not pass the ${fmt.flag(`--parallel`)} flag, but this run's group was originally created with the --parallel flag.
262261
@@ -273,7 +272,7 @@ export const AllCypressErrors = {
273272
274273
https://on.cypress.io/parallel-required`
275274
},
276-
CLOUD_PARALLEL_DISALLOWED: (arg1: {tags: string, group: string, runUrl: string, ciBuildId: string}) => {
275+
CLOUD_PARALLEL_DISALLOWED: (arg1: { tags: string, group: string, runUrl: string, ciBuildId: string }) => {
277276
return errTemplate`\
278277
You passed the ${fmt.flag(`--parallel`)} flag, but this run group was originally created without the --parallel flag.
279278
@@ -290,7 +289,7 @@ export const AllCypressErrors = {
290289
291290
https://on.cypress.io/parallel-disallowed`
292291
},
293-
CLOUD_PARALLEL_GROUP_PARAMS_MISMATCH: (arg1: {group: string, runUrl: string, ciBuildId: string, parameters: any, payload: any }) => {
292+
CLOUD_PARALLEL_GROUP_PARAMS_MISMATCH: (arg1: { group: string, runUrl: string, ciBuildId: string, parameters: any, payload: any }) => {
294293
let params: any = arg1.parameters
295294

296295
if (arg1.payload?.differentParams) {
@@ -344,7 +343,7 @@ export const AllCypressErrors = {
344343
345344
https://on.cypress.io/parallel-group-params-mismatch`
346345
},
347-
CLOUD_RUN_GROUP_NAME_NOT_UNIQUE: (arg1: {group: string, runUrl: string, ciBuildId?: string | null}) => {
346+
CLOUD_RUN_GROUP_NAME_NOT_UNIQUE: (arg1: { group: string, runUrl: string, ciBuildId?: string | null }) => {
348347
return errTemplate`\
349348
You passed the ${fmt.flag(`--group`)} flag, but this group name has already been used for this run.
350349
@@ -362,15 +361,15 @@ export const AllCypressErrors = {
362361
363362
https://on.cypress.io/run-group-name-not-unique`
364363
},
365-
CLOUD_AUTO_CANCEL_NOT_AVAILABLE_IN_PLAN: (arg1: {link: string}) => {
364+
CLOUD_AUTO_CANCEL_NOT_AVAILABLE_IN_PLAN: (arg1: { link: string }) => {
366365
return errTemplate`\
367366
${fmt.highlightSecondary(`Auto Cancellation`)} is not included under your current billing plan.
368367
369368
To enable this service, please visit your billing and upgrade to another plan with Auto Cancellation.
370369
371370
${fmt.off(arg1.link)}`
372371
},
373-
CLOUD_AUTO_CANCEL_MISMATCH: (arg1: {runUrl: string, tags: string, group: string, parallel: string, ciBuildId: string, autoCancelAfterFailures: string }) => {
372+
CLOUD_AUTO_CANCEL_MISMATCH: (arg1: { runUrl: string, tags: string, group: string, parallel: string, ciBuildId: string, autoCancelAfterFailures: string }) => {
374373
return errTemplate`\
375374
You passed the ${fmt.flag(`--auto-cancel-after-failures`)} flag, but this run originally started with a different value for the ${fmt.flag(`--auto-cancel-after-failures`)} flag.
376375
@@ -442,7 +441,6 @@ export const AllCypressErrors = {
442441
The --ci-build-id flag is used to either group or parallelize multiple runs together.
443442
444443
https://on.cypress.io/incorrect-ci-build-id-usage`
445-
/* eslint-enable indent */
446444
},
447445
RECORD_KEY_MISSING: () => {
448446
return errTemplate`\
@@ -487,7 +485,7 @@ export const AllCypressErrors = {
487485
488486
https://on.cypress.io/recording-project-runs`
489487
},
490-
CLOUD_INVALID_RUN_REQUEST: (arg1: {message: string, errors: string[], object: object}) => {
488+
CLOUD_INVALID_RUN_REQUEST: (arg1: { message: string, errors: string[], object: object }) => {
491489
return errTemplate`\
492490
Recording this run failed. The request was invalid.
493491
@@ -626,7 +624,7 @@ export const AllCypressErrors = {
626624
return AllCypressErrors.CLOUD_PROTOCOL_UPLOAD_NETWORK_FAILURE(firstError as Error & { url: string })
627625
}
628626

629-
return AllCypressErrors.CLOUD_PROTOCOL_UPLOAD_HTTP_FAILURE(error.errors[0] as Error & { url: string, status: number, statusText: string, responseBody: string})
627+
return AllCypressErrors.CLOUD_PROTOCOL_UPLOAD_HTTP_FAILURE(error.errors[0] as Error & { url: string, status: number, statusText: string, responseBody: string })
630628
}
631629

632630
let systemErr = error.errors.find((err) => {
@@ -931,7 +929,7 @@ export const AllCypressErrors = {
931929
932930
Instead the value was: ${fmt.stringify(value)}`
933931
},
934-
RENAMED_CONFIG_OPTION: (arg1: {name: string, newName: string}) => {
932+
RENAMED_CONFIG_OPTION: (arg1: { name: string, newName: string }) => {
935933
return errTemplate`\
936934
The ${fmt.highlight(arg1.name)} configuration option you have supplied has been renamed.
937935
@@ -952,7 +950,7 @@ export const AllCypressErrors = {
952950
This server has been configured as your ${fmt.highlight(`baseUrl`)}, and tests will likely fail if it is not running.`
953951
},
954952
// TODO: test this
955-
CANNOT_CONNECT_BASE_URL_RETRYING: (arg1: {attempt: number, baseUrl: string, remaining: number, delay: number}) => {
953+
CANNOT_CONNECT_BASE_URL_RETRYING: (arg1: { attempt: number, baseUrl: string, remaining: number, delay: number }) => {
956954
switch (arg1.attempt) {
957955
case 1:
958956
return errTemplate`\
@@ -970,7 +968,7 @@ export const AllCypressErrors = {
970968
}
971969
},
972970
// TODO: test this
973-
INVALID_REPORTER_NAME: (arg1: {name: string, paths: string[], error: Error}) => {
971+
INVALID_REPORTER_NAME: (arg1: { name: string, paths: string[], error: Error }) => {
974972
return errTemplate`\
975973
Error loading the reporter: ${fmt.highlight(arg1.name)}
976974
@@ -1016,15 +1014,15 @@ export const AllCypressErrors = {
10161014
10171015
https://on.cypress.io/installing-cypress`
10181016
},
1019-
FREE_PLAN_EXCEEDS_MONTHLY_TESTS: (arg1: {link: string, usedTestsMessage: string, limit: number}) => {
1017+
FREE_PLAN_EXCEEDS_MONTHLY_TESTS: (arg1: { link: string, usedTestsMessage: string, limit: number }) => {
10201018
return errTemplate`\
10211019
You've exceeded the limit of test results under your free plan this month. ${getUsedTestsMessage(arg1.limit, arg1.usedTestsMessage)}
10221020
10231021
To continue recording tests this month you must upgrade your account. Please visit your billing to upgrade to another billing plan.
10241022
10251023
${fmt.off(arg1.link)}`
10261024
},
1027-
FREE_PLAN_IN_GRACE_PERIOD_EXCEEDS_MONTHLY_TESTS: (arg1: {link: string, usedTestsMessage: string, gracePeriodMessage: string, limit: number}) => {
1025+
FREE_PLAN_IN_GRACE_PERIOD_EXCEEDS_MONTHLY_TESTS: (arg1: { link: string, usedTestsMessage: string, gracePeriodMessage: string, limit: number }) => {
10281026
return errTemplate`\
10291027
You've exceeded the limit of test results under your free plan this month. ${getUsedTestsMessage(arg1.limit, arg1.usedTestsMessage)}
10301028
@@ -1034,39 +1032,39 @@ export const AllCypressErrors = {
10341032
10351033
${fmt.off(arg1.link)}`
10361034
},
1037-
PLAN_EXCEEDS_MONTHLY_TESTS: (arg1: {link: string, planType: string, usedTestsMessage: string, limit: number}) => {
1035+
PLAN_EXCEEDS_MONTHLY_TESTS: (arg1: { link: string, planType: string, usedTestsMessage: string, limit: number }) => {
10381036
return errTemplate`\
10391037
You've exceeded the limit of test results under your ${fmt.highlight(arg1.planType)} billing plan this month. ${getUsedTestsMessage(arg1.limit, arg1.usedTestsMessage)}
10401038
10411039
To continue getting the full benefits of your current plan, please visit your billing to upgrade.
10421040
10431041
${fmt.off(arg1.link)}`
10441042
},
1045-
FREE_PLAN_IN_GRACE_PERIOD_PARALLEL_FEATURE: (arg1: {link: string, gracePeriodMessage: string}) => {
1043+
FREE_PLAN_IN_GRACE_PERIOD_PARALLEL_FEATURE: (arg1: { link: string, gracePeriodMessage: string }) => {
10461044
return errTemplate`\
10471045
${fmt.highlightSecondary(`Parallelization`)} is not included under your free plan.
10481046
10491047
Your plan is now in a grace period, which means your tests will still run in parallel until ${fmt.highlight(arg1.gracePeriodMessage)}. Please upgrade your plan to continue running your tests in parallel in the future.
10501048
10511049
${fmt.off(arg1.link)}`
10521050
},
1053-
PARALLEL_FEATURE_NOT_AVAILABLE_IN_PLAN: (arg1: {link: string}) => {
1051+
PARALLEL_FEATURE_NOT_AVAILABLE_IN_PLAN: (arg1: { link: string }) => {
10541052
return errTemplate`\
10551053
${fmt.highlightSecondary(`Parallelization`)} is not included under your current billing plan.
10561054
10571055
To run your tests in parallel, please visit your billing and upgrade to another plan with parallelization.
10581056
10591057
${fmt.off(arg1.link)}`
10601058
},
1061-
PLAN_IN_GRACE_PERIOD_RUN_GROUPING_FEATURE_USED: (arg1: {link: string, gracePeriodMessage: string}) => {
1059+
PLAN_IN_GRACE_PERIOD_RUN_GROUPING_FEATURE_USED: (arg1: { link: string, gracePeriodMessage: string }) => {
10621060
return errTemplate`\
10631061
${fmt.highlightSecondary(`Grouping`)} is not included under your free plan.
10641062
10651063
Your plan is now in a grace period, which means your tests will still run with groups until ${fmt.highlight(arg1.gracePeriodMessage)}. Please upgrade your plan to continue running your tests with groups in the future.
10661064
10671065
${fmt.off(arg1.link)}`
10681066
},
1069-
RUN_GROUPING_FEATURE_NOT_AVAILABLE_IN_PLAN: (arg1: {link: string}) => {
1067+
RUN_GROUPING_FEATURE_NOT_AVAILABLE_IN_PLAN: (arg1: { link: string }) => {
10701068
return errTemplate`\
10711069
${fmt.highlightSecondary(`Grouping`)} is not included under your current billing plan.
10721070
@@ -1113,7 +1111,7 @@ export const AllCypressErrors = {
11131111
11141112
CYPRESS_INTERNAL_ENV is reserved for internal use and cannot be modified.`
11151113
},
1116-
CDP_VERSION_TOO_OLD: (minimumVersion: string, currentVersion: {major: number, minor: string | number}) => {
1114+
CDP_VERSION_TOO_OLD: (minimumVersion: string, currentVersion: { major: number, minor: string | number }) => {
11171115
const phrase = currentVersion.major !== 0
11181116
? fmt.highlight(`${currentVersion.major}.${currentVersion.minor}`)
11191117
: fmt.off('an older version')
@@ -1636,7 +1634,7 @@ interface GenericError extends Error {
16361634
[key: string]: any
16371635
}
16381636

1639-
export const cloneErr = function (err: CypressError | GenericError, options: {html?: boolean} = {}) {
1637+
export const cloneErr = function (err: CypressError | GenericError, options: { html?: boolean } = {}) {
16401638
_.defaults(options, {
16411639
html: false,
16421640
})

packages/errors/src/stackUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ErrorLike } from './errorTypes'
33

44
export const stackLineRegex = /^\s*(at )?.*@?(?:\(?.*(?::\d+:\d+|<unknown>|\[native code\])+\)?)$/
55

6-
type MessageLines = [string[], string[]] & {messageEnded?: boolean}
6+
type MessageLines = [string[], string[]] & { messageEnded?: boolean }
77

88
// returns tuple of [message, stack]
99
export const splitStack = (stack: string) => {

packages/errors/test/support/error-comparison-tool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ app.get('/base-list', async (req, res) => {
140140
}
141141
})
142142

143-
app.get<{offset: number}>('/load-more/:offset', async (req, res) => {
143+
app.get<{ offset: number }>('/load-more/:offset', async (req, res) => {
144144
const rows = await getRows(req.params.offset)
145145

146146
res.send(rows)
147147
})
148148

149-
app.get<{offset: number}>('/load-more-base/:offset', async (req, res) => {
149+
app.get<{ offset: number }>('/load-more-base/:offset', async (req, res) => {
150150
const rows = await getRows(req.params.offset, true)
151151

152152
res.send(rows)
@@ -166,7 +166,7 @@ app.get('/looks-good/:name', async (req, res) => {
166166
}
167167
})
168168

169-
app.get<{name: string, type: string}>('/html/:name/:type', async (req, res) => {
169+
app.get<{ name: string, type: string }>('/html/:name/:type', async (req, res) => {
170170
const pathToFile = path.join(ERRORS_DIR, req.params.type, `${req.params.name}.html`)
171171

172172
try {

packages/errors/test/unit/visualSnapshotErrors_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ const testVisualError = <K extends CypressErrorType> (errorGeneratorFn: () => Er
185185
}
186186
}
187187

188-
const testVisualErrors = (whichError: CypressErrorType | '*', errorsToTest: {[K in CypressErrorType]: () => ErrorGenerator<K>}) => {
188+
const testVisualErrors = (whichError: CypressErrorType | '*', errorsToTest: { [K in CypressErrorType]: () => ErrorGenerator<K> }) => {
189189
// if we aren't testing all the errors
190190
if (whichError !== '*') {
191191
// then just test this individual error
@@ -291,7 +291,7 @@ const makeErr = () => {
291291

292292
err.stack = err.stack?.split('\n').slice(0, 3).join('\n') ?? ''
293293

294-
return err as Error & {stack: string}
294+
return err as Error & { stack: string }
295295
}
296296

297297
process.on('uncaughtException', (err) => {

0 commit comments

Comments
 (0)