Skip to content

Cross-language parity

The same logic, written in either language, gets the same score:

// backend/Orders.php
foreach ($orders as $order) { // +1
if ($order->isActive()) { // +2
array_map(function ($item) { // +0, nesting 3
if ($item->qty > 0) { // +4
return $item->qty > 10 ? 'bulk' : 'single'; // +5
// frontend/orders.ts
for (const order of orders) { // +1
if (order.isActive()) { // +2
order.items().map((item) => { // +0, nesting 3
if (item.qty > 0) { // +4
return item.qty > 10 ? 'bulk' : 'single' // +5
12 backend/Orders.php:3 OrderRepository::syncLineItems
12 frontend/orders.ts:1 syncLineItems

That is what makes one threshold meaningful across a monorepo: a limit of 15 means the same thing to the team writing PHP and the team writing TypeScript.

There is only one implementation of the scoring rules. The scorer walks a parsed tree and has no idea which language it is looking at. A language contributes a specification: a plain value naming which node kinds count as a branch, a loop or a closure. It contributes no scoring code of its own.

So the languages cannot drift apart by accident, because there is nothing to drift: adding PHP did not add a PHP scorer.

Parity is covered by tests that run on every commit. One compares PHP against JavaScript end to end through the binary; another compares a Vue script block against the equivalent TypeScript file. They pin the exact scores, not merely that the two agree, so a change that shifted both languages together would still fail.

It is about scores, not syntax. Constructs that exist in one language and not the other are covered by the scoring rules, and a few are deliberate divergences from the reference JavaScript analyser. Parity says that logic expressible in both gets the same number, not that every language has every construct.