Skip to content

Commit 5e9dcbc

Browse files
heiskrCopilot
andauthored
⚙️ Remove explicit any types from 16 TypeScript files (#60746)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent dd57bc1 commit 5e9dcbc

19 files changed

Lines changed: 330 additions & 286 deletions

eslint.config.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,32 +204,17 @@ export default [
204204
'src/article-api/transformers/audit-logs-transformer.ts',
205205
'src/article-api/transformers/rest-transformer.ts',
206206
'src/codeql-cli/scripts/convert-markdown-for-docs.ts',
207-
'src/content-linter/lib/init-test.ts',
208-
'src/content-linter/lib/linting-rules/code-annotations.ts',
209-
'src/content-linter/lib/linting-rules/index.ts',
210-
'src/content-linter/lib/linting-rules/journey-tracks-liquid.ts',
211207
'src/content-linter/lib/linting-rules/liquid-ifversion-versions.ts',
212-
'src/content-linter/lib/linting-rules/liquid-versioning.ts',
213-
'src/content-linter/lib/linting-rules/third-party-action-pinning.ts',
214208
'src/content-linter/scripts/lint-content.ts',
215-
'src/content-linter/scripts/pretty-print-results.ts',
216-
'src/content-linter/style/base.ts',
217-
'src/content-linter/tests/integration/lint-cli.ts',
218-
'src/content-linter/tests/lint-files.ts',
219-
'src/content-linter/tests/lint-frontmatter-links.ts',
220-
'src/content-linter/tests/unit/table-column-integrity-simple.ts',
209+
221210
'src/content-render/liquid/engine.ts',
222211
'src/content-render/liquid/index.ts',
223212
'src/content-render/scripts/liquid-tags.ts',
224213
'src/content-render/scripts/move-content.ts',
225-
'src/content-render/tests/link-error-line-numbers.ts',
226214
'src/content-render/unified/annotate.ts',
227215
'src/content-render/unified/index.ts',
228216
'src/data-directory/lib/get-data.ts',
229-
'src/early-access/scripts/migrate-early-access-product.ts',
230-
'src/fixtures/tests/categories-and-subcategory.ts',
231217
'src/fixtures/tests/guides.ts',
232-
'src/fixtures/tests/translations.ts',
233218
'src/frame/components/context/MainContext.tsx',
234219
'src/frame/lib/create-tree.ts',
235220
'src/frame/lib/frontmatter.ts',
@@ -290,7 +275,6 @@ export default [
290275
'src/types/markdownlint-rule-helpers.d.ts',
291276
'src/types/markdownlint-rule-search-replace.d.ts',
292277
'src/types/primer__octicons.d.ts',
293-
'src/workflows/projects.ts',
294278
],
295279
rules: {
296280
'@typescript-eslint/no-explicit-any': 'off',

src/content-linter/lib/init-test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export async function runRule(
2323
}
2424

2525
const testOptions: Partial<Options> = {
26-
customRules: [module as any],
26+
customRules: [
27+
module as unknown as NonNullable<Extract<Options['customRules'], unknown[]>>[number],
28+
],
2729
config: { ...defaultConfig, ...testConfig },
2830
}
2931
if (strings) testOptions.strings = strings

src/content-linter/lib/linting-rules/code-annotations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { RuleParams, RuleErrorCallback, MarkdownToken } from '@/content-lin
55

66
interface Frontmatter {
77
layout?: string
8-
[key: string]: any
8+
[key: string]: unknown
99
}
1010

1111
export const codeAnnotations = {

src/content-linter/lib/linting-rules/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ import { raiAppCardStructure } from '@/content-linter/lib/linting-rules/rai-app-
5858
import { frontmatterContentType } from '@/content-linter/lib/linting-rules/frontmatter-content-type'
5959
import { frontmatterDocsTeamMetrics } from '@/content-linter/lib/linting-rules/frontmatter-docs-team-metrics'
6060

61-
// Using any type because @github/markdownlint-github doesn't provide TypeScript declarations
62-
// The elements in the array have a 'names' property that contains rule identifiers
63-
const noDefaultAltText = markdownlintGitHub.find((elem: any) =>
61+
const noDefaultAltText = markdownlintGitHub.find((elem: { names: string[] }) =>
6462
elem.names.includes('no-default-alt-text'),
6563
)
66-
// Using any type because @github/markdownlint-github doesn't provide TypeScript declarations
67-
const noGenericLinkText = markdownlintGitHub.find((elem: any) =>
64+
const noGenericLinkText = markdownlintGitHub.find((elem: { names: string[] }) =>
6865
elem.names.includes('no-generic-link-text'),
6966
)
7067

src/content-linter/lib/linting-rules/journey-tracks-liquid.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export const journeyTracksLiquid = {
99
description: 'Journey track properties must use valid Liquid syntax',
1010
tags: ['frontmatter', 'journey-tracks', 'liquid'],
1111
function: (params: RuleParams, onError: RuleErrorCallback) => {
12-
// Using any for frontmatter as it's a dynamic YAML object with varying properties
13-
const fm: any = getFrontmatter(params.lines)
12+
const fm: Record<string, unknown> = getFrontmatter(params.lines) as Record<string, unknown>
1413
if (!fm || !fm.journeyTracks || !Array.isArray(fm.journeyTracks)) return
1514
if (!fm.layout || fm.layout !== 'journey-landing') return
1615

@@ -23,7 +22,7 @@ export const journeyTracksLiquid = {
2322
: 1
2423

2524
for (let trackIndex = 0; trackIndex < fm.journeyTracks.length; trackIndex++) {
26-
const track: any = fm.journeyTracks[trackIndex]
25+
const track = (fm.journeyTracks as Array<Record<string, unknown>>)[trackIndex]
2726
// Try to find the line number for this specific journey track so we can use that for the error
2827
// line number. Getting the exact line number is probably more work than it's worth for this
2928
// particular rule.
@@ -62,11 +61,11 @@ export const journeyTracksLiquid = {
6261
if (prop.value && typeof prop.value === 'string') {
6362
try {
6463
liquid.parse(prop.value)
65-
} catch (error: any) {
64+
} catch (error: unknown) {
6665
addError(
6766
onError,
6867
trackLineNumber,
69-
`Invalid Liquid syntax in journey track ${prop.name} (track ${trackIndex + 1}): ${error.message}`,
68+
`Invalid Liquid syntax in journey track ${prop.name} (track ${trackIndex + 1}): ${error instanceof Error ? error.message : String(error)}`,
7069
prop.value,
7170
)
7271
}
@@ -84,11 +83,11 @@ export const journeyTracksLiquid = {
8483
if ('href' in guideObj && typeof guideObj.href === 'string') {
8584
try {
8685
liquid.parse(guideObj.href)
87-
} catch (error: any) {
86+
} catch (error: unknown) {
8887
addError(
8988
onError,
9089
trackLineNumber,
91-
`Invalid Liquid syntax in journey track guide href (track ${trackIndex + 1}, guide ${guideIndex + 1}): ${error.message}`,
90+
`Invalid Liquid syntax in journey track guide href (track ${trackIndex + 1}, guide ${guideIndex + 1}): ${error instanceof Error ? error.message : String(error)}`,
9291
guideObj.href,
9392
)
9493
}
@@ -101,11 +100,11 @@ export const journeyTracksLiquid = {
101100
) {
102101
try {
103102
liquid.parse(guideObj.alternativeNextStep)
104-
} catch (error: any) {
103+
} catch (error: unknown) {
105104
addError(
106105
onError,
107106
trackLineNumber,
108-
`Invalid Liquid syntax in journey track guide alternativeNextStep (track ${trackIndex + 1}, guide ${guideIndex + 1}): ${error.message}`,
107+
`Invalid Liquid syntax in journey track guide alternativeNextStep (track ${trackIndex + 1}, guide ${guideIndex + 1}): ${error instanceof Error ? error.message : String(error)}`,
109108
guideObj.alternativeNextStep,
110109
)
111110
}

src/content-linter/lib/linting-rules/liquid-versioning.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,8 @@ function validateIfversionConditionals(cond: string, possibleVersionNames: Set<s
169169
`Found "${version}" inside "${cond}" with a "${operator}" operator, but "${version}" does not support semantic comparisons"`,
170170
)
171171
}
172-
// Using 'as any' because the operator is a runtime string value that we validate,
173172
// but the allowedVersionOperators array has a more specific type that TypeScript can't infer
174-
if (!allowedVersionOperators.includes(operator as any)) {
173+
if (!(allowedVersionOperators as readonly string[]).includes(operator)) {
175174
errors.push(
176175
`Found a "${operator}" operator inside "${cond}", but "${operator}" is not supported`,
177176
)
@@ -259,11 +258,9 @@ function getVersionsObject(part: string, allFeatures: AllFeatures): Record<strin
259258
const versions: Record<string, string> = {}
260259
if (part in allFeatures) {
261260
for (const [shortName, version] of Object.entries(allFeatures[part].versions)) {
262-
// Using 'as any' for recursive getVersionsObject call because it can return either
263-
// a string or a nested Record<string, string>, but we flatten it to string for this context
264261
const versionOperator: string =
265262
version in allFeatures
266-
? (getVersionsObject(version, allFeatures) as any)
263+
? Object.values(getVersionsObject(version, allFeatures))[0] || '*'
267264
: (version as string)
268265
if (shortName in versions) {
269266
versions[shortName] = lowestVersion(versionOperator, versions[shortName])

src/content-linter/lib/linting-rules/third-party-action-pinning.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ const firstPartyPrefixes = ['actions/', './.github/actions/', 'github/', 'octo-o
1414

1515
interface WorkflowStep {
1616
uses?: string
17-
[key: string]: any
17+
[key: string]: unknown
1818
}
1919

2020
interface WorkflowJob {
2121
steps?: WorkflowStep[]
22-
[key: string]: any
22+
[key: string]: unknown
2323
}
2424

2525
interface WorkflowYaml {
2626
jobs?: Record<string, WorkflowJob>
2727
steps?: WorkflowStep[]
28-
[key: string]: any
28+
[key: string]: unknown
2929
}
3030

3131
export const thirdPartyActionPinning: Rule = {

src/content-linter/scripts/pretty-print-results.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ function chalkFunColors(text: string): string {
152152
.map((char) => {
153153
const color = shuffledColors[colorIndex]
154154
colorIndex = (colorIndex + 1) % shuffledColors.length
155-
// Chalk's TypeScript types don't support dynamic property access, but these are valid color methods
156-
return (chalk as any)[color](char)
155+
const colorFn = chalk[color] as (text: string) => string
156+
return colorFn(char)
157157
})
158158
.join('')
159159
}

src/content-linter/style/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type RuleConfig = {
99
severity: 'error' | 'warning'
1010
'partial-markdown-files': boolean
1111
'yml-files': boolean
12-
[key: string]: any
12+
[key: string]: unknown
1313
}
1414

1515
type BaseConfig = {

src/content-linter/tests/integration/lint-cli.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ describe('Content Linter CLI Integration Tests', { timeout: 30000 }, () => {
5252
stdio: 'pipe',
5353
timeout: 10000, // 10 second timeout
5454
})
55-
} catch (error: any) {
56-
output = error.stdout + error.stderr
57-
exitCode = error.status || 1
55+
} catch (error: unknown) {
56+
const execError = error as { stdout?: string; stderr?: string; status?: number }
57+
output = (execError.stdout || '') + (execError.stderr || '')
58+
exitCode = execError.status || 1
5859
}
5960

6061
return { output, exitCode }

0 commit comments

Comments
 (0)