tryferos

Search articles

Find an article by its title, description or topic.

A flame marker gives one tick on a temperature dial a recognizable meaning.

Name conditions and numbers

Use named conditions, status values and thresholds to make rules readable where they run.

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, 1 and -1. Numeric literal types and type indexes stay legal, like Tuple[2].
  • Strings compared with ===, like state === 'idle'. Comparing with '' and typeof value === 'string' stay legal.
  1. Install the packages:

    npm i -D @tstr/linter oxlint
  2. Add 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 ignore replaces its default, so keep the defaults in the list:

    namedValues({  ignore: [0, 1, -1, 2],  'no-literal-comparison': { ignore: ['', 'Enter', 'Escape'] },});

    2 keeps width / 2 legal for centering, and 'Enter' and 'Escape' keep event.key === 'Enter' legal for key checks.

  3. 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

player/dash.ts
export function canDash(player: Player, msSinceLastDash: number) {  return player.state === 'idle' && msSinceLastDash >= 800;}
BeforeAfter
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.