From 5a8730afe4f43feb17688efdba106b97a1851874 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:38:51 +0200 Subject: [PATCH 1/2] chore(config): migrate renovate config (#3040) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Shinigami92 --- .github/renovate.json5 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 3ec71838c27..664a023e6b2 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -35,16 +35,17 @@ }, { "groupName": "eslint", - "matchPackagePrefixes": [ - "@eslint-types/", - "@eslint/", + "matchPackageNames": [ + "@eslint-types/**", + "@eslint/**", "eslint", + "eslint-**", "typescript-eslint" ] }, { "groupName": "vitest", - "matchPackagePrefixes": ["@vitest/", "vitest"] + "matchPackageNames": ["@vitest/**", "vitest"] }, { "groupName": "prettier", From 1e9d65bce14cb446388a61e2c9a74c5f898a985e Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Thu, 15 Aug 2024 00:43:30 +0200 Subject: [PATCH 2/2] docs(guide): add locale error handling sections (#3055) --- docs/guide/localization.md | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/docs/guide/localization.md b/docs/guide/localization.md index fe7c60a4291..f40a2f48a03 100644 --- a/docs/guide/localization.md +++ b/docs/guide/localization.md @@ -165,3 +165,85 @@ for (let key of Object.keys(allFakers)) { } } ``` + +## Handling Missing Data Errors + +```txt +[Error]: The locale data for 'category.entry' are missing in this locale. +Please contribute the missing data to the project or use a locale/Faker instance that has these data. +For more information see https://fakerjs.dev/guide/localization.html +``` + +If you receive this error, this means you are using a locale (`Faker` instance) that does not have the relevant data for that method yet. +Please consider contributing the missing data, so that others can use them in the future as well. + +As a workaround, you can provide additional fallbacks to your `Faker` instance: + +```ts +import { Faker, el } from '@faker-js/faker'; // [!code --] +import { Faker, el, en } from '@faker-js/faker'; // [!code ++] + +const faker = new Faker({ + locale: [el], // [!code --] + locale: [el, en], // [!code ++] +}); +console.log(faker.location.country()); // 'Belgium' +``` + +::: tip Note +Of course, you can use [Custom Locales and Fallbacks](#custom-locales-and-fallbacks) for this as well. +::: + +## Handling Not-Applicable Data Errors + +```txt +[Error]: The locale data for 'category.entry' aren't applicable to this locale. +If you think this is a bug, please report it at: https://github.com/faker-js/faker +``` + +If you receive this error, this means the current locale is unable to provide reasonable values for that method. +For example, there are no zip codes in Hongkong, so for that reason the `en_HK` locale is unable to provide these data. +The same applies to other locales and methods. + +```ts +import { fakerEN_HK } from '@faker-js/faker'; + +console.log(fakerEN_HK.location.zipCode()); // Error // [!code error] +``` + +For these cases, we explicitly set the data to `null` to clarify, that we have thought about it, but there are no valid values to put there. +We could have used an empty array `[]`, but some locale data are stored as objects `{}`, +so `null` works for both of them without custom downstream handling of missing data. + +::: tip Note +We are by far no experts in all provided languages/countries/locales, +so if you think this is an error for your locale, please create an issue and consider contributing the relevant data. +::: + +If you want to use other fallback data instead, you can define them like this: + +```ts{4} +import { Faker, en, en_HK } from '@faker-js/faker'; + +const faker = new Faker({ + locale: [{ location: { postcode: en.location.postcode } }, en_HK], +}); +console.log(faker.location.zipCode()); // '17551-0348' +``` + +::: warning Warning +Since `null` is considered present data, it will not use any fallbacks for that. +So the following code does **not** work: + +```ts +import { Faker, en, en_HK } from '@faker-js/faker'; + +const faker = new Faker({ + locale: [en_HK, { location: { postcode: en.location.postcode } }], // [!code warning] +}); +console.log(faker.location.zipCode()); // Error // [!code error] +``` + +::: + +See also: [Custom Locales and Fallbacks](#custom-locales-and-fallbacks)