From 8a405fadcd3c4c5fb97e2069df9fc800703b9a98 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Thu, 26 Oct 2023 20:53:10 +0200 Subject: [PATCH 1/2] infra(unicorn): prefer-array-some (#2451) --- .eslintrc.js | 1 - 1 file changed, 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index bf9afd39afa..669d5d2c1f0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -54,7 +54,6 @@ module.exports = defineConfig({ 'unicorn/no-object-as-default-parameter': 'off', 'unicorn/no-useless-switch-case': 'off', 'unicorn/numeric-separators-style': 'off', - 'unicorn/prefer-array-some': 'off', 'unicorn/prefer-code-point': 'off', 'unicorn/prefer-export-from': 'off', 'unicorn/prefer-module': 'off', From 9297e5b654d3aa44ec5d8601c8947ee707687e17 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Fri, 27 Oct 2023 00:12:41 +0200 Subject: [PATCH 2/2] infra(unicorn): prefer-ternary (#2464) --- .eslintrc.js | 2 +- src/modules/date/index.ts | 24 ++++++++---------------- src/modules/finance/index.ts | 11 +++-------- src/modules/internet/index.ts | 6 +----- 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 669d5d2c1f0..5f72451ba2f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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', @@ -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', diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts index e93be54d90f..3ad5f438383 100644 --- a/src/modules/date/index.ts +++ b/src/modules/date/index.ts @@ -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]); @@ -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]); diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index b932ab20d97..99d84da38c0 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -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); return symbol + formattedString; } diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 70e14ec7155..aecdb302a48 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -1475,11 +1475,7 @@ export class InternetModule { } if (memorable) { - if (consonant.test(prefix)) { - pattern = vowel; - } else { - pattern = consonant; - } + pattern = consonant.test(prefix) ? vowel : consonant; } const n = this.faker.number.int(94) + 33;