Skip to content

Commit a91e776

Browse files
authored
Convert 12 JavaScript files to TypeScript (#57575)
1 parent f313d7b commit a91e776

File tree

16 files changed

+199
-94
lines changed

16 files changed

+199
-94
lines changed

src/content-linter/tests/unit/github-owned-action-references.js renamed to src/content-linter/tests/unit/github-owned-action-references.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ import { runRule } from '../../lib/init-test'
44
import { githubOwnedActionReferences } from '../../lib/linting-rules/github-owned-action-references'
55

66
describe(githubOwnedActionReferences.names.join(' - '), () => {
7-
test('Using hardcoded GitHub-owned actions causes error', async () => {
8-
const markdown = [
7+
test('Using hardcoded GitHub-owned actions causes error', async (): Promise<void> => {
8+
const markdown: string = [
99
'Hello actions/checkout@v2 apps.',
1010
'A actions/delete-package-versions@v2 for apps.',
1111
'Hello actions/download-artifact@v2.',
1212
'actions/cache@432433423423',
1313
'actions/cache@',
1414
'[link title](/actions/cache)',
1515
].join('\n')
16-
const result = await runRule(githubOwnedActionReferences, { strings: { markdown } })
16+
const result = await runRule(githubOwnedActionReferences, {
17+
strings: { markdown },
18+
files: undefined,
19+
ruleConfig: true,
20+
})
1721
const errors = result.markdown
1822
expect(errors.length).toBe(3)
1923
})

src/content-linter/tests/unit/table-liquid-versioning.js renamed to src/content-linter/tests/unit/table-liquid-versioning.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import { tableLiquidVersioning } from '../../lib/linting-rules/table-liquid-vers
66
const FIXTURE_FILEPATH = 'src/content-linter/tests/fixtures/tables.md'
77

88
describe(tableLiquidVersioning.names.join(' - '), () => {
9-
test('non-early access file with early access references fails', async () => {
10-
const result = await runRule(tableLiquidVersioning, { files: [FIXTURE_FILEPATH] })
9+
test('non-early access file with early access references fails', async (): Promise<void> => {
10+
const result = await runRule(tableLiquidVersioning, {
11+
strings: undefined,
12+
files: [FIXTURE_FILEPATH],
13+
ruleConfig: true,
14+
})
1115
const errors = result[FIXTURE_FILEPATH]
1216
expect(errors.length).toBe(11)
13-
const lineNumbers = errors.map((error) => error.lineNumber)
14-
const expectedErrorLines = [38, 40, 43, 44, 51, 53, 54, 55, 57, 58, 59]
17+
const lineNumbers: number[] = errors.map((error) => error.lineNumber)
18+
const expectedErrorLines: number[] = [38, 40, 43, 44, 51, 53, 54, 55, 57, 58, 59]
1519
expect(JSON.stringify(lineNumbers)).toEqual(JSON.stringify(expectedErrorLines))
1620
})
1721
})

src/content-render/unified/text-only.js renamed to src/content-render/unified/text-only.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { decode } from 'html-entities'
77
// Take advantage of the subtle fact that a lot of the times, the html value
88
// we get here is a single line that starts with `<p>` and ends with `</p>`
99
// and contains no longer HTML tags.
10-
export function fastTextOnly(html) {
10+
export function fastTextOnly(html: string): string {
1111
if (!html) return ''
1212
if (html.startsWith('<p>') && html.endsWith('</p>')) {
1313
const middle = html.slice(3, -4)
1414
if (!middle.includes('<')) return decode(middle.trim())
1515
}
16-
return cheerio.load(html, { xmlMode: true }).text().trim()
16+
const $ = cheerio.load(html, { xmlMode: true })
17+
return $.root().text().trim()
1718
}
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { schema } from '@/frame/lib/frontmatter'
22

3+
interface FeatureVersionsSchema {
4+
type: 'object'
5+
properties: {
6+
versions: any
7+
}
8+
additionalProperties: false
9+
}
10+
311
// Copy the properties from the frontmatter schema.
4-
const featureVersions = {
12+
const featureVersions: FeatureVersionsSchema = {
13+
type: 'object',
514
properties: {
6-
versions: Object.assign({}, schema.properties.versions),
15+
versions: Object.assign({}, (schema.properties as any).versions),
716
},
17+
additionalProperties: false,
818
}
919

1020
// Remove the feature versions properties.
1121
// We don't want to allow features within features! We just want pure versioning.
1222
delete featureVersions.properties.versions.properties.feature
1323

14-
// Call it invalid if any properties other than version properties are found.
15-
featureVersions.additionalProperties = false
16-
17-
// avoid ajv strict warning
18-
featureVersions.type = 'object'
19-
2024
export default featureVersions

src/data-directory/lib/data-schemas/glossaries-candidates.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export interface TermSchema {
2+
type: 'string'
3+
minLength: number
4+
pattern: string
5+
}
6+
7+
export const term: TermSchema = {
8+
type: 'string',
9+
minLength: 1,
10+
pattern: '^((?!\\*).)*$', // no asterisks allowed
11+
}
12+
13+
export interface GlossaryCandidateItem {
14+
term: string
15+
}
16+
17+
export interface GlossaryCandidatesSchema {
18+
type: 'array'
19+
items: {
20+
type: 'object'
21+
required: ['term']
22+
additionalProperties: false
23+
properties: {
24+
term: TermSchema
25+
}
26+
}
27+
minItems: number
28+
}
29+
30+
const schema: GlossaryCandidatesSchema = {
31+
type: 'array',
32+
items: {
33+
type: 'object',
34+
required: ['term'],
35+
additionalProperties: false,
36+
properties: {
37+
term,
38+
},
39+
},
40+
minItems: 21,
41+
}
42+
43+
export default schema

src/data-directory/lib/data-schemas/glossaries-external.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { term, type TermSchema } from './glossaries-candidates'
2+
3+
export interface GlossaryExternalItem {
4+
term: string
5+
description: string
6+
}
7+
8+
export interface DescriptionSchema {
9+
type: 'string'
10+
lintable: boolean
11+
}
12+
13+
export interface GlossariesExternalSchema {
14+
type: 'array'
15+
items: {
16+
type: 'object'
17+
required: ['term', 'description']
18+
additionalProperties: false
19+
properties: {
20+
term: TermSchema
21+
description: DescriptionSchema
22+
}
23+
}
24+
minItems: number
25+
}
26+
27+
const schema: GlossariesExternalSchema = {
28+
type: 'array',
29+
items: {
30+
type: 'object',
31+
required: ['term', 'description'],
32+
additionalProperties: false,
33+
properties: {
34+
term,
35+
description: {
36+
type: 'string',
37+
lintable: true,
38+
},
39+
},
40+
},
41+
minItems: 21,
42+
}
43+
44+
export default schema

src/data-directory/tests/filename-to-key.js renamed to src/data-directory/tests/filename-to-key.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { describe, expect, test } from 'vitest'
33
import filenameToKey from '@/data-directory/lib/filename-to-key'
44

55
describe('filename-to-key', () => {
6-
test('converts filenames to object keys', () => {
6+
test('converts filenames to object keys', (): void => {
77
expect(filenameToKey('foo/bar/baz.txt')).toBe('foo.bar.baz')
88
})
99

10-
test('ignores leading slash on filenames', () => {
10+
test('ignores leading slash on filenames', (): void => {
1111
expect(filenameToKey('/foo/bar/baz.txt')).toBe('foo.bar.baz')
1212
})
1313

14-
test('supports MS Windows paths', () => {
14+
test('supports MS Windows paths', (): void => {
1515
expect(filenameToKey('path\\to\\file.txt')).toBe('path.to.file')
1616
})
1717
})

src/frame/tests/api.js renamed to src/frame/tests/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { get } from '@/tests/helpers/e2etest'
55
describe('general /api pages', () => {
66
vi.setConfig({ testTimeout: 60 * 1000 })
77

8-
test("any /api URL that isn't found should JSON", async () => {
8+
test("any /api URL that isn't found should JSON", async (): Promise<void> => {
99
const res = await get('/api')
1010
expect(res.statusCode).toBe(404)
1111
expect(res.headers['content-type']).toMatch(/application\/json/)
1212
})
1313

14-
test("any /api/* URL that isn't found should be JSON", async () => {
14+
test("any /api/* URL that isn't found should be JSON", async (): Promise<void> => {
1515
const res = await get('/api/yadayada')
1616
expect(res.statusCode).toBe(404)
1717
expect(JSON.parse(res.body).error).toBe('/yadayada not found')

0 commit comments

Comments
 (0)