Skip to content

fix(vehicle): calculate VIN check digit - #3954

Open
tianrking wants to merge 4 commits into
faker-js:nextfrom
tianrking:agent/vin-check-digit
Open

fix(vehicle): calculate VIN check digit#3954
tianrking wants to merge 4 commits into
faker-js:nextfrom
tianrking:agent/vin-check-digit

Conversation

@tianrking

Copy link
Copy Markdown

Summary

  • calculate the ISO 3779 check digit for generated Vehicle Identification Numbers (VINs)
  • preserve the existing random draws and replace only position 9 in the completed VIN
  • add checksum coverage for generated VINs, the X modulo-11 case, and update the affected seeded snapshots

Root cause

vehicle.vin() generated the ninth character as an unconstrained alphanumeric value. That position is the VIN check digit in the North American VIN standard, so generated values commonly failed validation or contained an invalid letter there.

The calculation uses the standard transliteration table and positional weights. Its zero weight for position 9 means the existing generated VIN can be used as input, preserving the random sequence while replacing only the check digit.

Fixes #3952.

Validation

  • corepack pnpm@10.34.4 run build
  • corepack pnpm@10.34.4 exec vitest run test/modules/vehicle.spec.ts
  • corepack pnpm@10.34.4 exec eslint src/modules/vehicle/module.ts test/modules/vehicle.spec.ts
  • corepack pnpm@10.34.4 exec prettier --check src/modules/vehicle/module.ts test/modules/vehicle.spec.ts
  • corepack pnpm@10.34.4 run ts-check
  • corepack pnpm@10.34.4 run test (54,317 passing; one existing docs-version-links failure in test/docs/versions.spec.ts, unrelated to this change)
  • git diff --check

@tianrking
tianrking requested a review from a team as a code owner July 16, 2026 18:38
@netlify

netlify Bot commented Jul 16, 2026

Copy link
Copy Markdown

Deploy Preview for fakerjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit cf94509
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/6a661f6164a90100087d5577
😎 Deploy Preview https://deploy-preview-3954.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.

Comment thread src/modules/vehicle/module.ts
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #3954   +/-   ##
=======================================
  Coverage   98.91%   98.91%           
=======================================
  Files         924      924           
  Lines        3224     3233    +9     
  Branches      585      569   -16     
=======================================
+ Hits         3189     3198    +9     
  Misses         31       31           
  Partials        4        4           
Files with missing lines Coverage Δ
src/modules/vehicle/module.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 test/modules/vehicle.spec.ts Outdated
Comment thread test/modules/vehicle.spec.ts Outdated
@ST-DDT
ST-DDT requested a review from Copilot July 17, 2026 06:58
@ST-DDT ST-DDT added c: bug Something isn't working p: 1-normal Nothing urgent s: pending triage Pending Triage m: vehicle Something is referring to the vehicle module labels Jul 17, 2026
@ST-DDT ST-DDT added this to the v10.x milestone Jul 17, 2026

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 pull request fixes vehicle.vin() to generate ISO 3779 / North American–compliant VINs by computing and inserting the proper check digit at position 9, while keeping the existing random generation sequence intact (only the completed VIN’s 9th character is replaced).

Changes:

  • Add VIN transliteration + weight tables and a local vinCheckDigit() helper to compute the ISO 3779 modulo-11 check digit (with 10 -> 'X').
  • Update VehicleModule.vin() to splice the computed check digit into position 9 of the already-generated VIN.
  • Add test coverage validating the check digit (including the 'X' case) and update affected seeded snapshots.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/modules/vehicle/module.ts Computes and inserts the VIN check digit into position 9 without changing RNG draw count.
test/modules/vehicle.spec.ts Adds a check-digit validator and asserts generated VINs have a correct position-9 check digit.
test/modules/__snapshots__/vehicle.spec.ts.snap Updates seeded VIN snapshots to reflect the corrected check digit.

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

@ST-DDT ST-DDT removed the s: pending triage Pending Triage label Jul 26, 2026
@ST-DDT
ST-DDT requested a review from Copilot July 26, 2026 16:59

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

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

Comment thread src/modules/vehicle/module.ts
Comment thread src/modules/vehicle/module.ts

// NHTSA 49 CFR § 565.15(c), Tables III and IV define the transliteration
// values and position weights used here:
// https://www.govinfo.gov/content/pkg/CFR-2025-title49-vol6/pdf/CFR-2025-title49-vol6-sec565-15.pdf

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.

I might be stupid, but this link does not lead to any valid PDF for me 🤷‍♀️

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

Labels

c: bug Something isn't working m: vehicle Something is referring to the vehicle module p: 1-normal Nothing urgent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

faker.vehicle.vin(): position 9 is random, so generated VINs fail check-digit validation

6 participants