Skip to content

Commit

Permalink
infra(unicorn): prefer-export-from (#3272)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Dec 2, 2024
1 parent 176d430 commit 7d59cd9
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 156 deletions.
1 change: 0 additions & 1 deletion eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ const config: ReturnType<typeof tseslint.config> = tseslint.config(

// TODO @Shinigami92 2023-09-23: The following rules currently conflict with our code.
// Each rule should be checked whether it should be enabled/configured and the problems fixed, or stay disabled permanently.
'unicorn/prefer-export-from': 'off',
'unicorn/prevent-abbreviations': 'off',
},
},
Expand Down
16 changes: 11 additions & 5 deletions scripts/generate-locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,14 @@ async function normalizeLocaleFile(filePath: string, definitionKey: string) {
const locales = await readdir(pathLocales);
removeIndexTs(locales);

// src/locale/index.ts (Faker Imports and Exports)
let localeIndexImports = '';
let localeIndexExportsIndividual = '';
let localeIndexExportsGrouped = '';
// src/locales/index.ts (Locale Data Imports and Exports)
let localesIndexImports = '';
let localesIndexExportsIndividual = '';
let localesIndexExportsGrouped = '';

let localizationLocales = '| Locale | Name | Faker |\n| :--- | :--- | :--- |\n';
const promises: Array<Promise<unknown>> = [];
Expand Down Expand Up @@ -459,9 +463,11 @@ for (const locale of locales) {
)}`;

localeIndexImports += `import { faker as ${localizedFaker} } from './${locale}';\n`;
localeIndexExportsIndividual += ` ${localizedFaker},\n`;
localeIndexExportsIndividual += `export { faker as ${localizedFaker} } from './${locale}';\n`;
localeIndexExportsGrouped += ` ${locale}: ${localizedFaker},\n`;
localesIndexImports += `import { default as ${locale} } from './${locale}';\n`;
localesIndexExportsIndividual += `export { default as ${locale} } from './${locale}';\n`;
localesIndexExportsGrouped += ` ${locale},\n`;
localizationLocales += `| \`${locale}\` | ${localeTitle} | \`${localizedFaker}\` |\n`;

promises.push(
Expand All @@ -484,9 +490,7 @@ let localeIndexContent = `
${localeIndexImports}
export {
${localeIndexExportsIndividual}
};
export const allFakers = {
${localeIndexExportsGrouped}
Expand All @@ -503,9 +507,11 @@ let localesIndexContent = `
${localesIndexImports}
export { ${locales.join(',')} };
${localesIndexExportsIndividual}
export const allLocales = { ${locales.join(',')} };
export const allLocales = {
${localesIndexExportsGrouped}
} as const;
`;

localesIndexContent = await formatTypescript(localesIndexContent);
Expand Down
140 changes: 69 additions & 71 deletions src/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,77 +73,75 @@ import { faker as fakerZH_CN } from './zh_CN';
import { faker as fakerZH_TW } from './zh_TW';
import { faker as fakerZU_ZA } from './zu_ZA';

export {
fakerAF_ZA,
fakerAR,
fakerAZ,
fakerBASE,
fakerCS_CZ,
fakerDA,
fakerDE,
fakerDE_AT,
fakerDE_CH,
fakerDV,
fakerEL,
fakerEN,
fakerEN_AU,
fakerEN_AU_ocker,
fakerEN_BORK,
fakerEN_CA,
fakerEN_GB,
fakerEN_GH,
fakerEN_HK,
fakerEN_IE,
fakerEN_IN,
fakerEN_NG,
fakerEN_US,
fakerEN_ZA,
fakerEO,
fakerES,
fakerES_MX,
fakerFA,
fakerFI,
fakerFR,
fakerFR_BE,
fakerFR_CA,
fakerFR_CH,
fakerFR_LU,
fakerFR_SN,
fakerHE,
fakerHR,
fakerHU,
fakerHY,
fakerID_ID,
fakerIT,
fakerJA,
fakerKA_GE,
fakerKO,
fakerLV,
fakerMK,
fakerNB_NO,
fakerNE,
fakerNL,
fakerNL_BE,
fakerPL,
fakerPT_BR,
fakerPT_PT,
fakerRO,
fakerRO_MD,
fakerRU,
fakerSK,
fakerSR_RS_latin,
fakerSV,
fakerTH,
fakerTR,
fakerUK,
fakerUR,
fakerUZ_UZ_latin,
fakerVI,
fakerYO_NG,
fakerZH_CN,
fakerZH_TW,
fakerZU_ZA,
};
export { faker as fakerAF_ZA } from './af_ZA';
export { faker as fakerAR } from './ar';
export { faker as fakerAZ } from './az';
export { faker as fakerBASE } from './base';
export { faker as fakerCS_CZ } from './cs_CZ';
export { faker as fakerDA } from './da';
export { faker as fakerDE } from './de';
export { faker as fakerDE_AT } from './de_AT';
export { faker as fakerDE_CH } from './de_CH';
export { faker as fakerDV } from './dv';
export { faker as fakerEL } from './el';
export { faker as fakerEN } from './en';
export { faker as fakerEN_AU } from './en_AU';
export { faker as fakerEN_AU_ocker } from './en_AU_ocker';
export { faker as fakerEN_BORK } from './en_BORK';
export { faker as fakerEN_CA } from './en_CA';
export { faker as fakerEN_GB } from './en_GB';
export { faker as fakerEN_GH } from './en_GH';
export { faker as fakerEN_HK } from './en_HK';
export { faker as fakerEN_IE } from './en_IE';
export { faker as fakerEN_IN } from './en_IN';
export { faker as fakerEN_NG } from './en_NG';
export { faker as fakerEN_US } from './en_US';
export { faker as fakerEN_ZA } from './en_ZA';
export { faker as fakerEO } from './eo';
export { faker as fakerES } from './es';
export { faker as fakerES_MX } from './es_MX';
export { faker as fakerFA } from './fa';
export { faker as fakerFI } from './fi';
export { faker as fakerFR } from './fr';
export { faker as fakerFR_BE } from './fr_BE';
export { faker as fakerFR_CA } from './fr_CA';
export { faker as fakerFR_CH } from './fr_CH';
export { faker as fakerFR_LU } from './fr_LU';
export { faker as fakerFR_SN } from './fr_SN';
export { faker as fakerHE } from './he';
export { faker as fakerHR } from './hr';
export { faker as fakerHU } from './hu';
export { faker as fakerHY } from './hy';
export { faker as fakerID_ID } from './id_ID';
export { faker as fakerIT } from './it';
export { faker as fakerJA } from './ja';
export { faker as fakerKA_GE } from './ka_GE';
export { faker as fakerKO } from './ko';
export { faker as fakerLV } from './lv';
export { faker as fakerMK } from './mk';
export { faker as fakerNB_NO } from './nb_NO';
export { faker as fakerNE } from './ne';
export { faker as fakerNL } from './nl';
export { faker as fakerNL_BE } from './nl_BE';
export { faker as fakerPL } from './pl';
export { faker as fakerPT_BR } from './pt_BR';
export { faker as fakerPT_PT } from './pt_PT';
export { faker as fakerRO } from './ro';
export { faker as fakerRO_MD } from './ro_MD';
export { faker as fakerRU } from './ru';
export { faker as fakerSK } from './sk';
export { faker as fakerSR_RS_latin } from './sr_RS_latin';
export { faker as fakerSV } from './sv';
export { faker as fakerTH } from './th';
export { faker as fakerTR } from './tr';
export { faker as fakerUK } from './uk';
export { faker as fakerUR } from './ur';
export { faker as fakerUZ_UZ_latin } from './uz_UZ_latin';
export { faker as fakerVI } from './vi';
export { faker as fakerYO_NG } from './yo_NG';
export { faker as fakerZH_CN } from './zh_CN';
export { faker as fakerZH_TW } from './zh_TW';
export { faker as fakerZU_ZA } from './zu_ZA';

export const allFakers = {
af_ZA: fakerAF_ZA,
Expand Down
4 changes: 1 addition & 3 deletions src/locales/base/location/time_zone.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import timeZone from '../date/time_zone';

// The base locale uses any possible time zone.
export default timeZone;
export { default } from '../date/time_zone';
3 changes: 1 addition & 2 deletions src/locales/hr/location/county.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// Since first-level administrative regions of Croatia are called "counties" we return them both from the state() and county() methods
import state from './state';
export default state;
export { default } from './state';
142 changes: 70 additions & 72 deletions src/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,77 +73,75 @@ import { default as zh_CN } from './zh_CN';
import { default as zh_TW } from './zh_TW';
import { default as zu_ZA } from './zu_ZA';

export {
af_ZA,
ar,
az,
base,
cs_CZ,
da,
de,
de_AT,
de_CH,
dv,
el,
en,
en_AU,
en_AU_ocker,
en_BORK,
en_CA,
en_GB,
en_GH,
en_HK,
en_IE,
en_IN,
en_NG,
en_US,
en_ZA,
eo,
es,
es_MX,
fa,
fi,
fr,
fr_BE,
fr_CA,
fr_CH,
fr_LU,
fr_SN,
he,
hr,
hu,
hy,
id_ID,
it,
ja,
ka_GE,
ko,
lv,
mk,
nb_NO,
ne,
nl,
nl_BE,
pl,
pt_BR,
pt_PT,
ro,
ro_MD,
ru,
sk,
sr_RS_latin,
sv,
th,
tr,
uk,
ur,
uz_UZ_latin,
vi,
yo_NG,
zh_CN,
zh_TW,
zu_ZA,
};
export { default as af_ZA } from './af_ZA';
export { default as ar } from './ar';
export { default as az } from './az';
export { default as base } from './base';
export { default as cs_CZ } from './cs_CZ';
export { default as da } from './da';
export { default as de } from './de';
export { default as de_AT } from './de_AT';
export { default as de_CH } from './de_CH';
export { default as dv } from './dv';
export { default as el } from './el';
export { default as en } from './en';
export { default as en_AU } from './en_AU';
export { default as en_AU_ocker } from './en_AU_ocker';
export { default as en_BORK } from './en_BORK';
export { default as en_CA } from './en_CA';
export { default as en_GB } from './en_GB';
export { default as en_GH } from './en_GH';
export { default as en_HK } from './en_HK';
export { default as en_IE } from './en_IE';
export { default as en_IN } from './en_IN';
export { default as en_NG } from './en_NG';
export { default as en_US } from './en_US';
export { default as en_ZA } from './en_ZA';
export { default as eo } from './eo';
export { default as es } from './es';
export { default as es_MX } from './es_MX';
export { default as fa } from './fa';
export { default as fi } from './fi';
export { default as fr } from './fr';
export { default as fr_BE } from './fr_BE';
export { default as fr_CA } from './fr_CA';
export { default as fr_CH } from './fr_CH';
export { default as fr_LU } from './fr_LU';
export { default as fr_SN } from './fr_SN';
export { default as he } from './he';
export { default as hr } from './hr';
export { default as hu } from './hu';
export { default as hy } from './hy';
export { default as id_ID } from './id_ID';
export { default as it } from './it';
export { default as ja } from './ja';
export { default as ka_GE } from './ka_GE';
export { default as ko } from './ko';
export { default as lv } from './lv';
export { default as mk } from './mk';
export { default as nb_NO } from './nb_NO';
export { default as ne } from './ne';
export { default as nl } from './nl';
export { default as nl_BE } from './nl_BE';
export { default as pl } from './pl';
export { default as pt_BR } from './pt_BR';
export { default as pt_PT } from './pt_PT';
export { default as ro } from './ro';
export { default as ro_MD } from './ro_MD';
export { default as ru } from './ru';
export { default as sk } from './sk';
export { default as sr_RS_latin } from './sr_RS_latin';
export { default as sv } from './sv';
export { default as th } from './th';
export { default as tr } from './tr';
export { default as uk } from './uk';
export { default as ur } from './ur';
export { default as uz_UZ_latin } from './uz_UZ_latin';
export { default as vi } from './vi';
export { default as yo_NG } from './yo_NG';
export { default as zh_CN } from './zh_CN';
export { default as zh_TW } from './zh_TW';
export { default as zu_ZA } from './zu_ZA';

export const allLocales = {
af_ZA,
Expand Down Expand Up @@ -215,4 +213,4 @@ export const allLocales = {
zh_CN,
zh_TW,
zu_ZA,
};
} as const;
10 changes: 8 additions & 2 deletions test/scripts/apidocs/method.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import { FakerError } from '../../../src/errors/faker-error';
import type { LiteralUnion } from '../../../src/internal/types';
import type { AlphaNumericChar } from '../../../src/modules/string';
// explicitly export types so they show up in the docs as decomposed types
export type { NumberColorFormat, StringColorFormat } from '../../../src';
export type { AlphaNumericChar, Casing, ColorFormat, LiteralUnion };
export type {
Casing,
ColorFormat,
NumberColorFormat,
StringColorFormat,
} from '../../../src';
export type { LiteralUnion } from '../../../src/internal/types';
export type { AlphaNumericChar } from '../../../src/modules/string';

/**
* Parameter options type with default from signature.
Expand Down

0 comments on commit 7d59cd9

Please sign in to comment.