noctcore-code-quality/no-bare-date-now
Read wall-clock time through a mockable
clockutil, not bareDate.now()/new Date().
Recommended preset: error · Autofix: no · Suggestions: no · Type information: not needed
Business logic that reads Date.now() or new Date() directly is hard to test: every time-dependent
branch depends on the real clock. Routing wall-clock reads through a shared clock util
(nowMs() / now()) gives time-dependent code one seam you can freeze or advance in tests.
What it flags
Section titled “What it flags”Date.now()→ suggestsnowMs().- Zero-argument
new Date()→ suggestsnow().
// bare clock reads in business logicconst start = Date.now();const created = new Date();import { now, nowMs } from './clock';
// through the clock seamconst start = nowMs();const created = now();
// parsing an explicit instantconst at = new Date('2026-01-01T00:00:00Z');What it does not flag
Section titled “What it does not flag”new Date(value)with an argument: that is a parse of an explicit instant, not a bare clock read.- Files covered by
allowIn, which by default is the clock util itself (**/clock.ts,**/clock/**).
Options
Section titled “Options”| Option | Type | Default | Meaning |
|---|---|---|---|
allowIn |
string[] (globs) |
["**/clock.ts", "**/clock/**"] |
File-path globs (infra / the clock util itself) where bare Date is allowed. |
'noctcore-code-quality/no-bare-date-now': ['error', { allowIn: ['**/clock.ts', '**/*.timing.ts'] }]When not to use it
Section titled “When not to use it”If your project has no clock abstraction and does not intend to add one.