Skip to content

refactor: extract shared LengthStrategy type - #3940

Open
Shinigami92 wants to merge 7 commits into
nextfrom
refactor-extract-length-strategy-type
Open

refactor: extract shared LengthStrategy type#3940
Shinigami92 wants to merge 7 commits into
nextfrom
refactor-extract-length-strategy-type

Conversation

@Shinigami92

@Shinigami92 Shinigami92 commented Jul 6, 2026

Copy link
Copy Markdown
Member

@Shinigami92 Shinigami92 self-assigned this Jul 6, 2026
@Shinigami92
Shinigami92 requested a review from a team as a code owner July 6, 2026 16:52
@Shinigami92 Shinigami92 added the c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs label Jul 6, 2026
@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for fakerjs ready!

Name Link
🔨 Latest commit 9330894
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/6a6a433a9b1ae400081c90ee
😎 Deploy Preview https://deploy-preview-3940.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.91%. Comparing base (e59f499) to head (9330894).

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #3940   +/-   ##
=======================================
  Coverage   98.91%   98.91%           
=======================================
  Files         924      925    +1     
  Lines        3224     3230    +6     
  Branches      567      567           
=======================================
+ Hits         3189     3195    +6     
  Misses         31       31           
  Partials        4        4           
Files with missing lines Coverage Δ
src/modules/lorem/module.ts 100.00% <ø> (ø)
src/modules/word/filter-word-list-by-length.ts 100.00% <ø> (ø)
src/modules/word/module.ts 96.00% <ø> (ø)
src/utils/types.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/utils/types.ts Outdated
@ST-DDT ST-DDT added this to the v10.x milestone Jul 6, 2026
@ST-DDT ST-DDT added p: 1-normal Nothing urgent m: utils Something related to public utils (methods/types) labels Jul 6, 2026
@Shinigami92

Shinigami92 commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

I will add the docs here when #3939 got merged, to not fall into to many merge conflicts

@ST-DDT

ST-DDT commented Jul 6, 2026

Copy link
Copy Markdown
Member

I will add the docs here when #3939 got merged, to not fall into to many merge conflicts

I have added a preview link for ease of verifcation.
AFAICT this PR does not need a docs upgrade, since the union type is already covered.

ST-DDT
ST-DDT previously approved these changes Jul 6, 2026
@Shinigami92
Shinigami92 force-pushed the refactor-extract-length-strategy-type branch from e802502 to f476ad6 Compare July 9, 2026 14:15

@xDivisionByZerox xDivisionByZerox 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.

We would loose the information describing each strategy itself with this PR:

Before After

@Shinigami92

Copy link
Copy Markdown
Member Author

We would loose the information describing each strategy itself with this PR:

Before After

That is a blocker for me 🙁
I can throw Claude on this again in next few days

@Shinigami92
Shinigami92 marked this pull request as draft July 10, 2026 18:09
@ST-DDT

ST-DDT commented Jul 10, 2026

Copy link
Copy Markdown
Member

Should we add a Types page?

@Shinigami92

Copy link
Copy Markdown
Member Author

Should we add a Types page?

If so, it needs clickable links from the method docs. But then you might loose the context / back history and get lost. How about hover tooltips? But these might introduce problems with mobile device docs. 🤔 Do you have further ideas?

@ST-DDT

ST-DDT commented Jul 10, 2026

Copy link
Copy Markdown
Member

Use the shadow type system and add the description as hoverable text.
Aka use the detected types to do actual work.

@Shinigami92
Shinigami92 force-pushed the refactor-extract-length-strategy-type branch 2 times, most recently from 6640166 to 3cbd7c7 Compare July 17, 2026 07:31
@Shinigami92
Shinigami92 marked this pull request as ready for review July 17, 2026 08:33
@Shinigami92

Copy link
Copy Markdown
Member Author
image

popover works on desktop and mobile (the popover api is stable since 2024)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes the “length mismatch handling” strategy into a shared LengthStrategy/LengthStrategyType in src/utils/types.ts, updates Lorem/Word APIs to use the shared type, and enhances the API docs generator/UI to preserve per-union-member documentation via “shadow type” popovers.

Changes:

  • Introduces LengthStrategy + LengthStrategyType in src/utils/types.ts and re-exports them from src/index.ts.
  • Updates word/lorem modules (and filterWordListByLength) to use LengthStrategyType instead of repeating the string-literal union.
  • Extends API docs processing/output to extract enum-member JSDoc for template-literal “shadow types” and render per-value descriptions as popovers (with snapshot/test coverage).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/scripts/apidocs/method.example.ts Adds a shadow-type test fixture (enum + template-literal alias + method).
test/scripts/apidocs/snapshots/method.spec.ts.snap Updates snapshots to include the new method/type rendering expectations.
src/utils/types.ts Adds shared LengthStrategy enum and LengthStrategyType alias.
src/modules/word/module.ts Replaces repeated strategy unions with LengthStrategyType across Word APIs.
src/modules/word/filter-word-list-by-length.ts Uses LengthStrategyType for the strategy option.
src/modules/lorem/module.ts Uses LengthStrategyType for the strategy option.
src/index.ts Re-exports LengthStrategy and LengthStrategyType.
scripts/apidocs/processing/type.ts Adds shadow-type description extraction + attachment to type members.
scripts/apidocs/processing/parameter.ts Enriches parameter types with per-value descriptions based on syntactic type nodes.
scripts/apidocs/output/page.ts Renders parameter types as HTML (with popover triggers for described members).
docs/.vitepress/components/api-docs/method.ts Clarifies type is HTML.
docs/.vitepress/components/api-docs/method-parameters.vue Switches type column to v-html and adds popover styling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/.vitepress/components/api-docs/method-parameters.vue Outdated
Comment thread scripts/apidocs/output/page.ts
Comment thread docs/.vitepress/components/api-docs/method-parameters.vue Outdated
Comment thread docs/.vitepress/components/api-docs/method-parameters.vue Outdated
Comment thread scripts/apidocs/output/page.ts Outdated
Comment thread scripts/apidocs/processing/type.ts
Comment thread scripts/apidocs/processing/type.ts
Comment thread docs/.vitepress/components/api-docs/method-parameters.vue Outdated
Comment thread docs/.vitepress/components/api-docs/method-parameters.vue
@Shinigami92
Shinigami92 requested a review from ST-DDT July 18, 2026 09:05

@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.

This is a good addition. I'm not sure about the font-family and how the descriptions gets added to the types, but the rest looks good to me.

During review I noticed, that this applies to LengthStrategy and SexType, but not ColorFormats. Which made me think what would be better and consistent UX.
Keep the named type, then show the values+descriptions on hover/popover or explode the enum/union types (as is).

Image

Comment thread scripts/apidocs/processing/type.ts Outdated
Comment thread scripts/apidocs/processing/type.ts
Comment thread docs/.vitepress/components/api-docs/method-parameters.vue
@Shinigami92
Shinigami92 requested a review from ST-DDT July 18, 2026 10:11
ST-DDT
ST-DDT previously approved these changes Jul 18, 2026

@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.

Since the remaining things will be handled in a separate PR, I approve this.

  • Discussion: Do we show the enum type values directly or do we show an popover with more details. aka do we give the user a hint that the wrapper type + actual enum exist or should they read that from the signature?
  • Inline: Read the enum value description at type creation time, instead of retroactively attaching it.

@Shinigami92
Shinigami92 force-pushed the refactor-extract-length-strategy-type branch from 25981a0 to 1a5d489 Compare July 20, 2026 16:13
@ST-DDT

ST-DDT commented Jul 26, 2026

Copy link
Copy Markdown
Member

There appears to be merge conflicts.

@ST-DDT ST-DDT added the needs rebase There is a merge conflict label Jul 26, 2026
@Shinigami92
Shinigami92 force-pushed the refactor-extract-length-strategy-type branch from 1a5d489 to 8047b4b Compare July 29, 2026 18:13
@Shinigami92
Shinigami92 force-pushed the refactor-extract-length-strategy-type branch from 8047b4b to 9330894 Compare July 29, 2026 18:15
@Shinigami92 Shinigami92 removed the needs rebase There is a merge conflict label Jul 29, 2026
@Shinigami92
Shinigami92 requested a review from ST-DDT July 29, 2026 18:17
ST-DDT

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs m: utils Something related to public utils (methods/types) p: 1-normal Nothing urgent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants