Convert 14 JavaScript files to TypeScript (#57464)
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
export const defaultConfig = {
|
||||
default: false,
|
||||
}
|
||||
5
src/content-linter/lib/default-markdownlint-options.ts
Normal file
5
src/content-linter/lib/default-markdownlint-options.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { Configuration } from 'markdownlint'
|
||||
|
||||
export const defaultConfig: Configuration = {
|
||||
default: false,
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// get-rules.d.ts
|
||||
// This is a declaration file for get-rules.js
|
||||
|
||||
import type { Rule, RuleConfig } from '../../types'
|
||||
|
||||
export const customRules: Rule[]
|
||||
export const allRules: Rule[]
|
||||
export const allConfig: RuleConfig
|
||||
@@ -1,8 +0,0 @@
|
||||
import rules from '../../../../node_modules/markdownlint/lib/rules'
|
||||
import { gitHubDocsMarkdownlint } from '../linting-rules/index'
|
||||
import { baseConfig } from '../../style/base'
|
||||
import { customConfig } from '../../style/github-docs'
|
||||
|
||||
export const customRules = gitHubDocsMarkdownlint.rules
|
||||
export const allRules = [...rules, ...gitHubDocsMarkdownlint.rules]
|
||||
export const allConfig = { ...baseConfig, ...customConfig }
|
||||
12
src/content-linter/lib/helpers/get-rules.ts
Normal file
12
src/content-linter/lib/helpers/get-rules.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { gitHubDocsMarkdownlint } from '@/content-linter/lib/linting-rules/index'
|
||||
import { baseConfig } from '@/content-linter/style/base'
|
||||
import { customConfig } from '@/content-linter/style/github-docs'
|
||||
import type { Rule } from '@/content-linter/types'
|
||||
|
||||
// Import markdownlint rules - external library without TypeScript declarations
|
||||
// @ts-ignore - markdownlint doesn't provide TypeScript declarations
|
||||
import markdownlintRules from '../../../../node_modules/markdownlint/lib/rules'
|
||||
|
||||
export const customRules: Rule[] = gitHubDocsMarkdownlint.rules
|
||||
export const allRules: any[] = [...markdownlintRules, ...gitHubDocsMarkdownlint.rules]
|
||||
export const allConfig: Record<string, any> = { ...baseConfig, ...customConfig }
|
||||
@@ -1,9 +0,0 @@
|
||||
export const MARKDOWN_OPTIONS = {
|
||||
bullet: '*',
|
||||
emphasis: '_',
|
||||
closeAtx: false,
|
||||
fence: '`',
|
||||
fences: true,
|
||||
incrementListMarker: false,
|
||||
strong: '*',
|
||||
}
|
||||
19
src/content-linter/lib/helpers/unified-formatter-options.ts
Normal file
19
src/content-linter/lib/helpers/unified-formatter-options.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
interface MarkdownFormatterOptions {
|
||||
bullet: string
|
||||
emphasis: string
|
||||
closeAtx: boolean
|
||||
fence: string
|
||||
fences: boolean
|
||||
incrementListMarker: boolean
|
||||
strong: string
|
||||
}
|
||||
|
||||
export const MARKDOWN_OPTIONS: MarkdownFormatterOptions = {
|
||||
bullet: '*',
|
||||
emphasis: '_',
|
||||
closeAtx: false,
|
||||
fence: '`',
|
||||
fences: true,
|
||||
incrementListMarker: false,
|
||||
strong: '*',
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
// If 'THROW_ON_EMPTY' is set and it's value is '0' or 'false' it becomes
|
||||
// false. Or true if it's 'true' or '1'.
|
||||
export const THROW_ON_EMPTY = Boolean(
|
||||
export const THROW_ON_EMPTY: boolean = Boolean(
|
||||
process.env.THROW_ON_EMPTY
|
||||
? JSON.parse(process.env.THROW_ON_EMPTY)
|
||||
: JSON.parse(process.env.CI || process.env.NODE_ENV !== 'production'),
|
||||
: JSON.parse(String(process.env.CI || process.env.NODE_ENV !== 'production')),
|
||||
)
|
||||
|
||||
export class DataReferenceError extends Error {}
|
||||
@@ -1 +0,0 @@
|
||||
export default ['=', '<', '>', '!=']
|
||||
@@ -0,0 +1,5 @@
|
||||
const ifversionSupportedOperators = ['=', '<', '>', '!='] as const
|
||||
|
||||
export type IfversionSupportedOperator = (typeof ifversionSupportedOperators)[number]
|
||||
|
||||
export default ifversionSupportedOperators
|
||||
@@ -1,7 +1,7 @@
|
||||
import { processLiquidPost } from './post'
|
||||
import { engine } from './engine'
|
||||
|
||||
export async function renderLiquid(template, context) {
|
||||
export async function renderLiquid(template: string, context: any): Promise<string> {
|
||||
template = await engine.parseAndRender(template, context)
|
||||
template = processLiquidPost(template)
|
||||
return template
|
||||
@@ -1,16 +0,0 @@
|
||||
export default {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'object',
|
||||
required: ['name', 'comment'],
|
||||
properties: {
|
||||
name: {
|
||||
type: 'string',
|
||||
},
|
||||
comment: {
|
||||
type: 'string',
|
||||
enum: ['number', 'slash', 'percent', 'hyphen', 'xml', 'none'],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
37
src/data-directory/lib/data-schemas/code-languages.ts
Normal file
37
src/data-directory/lib/data-schemas/code-languages.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
interface CodeLanguageProperties {
|
||||
name: {
|
||||
type: 'string'
|
||||
}
|
||||
comment: {
|
||||
type: 'string'
|
||||
enum: ['number', 'slash', 'percent', 'hyphen', 'xml', 'none']
|
||||
}
|
||||
}
|
||||
|
||||
interface CodeLanguageSchema {
|
||||
type: 'object'
|
||||
additionalProperties: {
|
||||
type: 'object'
|
||||
required: ['name', 'comment']
|
||||
properties: CodeLanguageProperties
|
||||
}
|
||||
}
|
||||
|
||||
const codeLanguagesSchema: CodeLanguageSchema = {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'object',
|
||||
required: ['name', 'comment'],
|
||||
properties: {
|
||||
name: {
|
||||
type: 'string',
|
||||
},
|
||||
comment: {
|
||||
type: 'string',
|
||||
enum: ['number', 'slash', 'percent', 'hyphen', 'xml', 'none'],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default codeLanguagesSchema
|
||||
@@ -4,10 +4,10 @@ interface DataSchemas {
|
||||
|
||||
const dataSchemas: DataSchemas = {
|
||||
'data/features': '@/data-directory/lib/data-schemas/features.js',
|
||||
'data/variables': '@/data-directory/lib/data-schemas/variables.js',
|
||||
'data/variables': '@/data-directory/lib/data-schemas/variables',
|
||||
'data/learning-tracks': '@/data-directory/lib/data-schemas/learning-tracks.js',
|
||||
'data/release-notes': '@/data-directory/lib/data-schemas/release-notes.js',
|
||||
'data/code-languages.yml': '@/data-directory/lib/data-schemas/code-languages.js',
|
||||
'data/code-languages.yml': '@/data-directory/lib/data-schemas/code-languages',
|
||||
'data/glossaries/candidates.yml': '@/data-directory/lib/data-schemas/glossaries-candidates.js',
|
||||
'data/glossaries/external.yml': '@/data-directory/lib/data-schemas/glossaries-external.js',
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
export default {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'string',
|
||||
lintable: true,
|
||||
},
|
||||
}
|
||||
17
src/data-directory/lib/data-schemas/variables.ts
Normal file
17
src/data-directory/lib/data-schemas/variables.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
interface VariableSchema {
|
||||
type: 'object'
|
||||
additionalProperties: {
|
||||
type: 'string'
|
||||
lintable: boolean
|
||||
}
|
||||
}
|
||||
|
||||
const variablesSchema: VariableSchema = {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'string',
|
||||
lintable: true,
|
||||
},
|
||||
}
|
||||
|
||||
export default variablesSchema
|
||||
@@ -1,6 +1,6 @@
|
||||
// prevent `[foo] (bar)` strings with a space between from being interpreted as markdown links
|
||||
// by encoding the space character
|
||||
|
||||
export default function encodeBracketedParentheses(input) {
|
||||
export default function encodeBracketedParentheses(input: string): string {
|
||||
return input.replace(/] \(/g, '] (')
|
||||
}
|
||||
@@ -6,8 +6,9 @@ import fm from './frontmatter'
|
||||
/**
|
||||
* Read only the frontmatter from file
|
||||
*/
|
||||
export default async function fmfromf(filepath) {
|
||||
let fileContent = await fs.readFile(filepath, 'utf8')
|
||||
// Using any type for return value because frontmatter structure is complex and varies
|
||||
export default async function fmfromf(filepath: string): Promise<any> {
|
||||
let fileContent: string = await fs.readFile(filepath, 'utf8')
|
||||
|
||||
fileContent = encodeBracketedParentheses(fileContent)
|
||||
|
||||
@@ -3,9 +3,9 @@ import path from 'path'
|
||||
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
const gitignorePath = path.join(process.cwd(), '.gitignore')
|
||||
const gitignore = await fs.readFile(gitignorePath, 'utf8')
|
||||
const entries = gitignore.split(/\r?\n/)
|
||||
const gitignorePath: string = path.join(process.cwd(), '.gitignore')
|
||||
const gitignore: string = await fs.readFile(gitignorePath, 'utf8')
|
||||
const entries: string[] = gitignore.split(/\r?\n/)
|
||||
|
||||
describe('.gitignore file', () => {
|
||||
test('includes an entry for .env', () => {
|
||||
@@ -62,7 +62,7 @@ export default function Category({
|
||||
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
|
||||
const { default: getRest, getRestMiniTocItems } = await import('@/rest/lib/index')
|
||||
const nonEnterpriseDefaultVersionModule = await import(
|
||||
'src/versions/lib/non-enterprise-default-version.js'
|
||||
'@/versions/lib/non-enterprise-default-version'
|
||||
)
|
||||
const nonEnterpriseDefaultVersion = nonEnterpriseDefaultVersionModule.default as string
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
const NEXT_DATA_QUERY = 'script#__NEXT_DATA__'
|
||||
const PRIMER_DATA_QUERY = 'script#__PRIMER_DATA__'
|
||||
|
||||
function getScriptData($, key) {
|
||||
const data = $(key)
|
||||
if (!data.length === 1) {
|
||||
throw new Error(`Not exactly 1 element match for '${key}'. Found ${data.length}`)
|
||||
}
|
||||
return JSON.parse(data.get()[0].children[0].data)
|
||||
}
|
||||
|
||||
export const getNextData = ($) => getScriptData($, NEXT_DATA_QUERY)
|
||||
export const getPrimerData = ($) => getScriptData($, PRIMER_DATA_QUERY)
|
||||
15
src/tests/helpers/script-data.ts
Normal file
15
src/tests/helpers/script-data.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
const NEXT_DATA_QUERY = 'script#__NEXT_DATA__'
|
||||
const PRIMER_DATA_QUERY = 'script#__PRIMER_DATA__'
|
||||
|
||||
// Using any type for $ parameter as it represents a jQuery-like selector (cheerio)
|
||||
function getScriptData($: any, key: string): any {
|
||||
const data = $(key)
|
||||
if (data.length !== 1) {
|
||||
throw new Error(`Not exactly 1 element match for '${key}'. Found ${data.length}`)
|
||||
}
|
||||
return JSON.parse(data.get()[0].children[0].data)
|
||||
}
|
||||
|
||||
// Using any types for cheerio/jQuery-like objects and parsed JSON data
|
||||
export const getNextData = ($: any): any => getScriptData($, NEXT_DATA_QUERY)
|
||||
export const getPrimerData = ($: any): any => getScriptData($, PRIMER_DATA_QUERY)
|
||||
7
src/types/markdownlint-rules.d.ts
vendored
Normal file
7
src/types/markdownlint-rules.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// Simple type declaration for markdownlint external library
|
||||
// Using any types to avoid complex typing for external dependencies
|
||||
|
||||
declare module '../../../../node_modules/markdownlint/lib/rules' {
|
||||
const rules: any[]
|
||||
export = rules
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { allVersions } from '@/versions/lib/all-versions'
|
||||
|
||||
const nonEnterpriseDefaultVersion = Object.values(allVersions).find(
|
||||
(version) => version.nonEnterpriseDefault,
|
||||
).version
|
||||
)!.version
|
||||
|
||||
export default nonEnterpriseDefaultVersion
|
||||
@@ -4,6 +4,6 @@ import nonEnterpriseDefaultVersion from './non-enterprise-default-version'
|
||||
// This is a convenience function to remove free-pro-team@latest from all
|
||||
// **user-facing** aspects of the site (particularly URLs) while continuing to support
|
||||
// free-pro-team@latest as a version both in the codebase and in content/data files.
|
||||
export default function removeFPTFromPath(path) {
|
||||
export default function removeFPTFromPath(path: string): string {
|
||||
return slash(path.replace(`/${nonEnterpriseDefaultVersion}`, ''))
|
||||
}
|
||||
Reference in New Issue
Block a user