From cddbb959f13aa29a7264174b1fc4eaa4271cf900 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Mon, 3 Apr 2023 21:14:12 +0200 Subject: chore: activate eslint no-else-return (#2009) --- scripts/apidoc/diff.ts | 6 +----- scripts/apidoc/signature.ts | 39 ++++++++++++++++++--------------------- scripts/generateLocales.ts | 8 ++++---- 3 files changed, 23 insertions(+), 30 deletions(-) (limited to 'scripts') diff --git a/scripts/apidoc/diff.ts b/scripts/apidoc/diff.ts index 913062c8..654f44b0 100644 --- a/scripts/apidoc/diff.ts +++ b/scripts/apidoc/diff.ts @@ -35,11 +35,7 @@ async function loadLocal(path: string): Promise { * @param source The source to load the diff index from. */ async function load(source: string): Promise { - if (source.startsWith('https://')) { - return loadRemote(source); - } else { - return loadLocal(source); - } + return source.startsWith('https://') ? loadRemote(source) : loadLocal(source); } /** diff --git a/scripts/apidoc/signature.ts b/scripts/apidoc/signature.ts index 113aba1d..05944ba7 100644 --- a/scripts/apidoc/signature.ts +++ b/scripts/apidoc/signature.ts @@ -95,13 +95,13 @@ function mdToHtml(md: string, inline: boolean = false): string { // Revert some escaped characters for comparison. if (comparableSanitizedHtml(rawHtml) === comparableSanitizedHtml(safeHtml)) { return safeHtml; - } else { - console.debug('Rejected unsafe md:', md); - console.error('Rejected unsafe html:', rawHtml); - console.error('Rejected unsafe html:', comparableSanitizedHtml(rawHtml)); - console.error('Expected safe html:', comparableSanitizedHtml(safeHtml)); - throw new Error('Found unsafe html'); } + + console.debug('Rejected unsafe md:', md); + console.error('Rejected unsafe html:', rawHtml); + console.error('Rejected unsafe html:', comparableSanitizedHtml(rawHtml)); + console.error('Expected safe html:', comparableSanitizedHtml(safeHtml)); + throw new Error('Found unsafe html'); } export function analyzeSignature( @@ -264,11 +264,8 @@ function typeToText(type_?: Type, short = false): string { switch (type.type) { case 'array': { const text = typeToText(type.elementType, short); - if (text.includes('|') || text.includes('{')) { - return `Array<${text}>`; - } else { - return `${text}[]`; - } + const isComplexType = text.includes('|') || text.includes('{'); + return isComplexType ? `Array<${text}>` : `${text}[]`; } case 'union': @@ -288,20 +285,20 @@ function typeToText(type_?: Type, short = false): string { !type.name.match(/Char$/) ) { return typeToText(reflectionType, short); - } else { - return type.name; } + + return type.name; } else if (type.name === 'LiteralUnion') { return [ typeToText(type.typeArguments[0], short), typeToText(type.typeArguments[1], short), ].join(' | '); - } else { - return `${type.name}<${type.typeArguments - .map((t) => typeToText(t, short)) - .join(', ')}>`; } + return `${type.name}<${type.typeArguments + .map((t) => typeToText(t, short)) + .join(', ')}>`; + case 'reflection': return declarationTypeToText(type.declaration, short); @@ -318,9 +315,9 @@ function typeToText(type_?: Type, short = false): string { const text = typeToText(type.target, short); if (short && type.operator === 'readonly') { return text; - } else { - return `${type.operator} ${text}`; } + + return `${type.operator} ${text}`; } default: @@ -353,10 +350,10 @@ function declarationTypeToText( return `{\n${list}\n}`; } else if (declaration.signatures?.length) { return signatureTypeToText(declaration.signatures[0]); - } else { - return declaration.toString(); } + return declaration.toString(); + default: return declaration.toString(); } diff --git a/scripts/generateLocales.ts b/scripts/generateLocales.ts index b721cb90..2af0c46a 100644 --- a/scripts/generateLocales.ts +++ b/scripts/generateLocales.ts @@ -102,17 +102,17 @@ function removeTsSuffix(files: string[]): string[] { function escapeImport(parent: string, module: string): string { if (['name', 'type', 'switch', parent].includes(module)) { return `${module}_`; - } else { - return module; } + + return module; } function escapeField(parent: string, module: string): string { if (['name', 'type', 'switch', parent].includes(module)) { return `${module}: ${module}_`; - } else { - return module; } + + return module; } function generateLocaleFile(locale: string): void { -- cgit v1.2.3