Enhance no-direct-date
ESLint rule
#9032
Labels
P1
Medium priority
Team S
Issues for Squad 1
Type: Infrastructure
Engineering infrastructure & tooling
Feature Description
In #8483 we introduced a new ESLint rule to avoid the use of
Date
directly, to encourage developers to use the reference date where relevant, but also to use our various date utility functions avoid introducing unexpected behavior related to the quirks of usingDate
directly.In the initial implementation, the rule was made specific to a new
Date
with no arguments, however this misses instances which could be created using our date string formatYYYY-MM-DD
which will be misinterpreted based on the current timezone.eg.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
no-direct-date
rule should be updated to flag all uses ofnew Date
with less than 3 arguments (or if problematic, any number of arguments)new Date( arg [, arg1...] )
(i.e. 1 or more args) should be audited and either:ignoreFiles
configuration in the eslint plugin config for the rule should be moved to the.eslintrc.json
Implementation Brief
Update
packages/eslint-plugin/rules/no-direct-date.js
:new Date( arg [, arg1...] )
, updateNewExpression
callback to report a rule violation if thenode.callee
isDate
and thenode.arguments.length
is> 0
and< 3
.Date( arg [, arg1...] )
, updateCallExpression
callback to report a rule violation if thenode.callee
isDate
and thenode.arguments.length
is> 0
and< 3
.Move the
ignoreFiles
configuration in the eslint plugin to theoverrides
block of the.eslintrc.json
file.Update all new lint errors to use the plugin reference date or ingnore the rule.
Test Coverage
packages/eslint-plugin/rules/no-direct-date.test.js
, adding invalid usages ofnew Date( arg [, arg1...] )
andDate( arg [, arg1...] )
with one or two args and a valid case with three or more arguments.QA Brief
Changelog entry
The text was updated successfully, but these errors were encountered: