aboutsummaryrefslogtreecommitdiff
path: root/scripts
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
parentcb746cb466743a219c0e3845edb29527a06b0a35 (diff)
downloadfaker-00b9d4be4bff3b3f64edf163768af71c99bceed1.tar.xz
faker-00b9d4be4bff3b3f64edf163768af71c99bceed1.zip
chore: prefer string templates over string concatenation (#732)
Diffstat (limited to 'scripts')
-rw-r--r--scripts/apidoc/apiDocsWriter.ts6
-rw-r--r--scripts/apidoc/signature.ts33
-rw-r--r--scripts/generateLocales.ts9
-rw-r--r--scripts/verifyCommit.ts20
4 files changed, 39 insertions, 29 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();
}
diff --git a/scripts/generateLocales.ts b/scripts/generateLocales.ts
index f4c1f50d..38715b97 100644
--- a/scripts/generateLocales.ts
+++ b/scripts/generateLocales.ts
@@ -101,7 +101,7 @@ function generateLocaleFile(locale: string): void {
`;
content = format(content, prettierTsOptions);
- writeFileSync(resolve(pathLocale, locale + '.ts'), content);
+ writeFileSync(resolve(pathLocale, `${locale}.ts`), content);
}
function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition {
@@ -253,7 +253,7 @@ function updateLocaleFileHook(
localePath: string[]
): void {
if (filePath === 'never') {
- console.log(filePath + ' <-> ' + locale + ' @ ' + localePath.join(' -> '));
+ console.log(`${filePath} <-> ${locale} @ ${localePath.join(' -> ')}`);
}
}
@@ -285,13 +285,14 @@ for (const locale of locales) {
generateLocaleFile(locale);
// src/locales/**/index.ts
+ const separator = localeSeparator ? `\nseparator: '${localeSeparator}',` : '';
+
generateRecursiveModuleIndexes(
pathModules,
locale,
'LocaleDefinition',
1,
- `title: '${localeTitle}',` +
- (localeSeparator ? `\nseparator: '${localeSeparator}',` : '')
+ `title: '${localeTitle}',${separator}`
);
}
diff --git a/scripts/verifyCommit.ts b/scripts/verifyCommit.ts
index e2c4ae70..11f22ab4 100644
--- a/scripts/verifyCommit.ts
+++ b/scripts/verifyCommit.ts
@@ -18,16 +18,22 @@ const isMergeCommit = msg.startsWith('Merge remote-tracking-branch');
if (!isMergeCommit && !releaseRE.test(msg) && !commitRE.test(msg)) {
console.log();
+
console.error(
` ${colors.bgRed(colors.white(' ERROR '))} ${colors.red(
`invalid commit message format.`
- )}\n\n` +
- colors.red(
- ` Proper commit message format is required for automated changelog generation. Examples:\n\n`
- ) +
- ` ${colors.green(`feat: add 'comments' option`)}\n` +
- ` ${colors.green(`fix: handle events on blur (close #28)`)}\n\n` +
- colors.red(` See .github/commit-convention.md for more details.\n`)
+ )}
+
+ ${colors.red(
+ `Proper commit message format is required for automated changelog generation. Examples:`
+ )}
+
+ ${colors.green(`feat: add 'comments' option`)}
+ ${colors.green(`fix: handle events on blur (close #28)`)}
+
+ ${colors.red(`See .github/commit-convention.md for more details.`)}
+`
);
+
process.exit(1);
}