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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = defineConfig({
'unicorn/no-null': 'off', // incompatible with TypeScript
'unicorn/no-zero-fractions': 'off', // deactivated to raise awareness of floating operations
'unicorn/number-literal-case': 'off', // incompatible with prettier
'unicorn/prefer-ternary': 'off', // ternaries aren't always better

// TODO @Shinigami92 2023-09-23: prefer-at should be turned on when we drop support for Node 14.
'unicorn/prefer-at': 'off',
Expand All @@ -59,7 +60,6 @@ module.exports = defineConfig({
'unicorn/prefer-module': 'off',
'unicorn/prefer-negative-index': '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';
const useContext = context && source['abbr_context'] != null;
type = useContext ? 'abbr_context' : 'abbr';
} else {
type = 'wide';
const useContext = context && source['wide_context'] != null;
type = useContext ? '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';
const useContext = context && source['abbr_context'] != null;
type = useContext ? 'abbr_context' : 'abbr';
} else {
type = 'wide';
const useContext = context && source['wide_context'] != null;
type = useContext ? 'wide_context' : 'wide';
}

return this.faker.helpers.arrayElement(source[type]);
Expand Down
11 changes: 3 additions & 8 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
6 changes: 1 addition & 5 deletions src/modules/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1475,11 +1475,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