diff options
| author | Shinigami <[email protected]> | 2022-12-31 12:22:38 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-12-31 12:22:38 +0100 |
| commit | 2d93e6f14a5ba976f87b71202bc4e011e38ee823 (patch) | |
| tree | 09c569ac0aa920ba090667a938f67416134dca26 /scripts | |
| parent | e296ff2d4f6f1aa56fe7c80722257bd0b316b30a (diff) | |
| download | faker-2d93e6f14a5ba976f87b71202bc4e011e38ee823.tar.xz faker-2d93e6f14a5ba976f87b71202bc4e011e38ee823.zip | |
chore: turn on padding-line-between-statements (#1691)
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/apidoc/apiDocsWriter.ts | 1 | ||||
| -rw-r--r-- | scripts/apidoc/moduleMethods.ts | 1 | ||||
| -rw-r--r-- | scripts/apidoc/parameterDefaults.ts | 2 | ||||
| -rw-r--r-- | scripts/apidoc/signature.ts | 10 | ||||
| -rw-r--r-- | scripts/apidoc/utils.ts | 1 | ||||
| -rw-r--r-- | scripts/bundle.ts | 1 | ||||
| -rw-r--r-- | scripts/generateLocales.ts | 3 |
7 files changed, 19 insertions, 0 deletions
diff --git a/scripts/apidoc/apiDocsWriter.ts b/scripts/apidoc/apiDocsWriter.ts index 1f0709bb..cd8dd2e5 100644 --- a/scripts/apidoc/apiDocsWriter.ts +++ b/scripts/apidoc/apiDocsWriter.ts @@ -161,6 +161,7 @@ export function writeApiSearchIndex(project: ProjectReflection): void { }, ]; } + return apiSection; }) .sort((a, b) => a.text.localeCompare(b.text)); diff --git a/scripts/apidoc/moduleMethods.ts b/scripts/apidoc/moduleMethods.ts index 10bce054..dd4f528a 100644 --- a/scripts/apidoc/moduleMethods.ts +++ b/scripts/apidoc/moduleMethods.ts @@ -46,6 +46,7 @@ export function extractModuleName(module: DeclarationReflection): string { } else if (name === 'NameModule') { return 'Person'; } + return name.replace(/Module$/, ''); } diff --git a/scripts/apidoc/parameterDefaults.ts b/scripts/apidoc/parameterDefaults.ts index 243d7e45..b889fe24 100644 --- a/scripts/apidoc/parameterDefaults.ts +++ b/scripts/apidoc/parameterDefaults.ts @@ -52,6 +52,7 @@ function cleanParameterDefault(value?: string): string | undefined { if (value == null) { return undefined; } + // Strip type casts: "'foobar' as unknown as T" => "'foobar'" return value.replace(/ as unknown as [A-Za-z<>]+/, ''); } @@ -124,6 +125,7 @@ function patchSignatureParameterDefaults( if (signatureParameters.length !== parameterDefaults.length) { throw new Error('Unexpected parameter length mismatch'); } + signatureParameters.forEach( (param, index) => (param.defaultValue = parameterDefaults[index] || param.defaultValue) diff --git a/scripts/apidoc/signature.ts b/scripts/apidoc/signature.ts index 3b97a2ef..22eed268 100644 --- a/scripts/apidoc/signature.ts +++ b/scripts/apidoc/signature.ts @@ -142,6 +142,7 @@ export function analyzeSignature( if (signatureTypeParameters.length !== 0) { signatureTypeParametersString = `<${signatureTypeParameters.join(', ')}>`; } + const signatureParametersString = signatureParameters.join(', '); let examples: string; @@ -150,6 +151,7 @@ export function analyzeSignature( } else { examples = `faker.${methodName}${signatureTypeParametersString}(${signatureParametersString}): ${signature.type?.toString()}\n`; } + faker.seed(0); if (moduleName) { try { @@ -230,6 +232,7 @@ function analyzeParameterOptions( if (!parameterType) { return []; } + if (parameterType.type === 'union') { return parameterType.types.flatMap((type) => analyzeParameterOptions(name, type) @@ -261,6 +264,7 @@ function typeToText(type_?: Type, short = false): string { if (!type_) { return '?'; } + const type = type_ as SomeType; switch (type.type) { case 'array': @@ -283,6 +287,7 @@ function typeToText(type_?: Type, short = false): string { .map((t) => typeToText(t, short)) .join(', ')}>`; } + case 'reflection': return declarationTypeToText(type.declaration, short); case 'indexedAccess': @@ -335,6 +340,7 @@ function signatureTypeToText(signature?: SignatureReflection): string { if (!signature) { return '(???) => ?'; } + return `(${signature.parameters ?.map((p) => `${p.name}: ${typeToText(p.type)}`) .join(', ')}) => ${typeToText(signature.type)}`; @@ -350,18 +356,22 @@ function extractDefaultFromComment(comment?: Comment): string | undefined { if (!comment) { return; } + const summary = comment.summary; const text = joinTagParts(summary).trim(); if (!text) { return; } + const result = /^(.*)[ \n]Defaults to `([^`]+)`\.(.*)$/s.exec(text); if (!result) { return; } + if (result[3].trim()) { throw new Error(`Found description text after the default value:\n${text}`); } + summary.splice(summary.length - 2, 2); const lastSummaryPart = summary[summary.length - 1]; lastSummaryPart.text = lastSummaryPart.text.replace(/[ \n]Defaults to $/, ''); diff --git a/scripts/apidoc/utils.ts b/scripts/apidoc/utils.ts index ef26a67d..9dad1b14 100644 --- a/scripts/apidoc/utils.ts +++ b/scripts/apidoc/utils.ts @@ -122,6 +122,7 @@ export function extractSeeAlsos(signature?: SignatureReflection): string[] { if (link.startsWith('-')) { link = link.slice(1).trim(); } + return link; }) .filter((link) => link) diff --git a/scripts/bundle.ts b/scripts/bundle.ts index a94d3183..e08b7de4 100644 --- a/scripts/bundle.ts +++ b/scripts/bundle.ts @@ -12,6 +12,7 @@ const target = ['ES2019', 'node14.17']; if (existsSync(localeDir)) { rmSync(localeDir, { recursive: true, force: true }); } + mkdirSync(localeDir); for (const locale of Object.keys(locales)) { writeFileSync( diff --git a/scripts/generateLocales.ts b/scripts/generateLocales.ts index d5540672..37f21ec9 100644 --- a/scripts/generateLocales.ts +++ b/scripts/generateLocales.ts @@ -82,6 +82,7 @@ function removeIndexTs(files: string[]): string[] { if (index !== -1) { files.splice(index, 1); } + return files; } @@ -152,6 +153,7 @@ function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition { console.error(`Failed to load ${pathModules} or manually parse it.`, e); } } + return localeDef; } @@ -177,6 +179,7 @@ function generateLocalesIndexFile( )}';` ); } + content.push( ...modules.map((m) => `import ${escapeImport(m)} from './${m}';`) ); |
