Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra(unicorn): prefer-ternary #2464

Merged
merged 11 commits into from
Oct 26, 2023
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ module.exports = defineConfig({
'unicorn/prefer-optional-catch-binding': 'off',
'unicorn/prefer-spread': 'off',
'unicorn/prefer-string-slice': 'off',
'unicorn/prefer-ternary': 'off',
'unicorn/prefer-top-level-await': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/require-array-join-separator': 'off',
Expand Down
24 changes: 8 additions & 16 deletions src/modules/date/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,15 +1097,11 @@ export class DateModule extends SimpleDateModule {
const source = this.faker.definitions.date.month;
let type: keyof DateEntryDefinition;
if (abbreviated) {
if (context && source['abbr_context'] != null) {
type = 'abbr_context';
} else {
type = 'abbr';
}
} else if (context && source['wide_context'] != null) {
type = 'wide_context';
type =
context && source['abbr_context'] != null ? 'abbr_context' : 'abbr';
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
} else {
type = 'wide';
type =
context && source['wide_context'] != null ? 'wide_context' : 'wide';
}

return this.faker.helpers.arrayElement(source[type]);
Expand Down Expand Up @@ -1287,15 +1283,11 @@ export class DateModule extends SimpleDateModule {
const source = this.faker.definitions.date.weekday;
let type: keyof DateEntryDefinition;
if (abbreviated) {
if (context && source['abbr_context'] != null) {
type = 'abbr_context';
} else {
type = 'abbr';
}
} else if (context && source['wide_context'] != null) {
type = 'wide_context';
type =
context && source['abbr_context'] != null ? 'abbr_context' : 'abbr';
} else {
type = 'wide';
type =
context && source['wide_context'] != null ? 'wide_context' : 'wide';
}

return this.faker.helpers.arrayElement(source[type]);
Expand Down
19 changes: 6 additions & 13 deletions src/modules/finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,9 @@ export class FinanceModule {
precision: 10 ** -dec,
});

let formattedString: string;
if (autoFormat) {
formattedString = randValue.toLocaleString(undefined, {
minimumFractionDigits: dec,
});
} else {
formattedString = randValue.toFixed(dec);
}
const formattedString = autoFormat
? randValue.toLocaleString(undefined, { minimumFractionDigits: dec })
: randValue.toFixed(dec);
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved

return symbol + formattedString;
}
Expand Down Expand Up @@ -1129,11 +1124,9 @@ export class FinanceModule {
if (bban.type === 'a') {
s += this.faker.helpers.arrayElement(iban.alpha);
} else if (bban.type === 'c') {
if (this.faker.datatype.boolean(0.8)) {
s += this.faker.number.int(9);
} else {
s += this.faker.helpers.arrayElement(iban.alpha);
}
s += this.faker.datatype.boolean(0.8)
? this.faker.number.int(9)
: this.faker.helpers.arrayElement(iban.alpha);
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
} else {
if (c >= 3 && this.faker.datatype.boolean(0.3)) {
if (this.faker.datatype.boolean()) {
Expand Down
6 changes: 1 addition & 5 deletions src/modules/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1476,11 +1476,7 @@ export class InternetModule {
}

if (memorable) {
if (consonant.test(prefix)) {
pattern = vowel;
} else {
pattern = consonant;
}
pattern = consonant.test(prefix) ? vowel : consonant;
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
}

const n = this.faker.number.int(94) + 33;
Expand Down
9 changes: 4 additions & 5 deletions src/modules/person/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@
}

if (values == null) {
if (female != null && male != null) {
values = faker.helpers.arrayElement([female, male]);
} else {
values = generic;
}
values =
female != null && male != null
? faker.helpers.arrayElement([female, male])

Check warning on line 50 in src/modules/person/index.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/person/index.ts#L50

Added line #L50 was not covered by tests
: generic;
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
}

return elementSelectorFn(values);
Expand Down
9 changes: 4 additions & 5 deletions src/simple-faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ export class SimpleFaker {
setDefaultRefDate(
dateOrSource: string | Date | number | (() => Date) = () => new Date()
): void {
if (typeof dateOrSource === 'function') {
this._defaultRefDate = dateOrSource;
} else {
this._defaultRefDate = () => new Date(dateOrSource);
}
this._defaultRefDate =
typeof dateOrSource === 'function'
? dateOrSource
: () => new Date(dateOrSource);
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
}

/** @internal */
Expand Down
10 changes: 4 additions & 6 deletions src/utils/merge-locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ export function mergeLocales(locales: LocaleDefinition[]): LocaleDefinition {

for (const locale of locales) {
for (const key in locale) {
const value = locale[key];
if (merged[key] === undefined) {
merged[key] = { ...value };
} else {
merged[key] = { ...value, ...merged[key] };
}
merged[key] =
merged[key] === undefined
? { ...locale[key] }
: { ...locale[key], ...merged[key] };
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down