Bare numbers and inline strings in conditions make the reader guess what the rule means. Name them, and let a lint rule catch the ones you miss.
Who it’s for
Game developers especially: gameplay code is full of tuning values like jump
force, cooldowns and damage, and state checks like state === 'attacking'.
It's just as useful anywhere business rules compare against thresholds or
statuses.
The problem
A condition with literal values says what it checks, never why. Take a player who can dash while standing still, once the last dash was long enough ago:
if (player.state === 'idle' && msSinceLastDash >= 800) { dash(player);}To make dashing feel snappier, you first have to work out what 800 is for, and whether the 800 in the enemy code is the same rule.
Why it hurts
- The rule hides in the comparison. You translate it back to its meaning on every read.
- Strings drift. Every inline copy of a value is one more place a typo or rename can miss.
- Same number, different rules. Searching for a bare number finds every unrelated rule that uses it, so tuning one risks breaking another.
The fix
Lint it Recommended
Use the named-values preset from @tstr/linter. It runs in both oxlint and ESLint and flags:
- Numbers other than
0,1and-1. Numeric literal types and type indexes stay legal, likeTuple[2]. - Strings compared with
===, likestate === 'idle'. Comparing with''andtypeof value === 'string'stay legal.
Install the packages:
npm i -D @tstr/linter oxlintAdd the preset to
oxlint.config.ts:import { defineConfig } from 'oxlint';import namedValues from '@tstr/linter/oxlint/named-values'; export default defineConfig({ extends: [namedValues()],});Optional
Allow values that already say what they mean. Each
ignorereplaces its default, so keep the defaults in the list:namedValues({ ignore: [0, 1, -1, 2], 'no-literal-comparison': { ignore: ['', 'Enter', 'Escape'] },});2keepswidth / 2legal for centering, and'Enter'and'Escape'keepevent.key === 'Enter'legal for key checks.Run
npx oxlint, then ask your agent to fix every error.
Otherwise, write it in AGENTS.md
If you live under a rock and don't utilize linters, add one to AGENTS.md:
- Name conditions and compared strings: `const isJumping = player.state === playerStates.jumping`, not `player.state === 'jumping'` inline.- Name every number other than 0, 1 and -1: `const maxHealth = 100`, not a bare `100`.Before & after
export function canDash(player: Player, msSinceLastDash: number) { return player.state === 'idle' && msSinceLastDash >= 800;}| Before | After |
|---|---|
An inline state string | playerStates.idle from shared definitions |
Comparisons inside the return | Booleans name each part of the rule |
800 as the threshold | dashCooldownMs names the tuning value and unit |
Sum up
Lint inline values, or write the rule down. Every condition then reads as what it means, and every value changes in one place you can find by name.




