Skip to content

Commit

Permalink
chore: activate eslint no-else-return (#2009)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Apr 3, 2023
1 parent 71232ba commit cddbb95
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 61 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 1 addition & 5 deletions scripts/apidoc/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
39 changes: 18 additions & 21 deletions scripts/apidoc/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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':
Expand All @@ -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);

Expand All @@ -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:
Expand Down Expand Up @@ -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();
}
Expand Down
8 changes: 4 additions & 4 deletions scripts/generateLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions src/modules/helpers/unique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
10 changes: 5 additions & 5 deletions src/modules/number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
17 changes: 6 additions & 11 deletions src/modules/person/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/modules/word/filterWordListByLength.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

0 comments on commit cddbb95

Please sign in to comment.