diff options
| -rw-r--r-- | .eslintrc.js | 1 | ||||
| -rw-r--r-- | scripts/apidoc/diff.ts | 6 | ||||
| -rw-r--r-- | scripts/apidoc/signature.ts | 39 | ||||
| -rw-r--r-- | scripts/generateLocales.ts | 8 | ||||
| -rw-r--r-- | src/modules/helpers/unique.ts | 22 | ||||
| -rw-r--r-- | src/modules/number/index.ts | 10 | ||||
| -rw-r--r-- | src/modules/person/index.ts | 17 | ||||
| -rw-r--r-- | src/modules/word/filterWordListByLength.ts | 8 |
8 files changed, 50 insertions, 61 deletions
diff --git a/.eslintrc.js b/.eslintrc.js index 26c86424..1eb35bb5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -30,6 +30,7 @@ module.exports = defineConfig({ 'no-useless-escape': 'off', 'deprecation/deprecation': 'error', eqeqeq: ['error', 'always', { null: 'ignore' }], + 'no-else-return': 'error', 'prefer-template': 'error', '@typescript-eslint/array-type': [ 'error', 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<DocsApiDiffIndex> { * @param source The source to load the diff index from. */ async function load(source: string): Promise<DocsApiDiffIndex> { - 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 { diff --git a/src/modules/helpers/unique.ts b/src/modules/helpers/unique.ts index 26f1b6d0..c6668137 100644 --- a/src/modules/helpers/unique.ts +++ b/src/modules/helpers/unique.ts @@ -150,16 +150,16 @@ export function exec< store[result] = result; options.currentIterations = 0; return result; - } else { - // console.log('conflict', result); - options.currentIterations++; - return exec(method, args, { - ...options, - startTime, - maxTime, - maxRetries, - compare, - exclude, - }); } + + // console.log('conflict', result); + options.currentIterations++; + return exec(method, args, { + ...options, + startTime, + maxTime, + maxRetries, + compare, + exclude, + }); } diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts index 1e3ed363..92751fe6 100644 --- a/src/modules/number/index.ts +++ b/src/modules/number/index.ts @@ -167,12 +167,12 @@ export class NumberModule { max: max * factor, }); return int / factor; - } else { - // @ts-expect-error: access private member field - const mersenne: Mersenne = this.faker._mersenne; - const real = mersenne.next(); - return real * (max - min) + min; } + + // @ts-expect-error: access private member field + const mersenne: Mersenne = this.faker._mersenne; + const real = mersenne.next(); + return real * (max - min) + min; } /** diff --git a/src/modules/person/index.ts b/src/modules/person/index.ts index 2d2d1dc1..5dbeea3d 100644 --- a/src/modules/person/index.ts +++ b/src/modules/person/index.ts @@ -149,18 +149,13 @@ export class PersonModule { } ); return this.faker.helpers.fake(pattern); - } else { - return selectDefinition( - this.faker, - this.faker.helpers.arrayElement, - sex, - { - generic: last_name, - female: female_last_name, - male: male_last_name, - } - ); } + + return selectDefinition(this.faker, this.faker.helpers.arrayElement, sex, { + generic: last_name, + female: female_last_name, + male: male_last_name, + }); } /** diff --git a/src/modules/word/filterWordListByLength.ts b/src/modules/word/filterWordListByLength.ts index ca312371..4651d497 100644 --- a/src/modules/word/filterWordListByLength.ts +++ b/src/modules/word/filterWordListByLength.ts @@ -87,12 +87,12 @@ export function filterWordListByLength(options: { if (typeof length === 'number') { return STRATEGIES[strategy](wordList, { min: length, max: length }); - } else { - return STRATEGIES[strategy](wordList, length); } + + return STRATEGIES[strategy](wordList, length); } else if (strategy === 'shortest' || strategy === 'longest') { return STRATEGIES[strategy](wordList); - } else { - return [...wordList]; } + + return [...wordList]; } |
