Skip to content

Commit cceb800

Browse files
heiskrCopilot
andauthored
Remove explicit any types from multiple files (#59576)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c2b6f1b commit cceb800

39 files changed

+205
-251
lines changed

eslint.config.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,11 @@ export default [
230230
'src/content-render/unified/annotate.ts',
231231
'src/content-render/unified/code-header.ts',
232232
'src/content-render/unified/copilot-prompt.ts',
233-
'src/content-render/unified/heading-links.ts',
234233
'src/content-render/unified/index.ts',
235234
'src/content-render/unified/module-types.d.ts',
236-
'src/content-render/unified/parse-info-string.ts',
237235
'src/content-render/unified/rewrite-empty-table-rows.ts',
238236
'src/content-render/unified/rewrite-for-rowheaders.ts',
239237
'src/content-render/unified/rewrite-local-links.ts',
240-
'src/content-render/unified/rewrite-table-captions.ts',
241-
'src/content-render/unified/rewrite-thead-th-scope.ts',
242238
'src/data-directory/lib/data-directory.ts',
243239
'src/data-directory/lib/data-schemas/features.ts',
244240
'src/data-directory/lib/data-schemas/learning-tracks.ts',
@@ -247,12 +243,6 @@ export default [
247243
'src/dev-toc/generate.ts',
248244
'src/early-access/scripts/migrate-early-access-product.ts',
249245
'src/early-access/scripts/what-docs-early-access-branch.ts',
250-
'src/events/components/events.ts',
251-
'src/events/components/experiments/experiment.ts',
252-
'src/events/lib/analyze-comment.ts',
253-
'src/events/lib/hydro.ts',
254-
'src/events/lib/middleware-errors.ts',
255-
'src/events/middleware.ts',
256246
'src/fixtures/tests/categories-and-subcategory.ts',
257247
'src/fixtures/tests/glossary.ts',
258248
'src/fixtures/tests/guides.ts',
@@ -264,19 +254,13 @@ export default [
264254
'src/frame/components/context/CategoryLandingContext.tsx',
265255
'src/frame/components/context/MainContext.tsx',
266256
'src/frame/components/context/TocLandingContext.tsx',
267-
'src/frame/components/hooks/useQueryParam.ts',
268-
'src/frame/components/ui/BumpLink/BumpLink.tsx',
269257
'src/frame/lib/create-tree.ts',
270258
'src/frame/lib/frontmatter.ts',
271-
'src/frame/lib/get-remote-json.ts',
272259
'src/frame/lib/page-data.ts',
273260
'src/frame/lib/page.ts',
274-
'src/frame/lib/read-file-contents.ts',
275261
'src/frame/lib/read-frontmatter.ts',
276-
'src/frame/lib/read-json-file.ts',
277262
'src/frame/middleware/find-page.ts',
278263
'src/frame/middleware/resolve-carousels.ts',
279-
'src/frame/middleware/set-fastly-surrogate-key.ts',
280264
'src/frame/tests/page.ts',
281265
'src/frame/tests/read-frontmatter.ts',
282266
'src/frame/tests/server.ts',
@@ -300,7 +284,6 @@ export default [
300284
'src/landings/components/SidebarProduct.tsx',
301285
'src/landings/pages/home.tsx',
302286
'src/landings/pages/product.tsx',
303-
'src/landings/tests/octicons.test.ts',
304287
'src/languages/lib/correct-translation-content.ts',
305288
'src/languages/lib/get-alert-titles.ts',
306289
'src/languages/lib/render-with-fallback.ts',
@@ -310,12 +293,6 @@ export default [
310293
'src/links/scripts/check-github-github-links.ts',
311294
'src/links/scripts/update-internal-links.ts',
312295
'src/links/tests/extract-links.ts',
313-
'src/observability/logger/index.ts',
314-
'src/observability/logger/lib/logger-context.ts',
315-
'src/observability/logger/lib/to-logfmt.ts',
316-
'src/observability/middleware/catch-middleware-error.ts',
317-
'src/observability/tests/logger.ts',
318-
'src/observability/tests/to-logfmt.test.ts',
319296
'src/pages/_error.tsx',
320297
'src/products/tests/get-product-groups.ts',
321298
'src/redirects/middleware/handle-redirects.ts',
@@ -348,8 +325,6 @@ export default [
348325
'src/search/scripts/index/utils/indexing-elasticsearch-utils.ts',
349326
'src/search/scripts/scrape/lib/parse-page-sections-into-records.ts',
350327
'src/search/tests/topics.ts',
351-
'src/shielding/middleware/handle-invalid-query-string-values.ts',
352-
'src/shielding/middleware/handle-invalid-query-strings.ts',
353328
'src/tests/helpers/check-url.ts',
354329
'src/tests/helpers/e2etest.ts',
355330
'src/tests/scripts/copy-fixture-data.ts',
@@ -362,18 +337,13 @@ export default [
362337
'src/types/primer__octicons.d.ts',
363338
'src/versions/scripts/update-versioning-in-files.ts',
364339
'src/versions/scripts/use-short-versions.ts',
365-
'src/versions/tests/get-applicable-versions.ts',
366340
'src/webhooks/lib/index.ts',
367341
'src/webhooks/scripts/webhook.ts',
368342
'src/workflows/content-changes-table-comment.ts',
369-
'src/workflows/enable-automerge.ts',
370343
'src/workflows/fr-add-docs-reviewers-requests.ts',
371344
'src/workflows/git-utils.ts',
372-
'src/workflows/issue-report.ts',
373345
'src/workflows/projects.ts',
374346
'src/workflows/tests/actions-workflows.ts',
375-
'src/workflows/unallowed-contributions.ts',
376-
'src/workflows/walk-files.ts',
377347
],
378348
rules: {
379349
'@typescript-eslint/no-explicit-any': 'off',

src/archives/middleware/archived-enterprise-versions.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,16 @@ type ArchivedRedirects = {
3939
// These files are huge so lazy-load them. But note that the
4040
// `readJsonFileLazily()` function will, at import-time, check that
4141
// the path does exist.
42-
const archivedRedirects: () => ArchivedRedirects = readCompressedJsonFileFallbackLazily(
42+
const archivedRedirects = readCompressedJsonFileFallbackLazily(
4343
'./src/redirects/lib/static/archived-redirects-from-213-to-217.json',
44-
)
44+
) as () => ArchivedRedirects
4545

4646
type ArchivedFrontmatterURLs = {
4747
[url: string]: string[]
4848
}
49-
const archivedFrontmatterValidURLS: () => ArchivedFrontmatterURLs =
50-
readCompressedJsonFileFallbackLazily(
51-
'./src/redirects/lib/static/archived-frontmatter-valid-urls.json',
52-
)
49+
const archivedFrontmatterValidURLS = readCompressedJsonFileFallbackLazily(
50+
'./src/redirects/lib/static/archived-frontmatter-valid-urls.json',
51+
) as () => ArchivedFrontmatterURLs
5352

5453
// Combine all the things you need to make sure the response is
5554
// aggressively cached.
@@ -121,15 +120,15 @@ export default async function archivedEnterpriseVersions(
121120
return res.redirect(redirectCode, redirectTo)
122121
}
123122

124-
const redirectJson = await getRemoteJSON(getProxyPath('redirects.json', requestedVersion), {
123+
const redirectJson = (await getRemoteJSON(getProxyPath('redirects.json', requestedVersion), {
125124
retry: retryConfiguration,
126125
// This is allowed to be different compared to the other requests
127126
// we make because downloading the `redirects.json` once is very
128127
// useful because it caches so well.
129128
// And, as of 2021 that `redirects.json` is 10MB so it's more likely
130129
// to time out.
131130
timeout: { response: 1000 },
132-
})
131+
})) as Record<string, string>
133132
if (!req.context) throw new Error('No context on request')
134133
const [language, withoutLanguage] = splitPathByLanguage(req.path, req.context.userLanguage)
135134
const newRedirectTo = redirectJson[withoutLanguage]
@@ -180,15 +179,15 @@ export default async function archivedEnterpriseVersions(
180179
versionSatisfiesRange(requestedVersion, `>${lastVersionWithoutArchivedRedirectsFile}`) &&
181180
!deprecatedWithFunctionalRedirects.includes(requestedVersion)
182181
) {
183-
const redirectJson = await getRemoteJSON(getProxyPath('redirects.json', requestedVersion), {
182+
const redirectJson = (await getRemoteJSON(getProxyPath('redirects.json', requestedVersion), {
184183
retry: retryConfiguration,
185184
// This is allowed to be different compared to the other requests
186185
// we make because downloading the `redirects.json` once is very
187186
// useful because it caches so well.
188187
// And, as of 2021 that `redirects.json` is 10MB so it's more likely
189188
// to time out.
190189
timeout: { response: 1000 },
191-
})
190+
})) as Record<string, string>
192191

193192
// make redirects found via redirects.json redirect with a 301
194193
if (redirectJson[req.path]) {

src/assets/tests/static-assets.ts

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path'
33

44
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'
55
import nock from 'nock'
6-
import type { Response } from 'express'
6+
import type { Request, Response } from 'express'
77

88
import { get } from '@/tests/helpers/e2etest'
99
import { checkCachingHeaders } from '@/tests/helpers/caching-headers'
@@ -32,7 +32,7 @@ function mockRequest(requestPath: string, { headers }: { headers?: Record<string
3232
_headers[header.toLowerCase()] = value
3333
},
3434
headers,
35-
}
35+
} as unknown as Request & ExtendedRequest
3636
}
3737

3838
type MockResponse = {
@@ -93,7 +93,7 @@ const mockResponse = () => {
9393
res.statusCode = code
9494
return res
9595
}
96-
return res
96+
return res as unknown as Response & MockResponse
9797
}
9898

9999
describe('static assets', () => {
@@ -224,11 +224,7 @@ describe('archived enterprise static assets', () => {
224224
throw new Error('did not expect this to ever happen')
225225
}
226226
setDefaultFastlySurrogateKey(req, res, () => {})
227-
await archivedEnterpriseVersionsAssets(
228-
req as unknown as ExtendedRequest,
229-
res as unknown as Response,
230-
next,
231-
)
227+
await archivedEnterpriseVersionsAssets(req, res, next)
232228
expect(res.statusCode).toBe(200)
233229
checkCachingHeaders(res, false, 60)
234230
})
@@ -244,11 +240,7 @@ describe('archived enterprise static assets', () => {
244240
throw new Error('did not expect this to ever happen')
245241
}
246242
setDefaultFastlySurrogateKey(req, res, () => {})
247-
await archivedEnterpriseVersionsAssets(
248-
req as unknown as ExtendedRequest,
249-
res as unknown as Response,
250-
next,
251-
)
243+
await archivedEnterpriseVersionsAssets(req, res, next)
252244
expect(res.statusCode).toBe(200)
253245
checkCachingHeaders(res, false, 60)
254246
})
@@ -264,11 +256,7 @@ describe('archived enterprise static assets', () => {
264256
throw new Error('did not expect this to ever happen')
265257
}
266258
setDefaultFastlySurrogateKey(req, res, () => {})
267-
await archivedEnterpriseVersionsAssets(
268-
req as unknown as ExtendedRequest,
269-
res as unknown as Response,
270-
next,
271-
)
259+
await archivedEnterpriseVersionsAssets(req, res, next)
272260
expect(res.statusCode).toBe(200)
273261
checkCachingHeaders(res, false, 60)
274262
})
@@ -285,11 +273,7 @@ describe('archived enterprise static assets', () => {
285273
nexted = true
286274
}
287275
setDefaultFastlySurrogateKey(req, res, next)
288-
await archivedEnterpriseVersionsAssets(
289-
req as unknown as ExtendedRequest,
290-
res as unknown as Response,
291-
next,
292-
)
276+
await archivedEnterpriseVersionsAssets(req, res, next)
293277
// It didn't exit in that middleware but called next() to move on
294278
// with any other middlewares.
295279
expect(nexted).toBe(true)
@@ -307,11 +291,7 @@ describe('archived enterprise static assets', () => {
307291
nexted = true
308292
}
309293
setDefaultFastlySurrogateKey(req, res, () => {})
310-
await archivedEnterpriseVersionsAssets(
311-
req as unknown as ExtendedRequest,
312-
res as unknown as Response,
313-
next,
314-
)
294+
await archivedEnterpriseVersionsAssets(req, res, next)
315295
// It tried to go via the proxy, but it wasn't there, but then it
316296
// tried "our disk" and it's eventually there.
317297
expect(nexted).toBe(true)
@@ -357,11 +337,7 @@ describe('archived enterprise static assets', () => {
357337
nexted = true
358338
}
359339
setDefaultFastlySurrogateKey(req, res, () => {})
360-
await archivedEnterpriseVersionsAssets(
361-
req as unknown as ExtendedRequest,
362-
res as unknown as Response,
363-
next,
364-
)
340+
await archivedEnterpriseVersionsAssets(req, res, next)
365341
expect(res.statusCode).toBe(expectStatus)
366342
if (shouldCallNext) {
367343
expect(nexted).toBe(true)
@@ -400,11 +376,7 @@ describe('archived enterprise static assets', () => {
400376
nexted = true
401377
}
402378
setDefaultFastlySurrogateKey(req, res, () => {})
403-
await archivedEnterpriseVersionsAssets(
404-
req as unknown as ExtendedRequest,
405-
res as unknown as Response,
406-
next,
407-
)
379+
await archivedEnterpriseVersionsAssets(req, res, next)
408380
expect(nexted).toBe(shouldCallNext)
409381
expect(res.statusCode).toBe(expectStatus)
410382
})

src/audit-logs/lib/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ export function getAuditLogEvents(page: string, version: string): AuditLogEventT
158158
auditLogEventsCache.get(openApiVersion)?.set(page, [])
159159
auditLogEventsCache
160160
.get(openApiVersion)
161-
?.set(page, readCompressedJsonFileFallback(auditLogFileName))
161+
?.set(page, readCompressedJsonFileFallback(auditLogFileName) as AuditLogEventT[])
162162
} else if (!auditLogEventsCache.get(openApiVersion)?.has(page)) {
163163
auditLogEventsCache.get(openApiVersion)?.set(page, [])
164164
auditLogEventsCache
165165
.get(openApiVersion)
166-
?.set(page, readCompressedJsonFileFallback(auditLogFileName))
166+
?.set(page, readCompressedJsonFileFallback(auditLogFileName) as AuditLogEventT[])
167167
}
168168

169169
const auditLogEvents = auditLogEventsCache.get(openApiVersion)?.get(page)

src/content-render/unified/heading-links.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
import { visit } from 'unist-util-visit'
22
import { h } from 'hastscript'
3+
import type { Root, Element, ElementContent, Properties } from 'hast'
34

4-
interface HeadingNode {
5-
type: 'element'
6-
tagName: string
7-
properties: {
8-
id?: string
5+
interface HeadingNode extends Element {
6+
properties: Properties & {
7+
id: string
98
tabIndex?: number
10-
[key: string]: any
119
}
12-
children: any[]
1310
}
1411

15-
const matcher = (node: any): node is HeadingNode =>
12+
const matcher = (node: Element): node is HeadingNode =>
1613
node.type === 'element' &&
1714
['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].includes(node.tagName) &&
18-
node.properties?.id
15+
!!node.properties?.id
1916

2017
export default function headingLinks() {
21-
return (tree: any) => {
22-
visit(tree, matcher, (node: HeadingNode) => {
18+
return (tree: Root) => {
19+
visit(tree, 'element', (node: Element) => {
20+
if (!matcher(node)) return
2321
const { id } = node.properties
24-
const text = node.children
22+
const text = node.children as ElementContent[]
2523
node.properties.tabIndex = -1
2624
node.children = [
2725
h('a', { className: 'heading-link', href: `#${id}` }, [

src/content-render/unified/parse-info-string.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@
77
// Also parse equals signs, where id=some-id becomes { id: 'some-id' }
88

99
import { visit } from 'unist-util-visit'
10+
import type { Node } from 'unist'
1011

11-
interface CodeNode {
12+
interface CodeNode extends Node {
1213
type: 'code'
1314
lang?: string
1415
meta?: string | Record<string, string | boolean>
1516
value: string
1617
}
1718

18-
// Note: Using 'any' for node because unist-util-visit's type constraints
19-
// don't easily allow for proper code node typing without complex generics
20-
const matcher = (node: any): node is CodeNode => node.type === 'code' && node.lang
19+
const matcher = (node: Node): node is CodeNode => node.type === 'code' && !!(node as CodeNode).lang
2120

2221
export default function parseInfoString() {
23-
// Note: Using 'any' for tree because unified's AST types are complex and
24-
// this function works with different tree types depending on the processor
25-
return (tree: any) => {
26-
visit(tree, matcher, (node: CodeNode) => {
22+
return (tree: Node) => {
23+
visit(tree, 'code', (node: Node) => {
24+
if (!matcher(node)) return
2725
node.meta = strToObj(node.meta as string)
2826

2927
// Temporary, remove {:copy} to avoid highlight parse error in translations.

src/content-render/unified/rewrite-table-captions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { visit } from 'unist-util-visit'
22
import type { Node, Parent } from 'unist'
3-
import type { Element } from 'hast'
3+
import type { Element, Text } from 'hast'
44

55
/**
66
* A rehype plugin that automatically adds aria-labelledby attributes to tables
@@ -96,7 +96,7 @@ function findPrecedingHeading(parent: Parent, tableIndex: number): HeadingInfo |
9696

9797
function extractTextFromNode(node: Node): string {
9898
if (node.type === 'text') {
99-
return (node as any).value
99+
return (node as Text).value
100100
}
101101

102102
if (node.type === 'element' && (node as Element).children) {

0 commit comments

Comments
 (0)