Skip to content

Commit 23c9d95

Browse files
authored
Remove 'github/no-then' eslint rule (#58220)
1 parent db3f4bf commit 23c9d95

File tree

17 files changed

+188
-248
lines changed

17 files changed

+188
-248
lines changed

eslint.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ export default [
9696
camelcase: 'off', // Many gh apis use underscores, 600+ uses
9797

9898
// Disabled rules to review
99-
'github/no-then': 'off', // 30+
10099
'@typescript-eslint/ban-ts-comment': 'off', // 50+
101100
'no-shadow': 'off', // 150+
102101
'github/array-foreach': 'off', // 250+

src/content-render/scripts/add-content-type.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,8 @@ function determineContentType(relativePath: string, legacyType: string): string
192192
return OTHER_TYPE
193193
}
194194

195-
main().catch(console.error)
195+
try {
196+
await main()
197+
} catch (error) {
198+
console.error(error)
199+
}

src/events/components/dotcom-cookies.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ async function fetchCookies(): Promise<DotcomCookies> {
4545
}
4646

4747
// Make a single fetch request to the backend.
48-
inFlightPromise = fetch(GET_COOKIES_ENDPOINT)
49-
.then((response) => {
48+
inFlightPromise = (async () => {
49+
try {
50+
const response = await fetch(GET_COOKIES_ENDPOINT)
5051
if (!response.ok) {
5152
throw new Error(`Failed to fetch cookies: ${response.statusText}`)
5253
}
53-
return response.json() as Promise<DotcomCookies>
54-
})
55-
.then((data) => {
54+
const data = (await response.json()) as DotcomCookies
5655
cachedCookies = data
5756
// Store the fetched cookies in local storage for future use.
5857
try {
@@ -61,20 +60,19 @@ async function fetchCookies(): Promise<DotcomCookies> {
6160
console.error('Error storing cookies in local storage:', e)
6261
}
6362
return data
64-
})
65-
.catch((err) => {
63+
} catch (err) {
6664
console.error('Error fetching cookies:', err)
6765
// On failure, return default values.
6866
const defaultCookies: DotcomCookies = {
6967
isStaff: false,
7068
}
7169
cachedCookies = defaultCookies
7270
return defaultCookies
73-
})
74-
.finally(() => {
71+
} finally {
7572
// Clear the in-flight promise regardless of success or failure.
7673
inFlightPromise = null
77-
})
74+
}
75+
})()
7876

7977
return inFlightPromise
8078
}

src/frame/middleware/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@ const asyncMiddleware =
8282
<TReq extends Request = Request, T = void>(
8383
fn: (req: TReq, res: Response, next: NextFunction) => T | Promise<T>,
8484
) =>
85-
(req: Request, res: Response, next: NextFunction) => {
86-
Promise.resolve(fn(req as TReq, res, next)).catch(next)
85+
async (req: Request, res: Response, next: NextFunction) => {
86+
try {
87+
await fn(req as TReq, res, next)
88+
} catch (error) {
89+
next(error)
90+
}
8791
}
8892

8993
export default function index(app: Express) {

src/ghes-releases/scripts/deprecate/archive-version.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,23 @@ async function main() {
9696
.listen(port, async () => {
9797
console.log(`started server on ${host}`)
9898

99-
await scrape({
100-
urls,
101-
urlFilter: (url: string) => {
102-
// Do not download assets from other hosts like S3 or octodex.github.com
103-
// (this will keep them as remote references in the downloaded pages)
104-
return url.startsWith(`http://localhost:${port}/`)
105-
},
106-
directory: tmpArchivalDirectory,
107-
filenameGenerator: 'bySiteStructure',
108-
requestConcurrency: 6,
109-
plugins: [new RewriteAssetPathsPlugin(tmpArchivalDirectory, localDev, GH_PAGES_URL)],
110-
}).catch((err: Error) => {
99+
try {
100+
await scrape({
101+
urls,
102+
urlFilter: (url: string) => {
103+
// Do not download assets from other hosts like S3 or octodex.github.com
104+
// (this will keep them as remote references in the downloaded pages)
105+
return url.startsWith(`http://localhost:${port}/`)
106+
},
107+
directory: tmpArchivalDirectory,
108+
filenameGenerator: 'bySiteStructure',
109+
requestConcurrency: 6,
110+
plugins: [new RewriteAssetPathsPlugin(tmpArchivalDirectory, localDev, GH_PAGES_URL)],
111+
})
112+
} catch (err) {
111113
console.error('scraping error')
112114
console.error(err)
113-
})
115+
}
114116

115117
fs.renameSync(
116118
path.join(tmpArchivalDirectory, `/localhost_${port}`),

src/ghes-releases/scripts/release-banner.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ async function main(): Promise<void> {
6868
`)
6969
}
7070

71-
main().catch((error) => {
71+
try {
72+
await main()
73+
} catch (error) {
7274
console.error('Error:', error)
7375
process.exit(1)
74-
})
76+
}

src/links/components/LinkPreviewPopover.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,19 @@ function popoverWrap(element: HTMLLinkElement, filledCallback?: (popover: HTMLDi
248248

249249
const { pathname } = new URL(element.href)
250250

251-
fetch(`/api/article/meta?${new URLSearchParams({ pathname })}`, {
252-
headers: {
253-
'X-Request-Source': 'hovercards',
254-
},
255-
}).then(async (response) => {
251+
async function fetchAndFillPopover() {
252+
const response = await fetch(`/api/article/meta?${new URLSearchParams({ pathname })}`, {
253+
headers: {
254+
'X-Request-Source': 'hovercards',
255+
},
256+
})
256257
if (response.ok) {
257258
const meta = (await response.json()) as PageMetadata
258259
fillPopover(element, meta, filledCallback)
259260
}
260-
})
261+
}
262+
263+
fetchAndFillPopover()
261264
}
262265

263266
function fillPopover(

src/links/scripts/rendered-content-link-checker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ async function limitConcurrency<T, R>(
128128
const executing = new Set<Promise<R>>()
129129

130130
for (const item of items) {
131-
const promise = asyncFn(item).then((result) => {
131+
const createPromise = async () => {
132+
const result = await asyncFn(item)
132133
executing.delete(promise)
133134
return result
134-
})
135+
}
136+
const promise = createPromise()
135137

136138
results.push(promise)
137139
executing.add(promise)

src/metrics/scripts/docstat.ts

Lines changed: 53 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,6 @@ interface CliOptions {
3939
allVersions?: boolean
4040
}
4141

42-
interface QueryResults {
43-
views?: string
44-
viewsDocset?: string
45-
users?: string
46-
usersDocset?: string
47-
viewDuration?: string
48-
viewDurationDocset?: string
49-
bounces?: string
50-
bouncesDocset?: string
51-
score?: string
52-
scoreDocset?: string
53-
exits?: string
54-
exitsDocset?: string
55-
}
56-
5742
interface JsonOutput {
5843
daysRange: string
5944
startDate: string
@@ -222,130 +207,8 @@ async function main(): Promise<void> {
222207
console.log(`\n\nSkipping comparison, since '${cleanPath}' is already a docset.\n`)
223208
}
224209

225-
// Create query promises for all requested metrics
226-
const queryPromises: Promise<void>[] = []
227-
const results: QueryResults = {}
228-
229-
// Setup all the promises for parallel execution
230-
if (options.views) {
231-
const queryType = 'views'
232-
queryPromises.push(
233-
getViews(queryPaths, client, dates, version, options.verbose, queryType).then((data) => {
234-
results.views = data
235-
}),
236-
)
237-
if (options.showDocset) {
238-
const queryType = 'docset views'
239-
queryPromises.push(
240-
getViews(docsetPath, client, dates, version, options.verbose, queryType).then((data) => {
241-
results.viewsDocset = data
242-
}),
243-
)
244-
}
245-
}
246-
247-
if (options.users) {
248-
const queryType = 'users'
249-
queryPromises.push(
250-
getUsers(queryPaths, client, dates, version, options.verbose, queryType).then((data) => {
251-
results.users = data
252-
}),
253-
)
254-
if (options.showDocset) {
255-
const queryType = 'docset users'
256-
queryPromises.push(
257-
getUsers(docsetPath, client, dates, version, options.verbose, queryType).then((data) => {
258-
results.usersDocset = data
259-
}),
260-
)
261-
}
262-
}
263-
264-
if (options.viewDuration) {
265-
const queryType = 'view duration'
266-
queryPromises.push(
267-
getViewDuration(queryPaths, client, dates, version, options.verbose, queryType).then(
268-
(data) => {
269-
results.viewDuration = data
270-
},
271-
),
272-
)
273-
if (options.showDocset) {
274-
const queryType = 'docset view duration'
275-
queryPromises.push(
276-
getViewDuration(docsetPath, client, dates, version, options.verbose, queryType).then(
277-
(data) => {
278-
results.viewDurationDocset = data
279-
},
280-
),
281-
)
282-
}
283-
}
284-
285-
if (options.bounces) {
286-
const queryType = 'bounces'
287-
queryPromises.push(
288-
getBounces(queryPaths, client, dates, version, options.verbose, queryType).then((data) => {
289-
results.bounces = data
290-
}),
291-
)
292-
if (options.showDocset) {
293-
const queryType = 'docset bounces'
294-
queryPromises.push(
295-
getBounces(docsetPath, client, dates, version, options.verbose, queryType).then(
296-
(data) => {
297-
results.bouncesDocset = data
298-
},
299-
),
300-
)
301-
}
302-
}
303-
304-
if (options.score) {
305-
const queryType = 'score'
306-
queryPromises.push(
307-
getScore(queryPaths, client, dates, version, options.verbose, queryType).then((data) => {
308-
results.score = data
309-
}),
310-
)
311-
if (options.showDocset) {
312-
const queryType = 'docset score'
313-
queryPromises.push(
314-
getScore(docsetPath, client, dates, version, options.verbose, queryType).then((data) => {
315-
results.scoreDocset = data
316-
}),
317-
)
318-
}
319-
}
320-
321-
if (options.exits) {
322-
const queryType = 'exits'
323-
queryPromises.push(
324-
getExitsToSupport(queryPaths, client, dates, version, options.verbose, queryType).then(
325-
(data) => {
326-
results.exits = data
327-
},
328-
),
329-
)
330-
if (options.showDocset) {
331-
const queryType = 'docset exits'
332-
queryPromises.push(
333-
getExitsToSupport(docsetPath, client, dates, version, options.verbose, queryType).then(
334-
(data) => {
335-
results.exitsDocset = data
336-
},
337-
),
338-
)
339-
}
340-
}
341-
342-
// Execute all queries in parallel
343-
await Promise.all(queryPromises)
344-
345-
spinner.succeed('Data retrieved successfully!\n')
346-
347-
// Extract all results from the results object
348-
const {
210+
// Execute all queries in parallel and destructure results
211+
const [
349212
views,
350213
viewsDocset,
351214
users,
@@ -358,7 +221,53 @@ async function main(): Promise<void> {
358221
scoreDocset,
359222
exits,
360223
exitsDocset,
361-
} = results
224+
] = await Promise.all([
225+
options.views
226+
? getViews(queryPaths, client, dates, version, options.verbose, 'views')
227+
: undefined,
228+
options.views && options.showDocset
229+
? getViews(docsetPath, client, dates, version, options.verbose, 'docset views')
230+
: undefined,
231+
options.users
232+
? getUsers(queryPaths, client, dates, version, options.verbose, 'users')
233+
: undefined,
234+
options.users && options.showDocset
235+
? getUsers(docsetPath, client, dates, version, options.verbose, 'docset users')
236+
: undefined,
237+
options.viewDuration
238+
? getViewDuration(queryPaths, client, dates, version, options.verbose, 'view duration')
239+
: undefined,
240+
options.viewDuration && options.showDocset
241+
? getViewDuration(
242+
docsetPath,
243+
client,
244+
dates,
245+
version,
246+
options.verbose,
247+
'docset view duration',
248+
)
249+
: undefined,
250+
options.bounces
251+
? getBounces(queryPaths, client, dates, version, options.verbose, 'bounces')
252+
: undefined,
253+
options.bounces && options.showDocset
254+
? getBounces(docsetPath, client, dates, version, options.verbose, 'docset bounces')
255+
: undefined,
256+
options.score
257+
? getScore(queryPaths, client, dates, version, options.verbose, 'score')
258+
: undefined,
259+
options.score && options.showDocset
260+
? getScore(docsetPath, client, dates, version, options.verbose, 'docset score')
261+
: undefined,
262+
options.exits
263+
? getExitsToSupport(queryPaths, client, dates, version, options.verbose, 'exits')
264+
: undefined,
265+
options.exits && options.showDocset
266+
? getExitsToSupport(docsetPath, client, dates, version, options.verbose, 'docset exits')
267+
: undefined,
268+
])
269+
270+
spinner.succeed('Data retrieved successfully!\n')
362271

363272
// Output JSON and exit
364273
if (options.json) {
@@ -491,11 +400,13 @@ async function main(): Promise<void> {
491400
}
492401
}
493402

494-
main().catch((error) => {
403+
try {
404+
await main()
405+
} catch (error) {
495406
console.error(red('Unexpected error:'))
496407
console.error(error)
497408
process.exit(1)
498-
})
409+
}
499410

500411
/* -------- UTILITY FUNCTIONS -------- */
501412

0 commit comments

Comments
 (0)