diff options
| author | ST-DDT <[email protected]> | 2024-03-06 17:35:53 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-06 16:35:53 +0000 |
| commit | 2716865a0441b8502c8d0ee3efbdbe1bcebe0101 (patch) | |
| tree | 2b98c5b34f4dfbd4eab56e8463b9b9f5c72f428a /src/modules | |
| parent | ade91fd30d6b5fbcc2ab2534502467b1e0f3b086 (diff) | |
| download | faker-2716865a0441b8502c8d0ee3efbdbe1bcebe0101.tar.xz faker-2716865a0441b8502c8d0ee3efbdbe1bcebe0101.zip | |
infra(unicorn): switch-case-braces (#2721)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/color/index.ts | 54 | ||||
| -rw-r--r-- | src/modules/helpers/eval.ts | 10 | ||||
| -rw-r--r-- | src/modules/helpers/index.ts | 3 | ||||
| -rw-r--r-- | src/modules/location/index.ts | 11 | ||||
| -rw-r--r-- | src/modules/person/index.ts | 9 | ||||
| -rw-r--r-- | src/modules/string/index.ts | 22 | ||||
| -rw-r--r-- | src/modules/system/index.ts | 15 |
7 files changed, 90 insertions, 34 deletions
diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts index 779bd20b..2b355062 100644 --- a/src/modules/color/index.ts +++ b/src/modules/color/index.ts @@ -60,12 +60,16 @@ function formatHexColor( const { prefix, casing } = options; switch (casing) { - case 'upper': + case 'upper': { hexColor = hexColor.toUpperCase(); break; - case 'lower': + } + + case 'lower': { hexColor = hexColor.toLowerCase(); break; + } + case 'mixed': // Do nothing } @@ -111,32 +115,49 @@ function toCSS( ): string { const percentage = (value: number) => Math.round(value * 100); switch (cssFunction) { - case 'rgba': + case 'rgba': { return `rgba(${values[0]}, ${values[1]}, ${values[2]}, ${values[3]})`; - case 'color': + } + + case 'color': { return `color(${space} ${values[0]} ${values[1]} ${values[2]})`; - case 'cmyk': + } + + case 'cmyk': { return `cmyk(${percentage(values[0])}%, ${percentage( values[1] )}%, ${percentage(values[2])}%, ${percentage(values[3])}%)`; - case 'hsl': + } + + case 'hsl': { return `hsl(${values[0]}deg ${percentage(values[1])}% ${percentage( values[2] )}%)`; - case 'hsla': + } + + case 'hsla': { return `hsl(${values[0]}deg ${percentage(values[1])}% ${percentage( values[2] )}% / ${percentage(values[3])})`; - case 'hwb': + } + + case 'hwb': { return `hwb(${values[0]} ${percentage(values[1])}% ${percentage( values[2] )}%)`; - case 'lab': + } + + case 'lab': { return `lab(${percentage(values[0])}% ${values[1]} ${values[2]})`; - case 'lch': + } + + case 'lch': { return `lch(${percentage(values[0])}% ${values[1]} ${values[2]})`; - case 'rgb': + } + + case 'rgb': { return `rgb(${values[0]}, ${values[1]}, ${values[2]})`; + } } } @@ -155,12 +176,17 @@ function toColorFormat( space: CssSpaceType = 'sRGB' ): string | number[] { switch (format) { - case 'css': + case 'css': { return toCSS(values, cssFunction, space); - case 'binary': + } + + case 'binary': { return toBinary(values); - case 'decimal': + } + + case 'decimal': { return values; + } } } diff --git a/src/modules/helpers/eval.ts b/src/modules/helpers/eval.ts index 033c5d35..4a861ec0 100644 --- a/src/modules/helpers/eval.ts +++ b/src/modules/helpers/eval.ts @@ -119,12 +119,15 @@ function evalProcessFunction( switch (nextChar) { case '.': case '(': - case undefined: + case undefined: { break; // valid - default: + } + + default: { throw new FakerError( `Expected dot ('.'), open parenthesis ('('), or nothing after function call but got '${nextChar}'` ); + } } return [ @@ -223,7 +226,8 @@ function resolveProperty(entrypoint: unknown, key: string): unknown { return entrypoint?.[key as keyof typeof entrypoint]; } - default: + default: { return undefined; + } } } diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index b21f13e7..b86b2cd7 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -56,8 +56,9 @@ function getRepetitionsBasedOnQuantifierParameters( break; } - default: + default: { throw new FakerError('Unknown quantifier symbol provided.'); + } } } else if (quantifierMin != null && quantifierMax != null) { repetitions = faker.number.int({ diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts index 97120766..92284560 100644 --- a/src/modules/location/index.ts +++ b/src/modules/location/index.ts @@ -355,12 +355,17 @@ export class LocationModule extends ModuleBase { const { variant = 'alpha-2' } = options; const key = (() => { switch (variant) { - case 'numeric': + case 'numeric': { return 'numeric'; - case 'alpha-3': + } + + case 'alpha-3': { return 'alpha3'; - case 'alpha-2': + } + + case 'alpha-2': { return 'alpha2'; + } } })(); diff --git a/src/modules/person/index.ts b/src/modules/person/index.ts index dce8a45f..6bb4f776 100644 --- a/src/modules/person/index.ts +++ b/src/modules/person/index.ts @@ -37,17 +37,20 @@ function selectDefinition<T>( let values: T[] | undefined | null; switch (sex) { - case Sex.Female: + case Sex.Female: { values = female; break; + } - case Sex.Male: + case Sex.Male: { values = male; break; + } - default: + default: { values = generic; break; + } } if (values == null) { diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts index cf469a2c..cfee0dc1 100644 --- a/src/modules/string/index.ts +++ b/src/modules/string/index.ts @@ -223,15 +223,20 @@ export class StringModule extends SimpleModuleBase { let charsArray: string[]; switch (casing) { - case 'upper': + case 'upper': { charsArray = [...UPPER_CHARS]; break; - case 'lower': + } + + case 'lower': { charsArray = [...LOWER_CHARS]; break; - case 'mixed': + } + + case 'mixed': { charsArray = [...LOWER_CHARS, ...UPPER_CHARS]; break; + } } charsArray = charsArray.filter((elem) => !exclude.includes(elem)); @@ -313,15 +318,20 @@ export class StringModule extends SimpleModuleBase { let charsArray = [...DIGIT_CHARS]; switch (casing) { - case 'upper': + case 'upper': { charsArray.push(...UPPER_CHARS); break; - case 'lower': + } + + case 'lower': { charsArray.push(...LOWER_CHARS); break; - case 'mixed': + } + + case 'mixed': { charsArray.push(...LOWER_CHARS, ...UPPER_CHARS); break; + } } charsArray = charsArray.filter((elem) => !exclude.includes(elem)); diff --git a/src/modules/system/index.ts b/src/modules/system/index.ts index ee0d2600..3468bbb0 100644 --- a/src/modules/system/index.ts +++ b/src/modules/system/index.ts @@ -266,23 +266,30 @@ export class SystemModule extends ModuleBase { let prefix = ''; const digit = () => this.faker.string.numeric({ allowLeadingZeros: true }); switch (interfaceSchema) { - case 'index': + case 'index': { suffix = digit(); break; - case 'slot': + } + + case 'slot': { suffix = `${digit()}${ this.faker.helpers.maybe(() => `f${digit()}`) ?? '' }${this.faker.helpers.maybe(() => `d${digit()}`) ?? ''}`; break; - case 'mac': + } + + case 'mac': { suffix = this.faker.internet.mac(''); break; - case 'pci': + } + + case 'pci': { prefix = this.faker.helpers.maybe(() => `P${digit()}`) ?? ''; suffix = `${digit()}s${digit()}${ this.faker.helpers.maybe(() => `f${digit()}`) ?? '' }${this.faker.helpers.maybe(() => `d${digit()}`) ?? ''}`; break; + } } return `${prefix}${interfaceType}${commonInterfaceSchemas[interfaceSchema]}${suffix}`; |
