prefer-date-now
UnreleasedConfiguration
Rule Details
Prefer Date.now() when reading the current timestamp. This avoids creating
a Date object only to convert it into the number of milliseconds since the
Unix Epoch.
This rule is enabled in the Unicorn recommended preset.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
The rule also checks unary minus, BigInt(new Date()), and the numeric
operators -, *, /, %, and **, including their assignment forms.
Automatic fixes preserve the surrounding conversion or arithmetic operation.
Only argument-free new Date() expressions are checked. Date construction
with arguments, optional method calls, computed method names, addition, and
bitwise operations are left unchanged. The rule is syntax-based: a locally
declared constructor named Date is treated the same as the built-in.
Options
This rule has no options.