Skip to content

Commit 13178f0

Browse files
authored
Remove 'any' types from 14 files (#58716)
1 parent 21eb817 commit 13178f0

File tree

16 files changed

+207
-133
lines changed

16 files changed

+207
-133
lines changed

src/codeql-cli/scripts/sync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function main() {
2929
includeBasePath: true,
3030
globs: ['**/*.md'],
3131
})
32-
const cliMarkdownContents: Record<string, { data: any; content: string }> = {}
32+
const cliMarkdownContents: Record<string, { data: Record<string, unknown>; content: string }> = {}
3333

3434
for (const file of markdownFiles) {
3535
const sourceContent = await readFile(file, 'utf8')

src/content-linter/lib/linting-rules/ctas-schema.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,16 @@ export const ctasSchema: Rule = {
105105
for (const error of errors) {
106106
let message = ''
107107
if (error.keyword === 'required') {
108-
message = `Missing required parameter: ${(error.params as any)?.missingProperty}`
108+
message = `Missing required parameter: ${(error.params as { missingProperty?: string })?.missingProperty}`
109109
} else if (error.keyword === 'enum') {
110110
const paramName = error.instancePath.substring(1)
111111
// Get the actual invalid value from refParams and allowed values from params
112112
const invalidValue = refParams[paramName]
113-
const allowedValues = (error.params as any)?.allowedValues || []
113+
const allowedValues =
114+
(error.params as { allowedValues?: unknown[] })?.allowedValues || []
114115
message = `Invalid value for ${paramName}: "${invalidValue}". Valid values are: ${allowedValues.join(', ')}`
115116
} else if (error.keyword === 'additionalProperties') {
116-
message = `Unexpected parameter: ${(error.params as any)?.additionalProperty}`
117+
message = `Unexpected parameter: ${(error.params as { additionalProperty?: string })?.additionalProperty}`
117118
} else {
118119
message = `CTA URL validation error: ${error.message}`
119120
}

src/content-linter/lib/linting-rules/link-punctuation.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,39 @@ import type { RuleParams, RuleErrorCallback, Rule } from '../../types'
33

44
import { doesStringEndWithPeriod, getRange, isStringQuoted } from '../helpers/utils'
55

6+
// Minimal type for markdownit tokens used in this rule
7+
interface MarkdownToken {
8+
children?: MarkdownToken[]
9+
line?: string
10+
type?: string
11+
content?: string
12+
lineNumber?: number
13+
}
14+
615
export const linkPunctuation: Rule = {
716
names: ['GHD001', 'link-punctuation'],
817
description: 'Internal link titles must not contain punctuation',
918
tags: ['links', 'url'],
1019
parser: 'markdownit',
1120
function: (params: RuleParams, onError: RuleErrorCallback) => {
12-
// Using 'any' type for token as markdownlint-rule-helpers doesn't provide TypeScript types
13-
filterTokens(params, 'inline', (token: any) => {
21+
filterTokens(params, 'inline', (token: MarkdownToken) => {
1422
const { children, line } = token
1523
let inLink = false
16-
for (const child of children) {
24+
for (const child of children || []) {
1725
if (child.type === 'link_open') {
1826
inLink = true
1927
} else if (child.type === 'link_close') {
2028
inLink = false
21-
} else if (inLink && child.type === 'text') {
29+
} else if (inLink && child.type === 'text' && child.content) {
2230
const content = child.content.trim()
2331
const hasPeriod = doesStringEndWithPeriod(content)
2432
const hasQuotes = isStringQuoted(content)
2533

2634
if (hasPeriod || hasQuotes) {
27-
const range = getRange(line, content)
35+
const range = line ? getRange(line, content) : []
2836
addError(
2937
onError,
30-
child.lineNumber,
38+
child.lineNumber || 1,
3139
'Remove quotes and/or period punctuation from the link title.',
3240
child.content,
3341
range,

src/content-render/liquid/data.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import { getDataByLanguage } from '@/data-directory/lib/get-data'
77
const Syntax = /([a-z0-9/\\_.\-[\]]+)/i
88
const SyntaxHelp = "Syntax Error in 'data' - Valid syntax: data [path]"
99

10-
// Using any for scope because it has custom environments property not in Liquid's Scope type
10+
// Using unknown for scope because it has custom environments property not in Liquid's Scope type
1111
interface CustomScope {
12-
environments: any
13-
[key: string]: any
12+
environments: {
13+
currentLanguage?: string
14+
[key: string]: unknown
15+
}
16+
[key: string]: unknown
1417
}
1518

1619
interface DataTag {
@@ -32,7 +35,7 @@ export default {
3235
},
3336

3437
async render(scope: CustomScope) {
35-
let text = getDataByLanguage(this.path, scope.environments.currentLanguage)
38+
let text = getDataByLanguage(this.path, scope.environments.currentLanguage || '')
3639
if (text === undefined) {
3740
if (scope.environments.currentLanguage === 'en') {
3841
const message = `Can't find the key 'data ${this.path}' in the scope.`

src/fixtures/tests/internal-links.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('autotitle', () => {
99
test('internal links with AUTOTITLE resolves', async () => {
1010
const $: cheerio.Root = await getDOM('/get-started/foo/autotitling')
1111
const links = $('#article-contents a[href]')
12-
links.each((i: number, element: any) => {
12+
links.each((i: number, element: cheerio.Element) => {
1313
if ($(element).attr('href')?.includes('/get-started/start-your-journey/hello-world')) {
1414
expect($(element).text()).toBe('Hello World')
1515
}
@@ -49,13 +49,14 @@ describe('cross-version-links', () => {
4949

5050
// Tests that the hardcoded prefix is always removed
5151
const firstLink = links.filter(
52-
(i: number, element: any) => $(element).text() === 'Hello world always in free-pro-team',
52+
(i: number, element: cheerio.Element) =>
53+
$(element).text() === 'Hello world always in free-pro-team',
5354
)
5455
expect(firstLink.attr('href')).toBe('/en/get-started/start-your-journey/hello-world')
5556

5657
// Tests that the second link always goes to enterprise-server@X.Y
5758
const secondLink = links.filter(
58-
(i: number, element: any) =>
59+
(i: number, element: cheerio.Element) =>
5960
$(element).text() === 'Autotitling page always in enterprise-server latest',
6061
)
6162
expect(secondLink.attr('href')).toBe(
@@ -72,29 +73,33 @@ describe('link-rewriting', () => {
7273

7374
{
7475
const link = links.filter(
75-
(i: number, element: any) => $(element).text() === 'Cross Version Linking',
76+
(i: number, element: cheerio.Element) => $(element).text() === 'Cross Version Linking',
7677
)
7778
expect(link.attr('href')).toMatch('/en/get-started/')
7879
}
7980

8081
// Some links are left untouched
8182

8283
{
83-
const link = links.filter((i: number, element: any) =>
84+
const link = links.filter((i: number, element: cheerio.Element) =>
8485
$(element).text().includes('Enterprise 11.10'),
8586
)
8687
expect(link.attr('href')).toMatch('/en/enterprise/')
8788
}
8889
{
89-
const link = links.filter((i: number, element: any) => $(element).text().includes('peterbe'))
90+
const link = links.filter((i: number, element: cheerio.Element) =>
91+
$(element).text().includes('peterbe'),
92+
)
9093
expect(link.attr('href')).toMatch(/^https:/)
9194
}
9295
{
93-
const link = links.filter((i: number, element: any) => $(element).text().includes('Picture'))
96+
const link = links.filter((i: number, element: cheerio.Element) =>
97+
$(element).text().includes('Picture'),
98+
)
9499
expect(link.attr('href')).toMatch(/^\/assets\//)
95100
}
96101
{
97-
const link = links.filter((i: number, element: any) =>
102+
const link = links.filter((i: number, element: cheerio.Element) =>
98103
$(element).text().includes('GraphQL Schema'),
99104
)
100105
expect(link.attr('href')).toMatch(/^\/public\//)
@@ -108,7 +113,7 @@ describe('link-rewriting', () => {
108113
const links = $('#article-contents a[href]')
109114

110115
const link = links.filter(
111-
(i: number, element: any) => $(element).text() === 'Cross Version Linking',
116+
(i: number, element: cheerio.Element) => $(element).text() === 'Cross Version Linking',
112117
)
113118
expect(link.attr('href')).toMatch('/en/enterprise-cloud@latest/get-started/')
114119
})
@@ -121,7 +126,7 @@ describe('link-rewriting', () => {
121126
const links = $('#article-contents a[href]')
122127

123128
const link = links.filter(
124-
(i: number, element: any) => $(element).text() === 'Cross Version Linking',
129+
(i: number, element: cheerio.Element) => $(element).text() === 'Cross Version Linking',
125130
)
126131
expect(link.attr('href')).toMatch(
127132
`/en/enterprise-server@${enterpriseServerReleases.latestStable}/get-started/`,
@@ -133,14 +138,14 @@ describe('subcategory links', () => {
133138
test('no free-pro-team prefix', async () => {
134139
const $: cheerio.Root = await getDOM('/rest/actions')
135140
const links = $('[data-testid="table-of-contents"] a[href]')
136-
links.each((i: number, element: any) => {
141+
links.each((i: number, element: cheerio.Element) => {
137142
expect($(element).attr('href')).not.toContain('/free-pro-team@latest')
138143
})
139144
})
140145
test('enterprise-server prefix', async () => {
141146
const $: cheerio.Root = await getDOM('/enterprise-server@latest/rest/actions')
142147
const links = $('[data-testid="table-of-contents"] a[href]')
143-
links.each((i: number, element: any) => {
148+
links.each((i: number, element: cheerio.Element) => {
144149
expect($(element).attr('href')).toMatch(/\/enterprise-server@\d/)
145150
})
146151
})

src/graphql/tests/build-changelog.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ interface Preview {
1919
title: string
2020
description: string
2121
toggled_by: string
22-
announcement: any
23-
updates: any
22+
announcement: unknown
23+
updates: unknown
2424
toggled_on: string[]
2525
owning_teams: string[]
2626
}
@@ -33,7 +33,7 @@ interface UpcomingChange {
3333

3434
interface IgnoredChange {
3535
type: string
36-
[key: string]: any
36+
[key: string]: unknown
3737
}
3838

3939
interface IgnoredChangesSummary {
@@ -285,7 +285,7 @@ describe('ignored changes tracking', () => {
285285
// This should generate a TypeDescriptionAdded change type that gets ignored
286286
await createChangelogEntry(oldSchemaString, newSchemaString, [], [], [])
287287

288-
const ignoredChanges: IgnoredChange[] = getLastIgnoredChanges()
288+
const ignoredChanges: IgnoredChange[] = getLastIgnoredChanges() as unknown as IgnoredChange[]
289289
expect(ignoredChanges.length).toBe(1)
290290
expect(ignoredChanges[0].type).toBe('TYPE_DESCRIPTION_ADDED')
291291
})

src/landings/components/ProductGuidesContext.tsx

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createContext, useContext } from 'react'
22
import pick from 'lodash/pick'
3+
import type { ExtendedRequest } from '@/types'
34

45
export type LearningTrack = {
56
trackName: string
@@ -38,24 +39,45 @@ export const useProductGuidesContext = (): ProductGuidesContextT => {
3839
return context
3940
}
4041

41-
export const getProductGuidesContextFromRequest = (req: any): ProductGuidesContextT => {
42-
const page = req.context.page
42+
export const getProductGuidesContextFromRequest = (req: ExtendedRequest): ProductGuidesContextT => {
43+
if (!req.context || !req.context.page) {
44+
throw new Error('Request context or page is missing')
45+
}
46+
47+
const page = req.context.page as typeof req.context.page & {
48+
learningTracks?: Array<Record<string, unknown>>
49+
includeGuides?: Array<Record<string, unknown>>
50+
}
4351

44-
const learningTracks: LearningTrack[] = (page.learningTracks || []).map((track: any) => ({
45-
...pick(track, ['title', 'description', 'trackName', 'trackProduct']),
46-
guides: (track.guides || []).map((guide: any) => {
47-
return pick(guide, ['title', 'intro', 'href', 'page.type'])
52+
const learningTracks: LearningTrack[] = (page.learningTracks || []).map(
53+
(track: Record<string, unknown>) => ({
54+
title: (track.title as string) || '',
55+
description: (track.description as string) || '',
56+
trackName: (track.trackName as string) || '',
57+
trackProduct: (track.trackProduct as string) || '',
58+
guides: ((track.guides as Array<Record<string, unknown>>) || []).map(
59+
(guide: Record<string, unknown>) => ({
60+
title: (guide.title as string) || '',
61+
intro: (guide.intro as string) || '',
62+
href: (guide.href as string) || '',
63+
page: guide.page as { type: string } | undefined,
64+
}),
65+
),
4866
}),
49-
}))
67+
)
5068

5169
return {
5270
...pick(page, ['title', 'intro']),
71+
title: page.title || '',
72+
intro: page.intro || '',
5373
learningTracks,
54-
includeGuides: (page.includeGuides || []).map((guide: any) => {
74+
includeGuides: (page.includeGuides || []).map((guide: Record<string, unknown>) => {
5575
return {
56-
...pick(guide, ['href', 'title', 'intro']),
57-
type: guide.type || '',
58-
topics: guide.topics || [],
76+
href: (guide.href as string) || '',
77+
title: (guide.title as string) || '',
78+
intro: (guide.intro as string) || '',
79+
type: (guide.type as string) || '',
80+
topics: (guide.topics as Array<string>) || [],
5981
}
6082
}),
6183
}

src/languages/scripts/count-translation-corruptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ function run(languageCode: string, site: Site, englishReusables: Reusables) {
7777
const illegalTags = new Map<string, number>()
7878

7979
function countError(error: TokenizationError, where: string) {
80-
const originalError = (error as any).originalError
80+
const originalError = (error as { originalError?: Error }).originalError
8181
const errorString = originalError ? originalError.message : error.message
8282
if (errorString.includes('illegal tag syntax')) {
83-
const illegalTag = (error as any).token.content
83+
const illegalTag = (error as unknown as { token: { content: string } }).token.content
8484
illegalTags.set(illegalTag, (illegalTags.get(illegalTag) || 0) + 1)
8585
}
8686
errors.set(errorString, (errors.get(errorString) || 0) + 1)

src/learning-track/lib/types.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22
* Common types used across learning track components
33
*/
44

5-
/**
6-
* Basic context interface for rendering operations
7-
*/
8-
export interface Context {
9-
currentProduct?: string
10-
currentLanguage?: string
11-
currentVersion?: string
12-
pages?: any
13-
redirects?: any
14-
// Additional properties that may be needed for rendering
15-
[key: string]: any
16-
}
5+
import type { Context, Page as MainPage } from '@/types'
6+
7+
// Re-export Context from main types to avoid duplicate definitions
8+
export type { Context }
179

1810
/**
1911
* Options for retrieving link data
@@ -49,11 +41,9 @@ export interface PageFeaturedLinks {
4941

5042
/**
5143
* Page interface for basic page properties
44+
* Using the main Page type from @/types
5245
*/
53-
export interface Page {
54-
renderTitle: (context: Context, opts: any) => Promise<string>
55-
renderProp: (prop: string, context: Context, opts: any) => Promise<string>
56-
}
46+
export type Page = MainPage
5747

5848
/**
5949
* Guide in a learning track
@@ -83,7 +73,7 @@ export interface LearningTrackMetadata {
8373
title: string
8474
description: string
8575
guides: string[]
86-
versions?: any
76+
versions?: unknown
8777
}
8878

8979
/**

src/observability/tests/failbot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import nock from 'nock'
44
import FailBot from '../lib/failbot'
55

66
describe('FailBot', () => {
7-
const requestBodiesSent: any[] = []
7+
const requestBodiesSent: unknown[] = []
88

99
beforeEach(() => {
1010
delete process.env.HAYSTACK_URL

0 commit comments

Comments
 (0)