site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

Add ESLint rule to warn about direct use of `Date`

Open aaemnnosttv opened this issue 3 months ago • 0 comments

Feature Description

There are several cases where we have needed to have conditional behavior based on time. For short periods of time this is usually fine. However, in cases that involve periods of time of one or more days, we have a core abstraction for called the "reference date" (which is a proxy to the current date). This is usually what we want to use for such things as it is easy for us to override for the purposes of QA and other testing. In an effort to encourage this to be used consistently, we should introduce an ESLint rule to warn about using Date directly.

Example https://github.com/google/site-kit-wp/issues/8248#issuecomment-2038299364


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • A new ESLint rule should be created that warns about usage of new Date() and Date.now().
  • Existing usage of new Date() and Date.now() should be audited and either:
    • Ignored with a comment explaining why they are not using the reference date
    • Updated to use select( CORE_USER ).getReferenceDate() where appropriate

Implementation Brief

  • [ ]

Test Coverage

QA Brief

Changelog entry

aaemnnosttv avatar Apr 04 '24 22:04 aaemnnosttv