aboutsummaryrefslogtreecommitdiff
path: root/scripts/apidoc
diff options
context:
space:
mode:
authorPiotr Kuczynski <[email protected]>2022-04-19 22:38:17 +0200
committerGitHub <[email protected]>2022-04-19 22:38:17 +0200
commit00b9d4be4bff3b3f64edf163768af71c99bceed1 (patch)
tree0fa0e76b036c11c38eea251a8c4d371875810eed /scripts/apidoc
parentcb746cb466743a219c0e3845edb29527a06b0a35 (diff)
downloadfaker-00b9d4be4bff3b3f64edf163768af71c99bceed1.tar.xz
faker-00b9d4be4bff3b3f64edf163768af71c99bceed1.zip
chore: prefer string templates over string concatenation (#732)
Diffstat (limited to 'scripts/apidoc')
-rw-r--r--scripts/apidoc/apiDocsWriter.ts6
-rw-r--r--scripts/apidoc/signature.ts33
2 files changed, 21 insertions, 18 deletions
diff --git a/scripts/apidoc/apiDocsWriter.ts b/scripts/apidoc/apiDocsWriter.ts
index f712e4aa..cb803499 100644
--- a/scripts/apidoc/apiDocsWriter.ts
+++ b/scripts/apidoc/apiDocsWriter.ts
@@ -64,7 +64,7 @@ export function writeApiDocsModulePage(
content = vitePressInFileOptions + formatMarkdown(content);
- writeFileSync(resolve(pathOutputDir, lowerModuleName + '.md'), content);
+ writeFileSync(resolve(pathOutputDir, `${lowerModuleName}.md`), content);
}
/**
@@ -87,7 +87,7 @@ export function writeApiDocsDirectPage(methodName: string): void {
content = vitePressInFileOptions + formatMarkdown(content);
- writeFileSync(resolve(pathOutputDir, methodName + '.md'), content);
+ writeFileSync(resolve(pathOutputDir, `${methodName}.md`), content);
}
/**
@@ -111,7 +111,7 @@ export const ${lowerModuleName}: Method[] = ${JSON.stringify(
contentTs = formatTypescript(contentTs);
- writeFileSync(resolve(pathOutputDir, lowerModuleName + '.ts'), contentTs);
+ writeFileSync(resolve(pathOutputDir, `${lowerModuleName}.ts`), contentTs);
}
/**
diff --git a/scripts/apidoc/signature.ts b/scripts/apidoc/signature.ts
index 0341d7c0..704c4dad 100644
--- a/scripts/apidoc/signature.ts
+++ b/scripts/apidoc/signature.ts
@@ -29,7 +29,7 @@ export function prettifyMethodName(method: string): string {
export function toBlock(comment?: Comment): string {
return (
(comment?.shortText.trim() || 'Missing') +
- (comment?.text ? '\n\n' + comment.text : '')
+ (comment?.text ? `\n\n${comment.text}` : '')
);
}
@@ -116,11 +116,11 @@ export function analyzeSignature(
try {
let example = JSON.stringify(faker[moduleName][methodName]());
if (example.length > 50) {
- example = example.substring(0, 47) + '...';
+ example = `${example.substring(0, 47)}...`;
}
examples += `faker.${moduleName}.${methodName}()`;
- examples += (example ? ` // => ${example}` : '') + '\n';
+ examples += `${example ? ` // => ${example}` : ''}\n`;
} catch (error) {
// Ignore the error => hide the example call + result.
}
@@ -131,7 +131,7 @@ export function analyzeSignature(
.map((tag) => tag.text.trimEnd()) || [];
if (exampleTags.length > 0) {
- examples += exampleTags.join('\n').trim() + '\n';
+ examples += `${exampleTags.join('\n').trim()}\n`;
}
const seeAlsos =
@@ -140,13 +140,15 @@ export function analyzeSignature(
.map((t) => t.text.trim()) ?? [];
const prettyMethodName = prettifyMethodName(methodName);
+ const code = '```';
+
return {
name: methodName,
title: prettyMethodName,
description: mdToHtml(toBlock(signature.comment)),
parameters: parameters,
returns: typeToText(signature.type),
- examples: mdToHtml('```ts\n' + examples + '```'),
+ examples: mdToHtml(`${code}ts\n${examples}${code}`),
deprecated: signature.comment?.hasTag('deprecated') ?? false,
seeAlsos,
};
@@ -164,10 +166,10 @@ function analyzeParameter(parameter: ParameterReflection): {
let signatureText = '';
if (defaultValue) {
- signatureText = ' = ' + defaultValue;
+ signatureText = ` = ${defaultValue}`;
}
- const signature = declarationName + ': ' + typeToText(type) + signatureText;
+ const signature = `${declarationName}: ${typeToText(type)}${signatureText}`;
const parameters: MethodParameter[] = [
{
@@ -256,27 +258,28 @@ function declarationTypeToText(
switch (declaration.kind) {
case ReflectionKind.Method:
return signatureTypeToText(declaration.signatures[0]);
+
case ReflectionKind.Property:
return typeToText(declaration.type);
+
case ReflectionKind.TypeLiteral:
if (declaration.children?.length) {
if (short) {
// This is too long for the parameter table, thus we abbreviate this.
return '{ ... }';
}
- return (
- '{' +
- declaration.children
- .map((c) => `\n${c.name}: ${declarationTypeToText(c)}`)
- .join()
- .replace(/\n/g, '\n ') +
- '\n}'
- );
+
+ const list = declaration.children
+ .map((c) => ` ${c.name}: ${declarationTypeToText(c)}`)
+ .join(',\n');
+
+ return `{\n${list}\n}`;
} else if (declaration.signatures?.length) {
return signatureTypeToText(declaration.signatures[0]);
} else {
return declaration.toString();
}
+
default:
return declaration.toString();
}