Skip to content

feat(locale): add hyphenated names to English locales#1872

Merged
ST-DDT merged 10 commits into
faker-js:nextfrom
matthewmayer:locale/more-hyphenated-names
Mar 27, 2023
Merged

feat(locale): add hyphenated names to English locales#1872
ST-DDT merged 10 commits into
faker-js:nextfrom
matthewmayer:locale/more-hyphenated-names

Conversation

@matthewmayer

@matthewmayer matthewmayer commented Feb 24, 2023

Copy link
Copy Markdown
Contributor

fix #691

  • default en locale gets 95% non-hyphenated 5% hyphenated
  • other locales without existing last_name_patterns get 100% non-hyphenated
  • locales with split male_last_name and female_last_names get split patterns
  • existing locales with last_name_patterns (e.g. lv, en_GB) are not changed.

If additional information about hyphenation rules in other locales can be found, this can be added in a subsequent PR. I kept this one formulaic to make it easy to review.

- default en locale gets 95% non-hyphenated 5% hyphenated
- other locales without existing last_name_patterns get 100% non-hyphenated
- locales with split male_last_name and  female_last_names get split patterns
- existing locales with last_name_patterns (e.g. lv, en_GB) are not changed.
@matthewmayer
matthewmayer requested a review from a team as a code owner February 24, 2023 08:40
@matthewmayer matthewmayer changed the title locale: more hyphenated names feat (locale): more hyphenated names Feb 24, 2023
@matthewmayer matthewmayer changed the title feat (locale): more hyphenated names feat(locale): more hyphenated names Feb 24, 2023
@codecov

codecov Bot commented Feb 24, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1872 (620d6cc) into next (8a4ca4e) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head 620d6cc differs from pull request most recent head 74631cc. Consider uploading reports for the commit 74631cc to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #1872      +/-   ##
==========================================
- Coverage   99.64%   99.62%   -0.02%     
==========================================
  Files        2384     2450      +66     
  Lines      238992   239274     +282     
  Branches     1231     1228       -3     
==========================================
+ Hits       238132   238387     +255     
- Misses        838      865      +27     
  Partials       22       22              
Impacted Files Coverage Δ
src/locales/af_ZA/person/index.ts 100.00% <100.00%> (ø)
src/locales/af_ZA/person/last_name_patterns.ts 100.00% <100.00%> (ø)
src/locales/ar/person/index.ts 100.00% <100.00%> (ø)
src/locales/ar/person/last_name_patterns.ts 100.00% <100.00%> (ø)
src/locales/az/person/female_last_name_patterns.ts 100.00% <100.00%> (ø)
src/locales/az/person/index.ts 100.00% <100.00%> (ø)
src/locales/az/person/male_last_name_patterns.ts 100.00% <100.00%> (ø)
src/locales/cz/person/female_last_name_patterns.ts 100.00% <100.00%> (ø)
src/locales/cz/person/index.ts 100.00% <100.00%> (ø)
src/locales/cz/person/male_last_name_patterns.ts 100.00% <100.00%> (ø)
... and 108 more

... and 3 files with indirect coverage changes

@matthewmayer

Copy link
Copy Markdown
Contributor Author

this exposed a bug in the test for commitEntry, the local part of the email addresses was not allowing hyphens. i changed the regex to match the one we use in the emailAddress method https://github.com/faker-js/faker/blob/add2254ca31434af3003c0051064bdb27713992d/src/modules/internet/index.ts

@matthewmayer matthewmayer changed the title feat(locale): more hyphenated names feat(locale): add hyphenated names to English locales Feb 24, 2023
@Shinigami92

Copy link
Copy Markdown
Member

this exposed a bug in the test for commitEntry, the local part of the email addresses was not allowing hyphens. i changed the regex to match the one we use in the emailAddress method add2254/src/modules/internet/index.ts

Please lets extract this to its own PR, so

  1. it is reviewable in parallel to this PR
  2. it gets its own "fix/test" changelog entry
@matthewmayer

Copy link
Copy Markdown
Contributor Author

I considered that, but the test doesn't fail on the next branch because email addresses in en never contain hyphens.

@Shinigami92

Copy link
Copy Markdown
Member

I considered that, but the test doesn't fail on the next branch because email addresses in en never contain hyphens.

You are free to add static tests that handles special cases in the random seeded test cases (second part of each test file)

Maybe we need to change something here instead of the test

user = user.replace(/^[\.,:;"\\']|[\<\>\n]|[\.,:;"\\']$/g, '');

We are already starting to pollute this PR with unrelated discussions, please lets stop this and extract it so we can have dedicated discussions

@Shinigami92 Shinigami92 added the s: pending triage Pending Triage label Feb 24, 2023
@matthewmayer

Copy link
Copy Markdown
Contributor Author

I considered that, but the test doesn't fail on the next branch because email addresses in en never contain hyphens.

You are free to add static tests that handles special cases in the random seeded test cases (second part of each test file)

Maybe we need to change something here instead of the test

user = user.replace(/^[\.,:;"\\']|[\<\>\n]|[\.,:;"\\']$/g, '');

We are already starting to pollute this PR with unrelated discussions, please lets stop this and extract it so we can have dedicated discussions

#1876

@ST-DDT ST-DDT added p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug c: locale Permutes locale definitions m: person Something is referring to the person module and removed s: pending triage Pending Triage labels Feb 24, 2023

@ST-DDT ST-DDT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are now somewhat mandatory:

if (
last_name_patterns != null ||
male_last_name_patterns != null ||
female_last_name_patterns != null
) {
const pattern = selectDefinition(
this.faker,
this.faker.helpers.weightedArrayElement,
sex,
{
generic: last_name_patterns,
female: female_last_name_patterns,
male: male_last_name_patterns,
}
);
return this.faker.helpers.fake(pattern);

So IMO the other code branch could be removed.
Also the PR does more than the PR title suggests IMO.

Not sure whether it is worth splitting into two PRs:

  1. Make last_name_patterns required/Generate last_name_patterns for all locales
  2. add hyphenated names to English locales
Comment thread src/locales/lv/person/female_last_name_patterns.ts
Comment thread src/locales/lv/person/male_last_name_patterns.ts
@matthewmayer

Copy link
Copy Markdown
Contributor Author

It's not mandatory if you create a new locale which doesn't extend en.

@ST-DDT ST-DDT added the needs rebase There is a merge conflict label Mar 23, 2023
@ST-DDT

ST-DDT commented Mar 23, 2023

Copy link
Copy Markdown
Member

Please fix the merge conflicts.

# Conflicts:
#	src/locales/zh_TW/person/index.ts
@ST-DDT ST-DDT removed the needs rebase There is a merge conflict label Mar 23, 2023
@ST-DDT

ST-DDT commented Mar 23, 2023

Copy link
Copy Markdown
Member

Please adjust the PR title to reflect the current. It also changes non English locales.

@matthewmayer

Copy link
Copy Markdown
Contributor Author

Please adjust the PR title to reflect the current. It also changes non English locales.

it doesn't add any hyphenated patterns to any non-English locales, the changes are to prevent hyphenated patterns from propagating to the other non-English locales unexpectedly.

@ST-DDT
ST-DDT requested review from a team March 23, 2023 17:11
@matthewmayer

Copy link
Copy Markdown
Contributor Author

could append ", add last_name_patterns to all locales" maybe? but makes it a bit long

@ST-DDT
ST-DDT enabled auto-merge (squash) March 27, 2023 11:05
@ST-DDT
ST-DDT merged commit 17f0488 into faker-js:next Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: locale Permutes locale definitions m: person Something is referring to the person module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug

3 participants