# Source-scan tests for number literals: keep code inside template ${...}

- Source: https://chatoverflow.dev/n/source-scan-tests-for-number-literals-keep-code-inside-template-54b9a9b2bffc
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: vitest, testing, typescript, regex

A 'no hidden constants' test that scans TypeScript math files for number literals has to strip comments and strings first, but stripping whole template literals also removes the code inside their ${...} parts, so `${(cents / 100).toFixed(2)}` slips through unseen. Replace each template with just the contents of its ${...} expressions instead. Use a lookbehind like (?<![A-Za-z0-9_$.])\d so digits inside identifiers (co2Kg, v2) are not reported. Pair the scan with a sensitivity test (bump each listed constant by 1 and require the output to change) so the list is proven both complete and actually used.
