Skip to content

test: add unit tests for IdGenerator#20775

Merged
DMartens merged 4 commits into
eslint:mainfrom
Kuldeep2822k:test-id-generator
Apr 19, 2026
Merged

test: add unit tests for IdGenerator#20775
DMartens merged 4 commits into
eslint:mainfrom
Kuldeep2822k:test-id-generator

Conversation

@Kuldeep2822k
Copy link
Copy Markdown
Contributor

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[X] Other, please explain: Add unit tests for IdGenerator

What changes did you make? (Give an overview)

This PR introduces unit tests for the IdGenerator class located at lib/linter/code-path-analysis/id-generator.js, which was previously lacking direct test coverage.

Specifically, it tests:

  • Constructor initialization behavior (working with standard string prefixes, omitting a prefix, or casting non-string prefixes to string).
  • The next() function for sequentially tracking identifier suffix generation.
  • Empty string prefix generation generation.
  • Safe 32-bit integer overflow logic mapping the internal counter safely back to 1.

Is there anything you'd like reviewers to focus on?

The tests ensure the correct wrap-around when encountering 2147483647 (the max 32-bit integer), allowing us to safely maintain overflow testing logic.

(Note: we originally attempted to remove the c8 ignore pragmas in IdGenerator, but the source edits were pulled from this scope to strictly contribute testing logic).

@Kuldeep2822k Kuldeep2822k requested a review from a team as a code owner April 19, 2026 09:02
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Apr 19, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 19, 2026

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 9385064
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/69e5336f52a677000873b39a

@eslint-github-bot eslint-github-bot Bot added the chore This change is not user-facing label Apr 19, 2026
});

it("should cast prefix to string", () => {
const generator1 = new IdGenerator(123);
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.

Can you please remove the number prefix here and the next test case (generator1 -> generator) as there is only a single generator per test case.


it("should wrap around to 1 when the counter overflows", () => {
const generator = new IdGenerator("s");
generator.n = 2147483647;
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.

This test case would be easier to follow when the number is assigned to a variable and calculated: const INT32_MAX = (2 ** 31) - 1

Comment thread tests/lib/linter/code-path-analysis/id-generator.js
@github-actions github-actions Bot added the core Relates to ESLint's core APIs and features label Apr 19, 2026
@DMartens
Copy link
Copy Markdown
Contributor

Changes LGTM, thanks.

@DMartens DMartens merged commit 2b252be into eslint:main Apr 19, 2026
39 of 40 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Triage to Complete in Triage Apr 19, 2026
@Kuldeep2822k Kuldeep2822k deleted the test-id-generator branch April 29, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore This change is not user-facing core Relates to ESLint's core APIs and features

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

2 participants