Skip to content
Esc

@noctcore/eslint-plugin-dates

v0.1.02 rules0 recommended2 opt-innamespace noctcore-dates

A bad fit for code whose dates are all instants (log stamps, token expiries), and it matches methods by name, without types.

Calendar days read in one zone: local Date accessors, date-only parsing, and hand-rolled day arithmetic kept to one calendar module.

A due date or a leave day is a calendar day, not an instant, and the Date API reads it in whatever zone the machine is in. The same row shows 31 March on a laptop in Warsaw and 30 March on a CI runner in UTC, so the bug passes every test on the machine that wrote it. The fix is one calendar module that answers every day question in the zone the product agreed on; these two rules keep the rest of the code going through it.

It will yell at you about local Date accessors (getDate(), setHours()), new Date('2026-03-31') and toISOString().slice(0, 10), and, in the second rule, hand-rolled day arithmetic (getUTC*, Date.UTC(), setMonth, 24 * 60 * 60 * 1000). Both rules are opt-in: name your calendar module in allowIn so it is the one file that may do this. It is a bad fit for code whose dates are all instants (log stamps, token expiries), and it matches methods by name, without types.

Install
npm install --save-dev @noctcore/eslint-plugin-dates @typescript-eslint/parser
# or: bun add -D / pnpm add -D @noctcore/eslint-plugin-dates @typescript-eslint/parser

The recommended preset turns none of its 2 rules on: each needs options only your project can give, so the preset alone checks nothing. Switch a rule on in the board, then fill in its options as the rule's page shows.

Each rule links to its page, with the options it takes and Incorrect and Correct examples. A good first read is no-local-calendar-time.

0 of 2 at error

--fixsuggestionsneeds optionstype infoEach switch sets a rule to error or off.

calendar-math-via-shared
Disallow hand-rolled calendar arithmetic (getUTC* / setUTC*, Date.UTC(), setMonth, and milliseconds-per-day constants) outside the calendar module listed in allowIn.
opt-in
no-local-calendar-time
Disallow reading a calendar day through the machine's time zone: local Date accessors, new Date('YYYY-MM-DD'), and toISOString().slice(0, 10).
opt-in