This rule raises an issue when new Date() is called with date.getTime() as an argument instead of passing the Date object
directly.
The JavaScript Date constructor can accept another Date object directly as an argument to create a clone. When you pass
date.getTime() to new Date(), you are unnecessarily converting the date to a timestamp first, then back to a Date
object.
This approach has several drawbacks:
The direct approach new Date(date) is cleaner, more efficient, and clearly expresses the intent to create a copy of an existing
date.
This issue primarily affects code readability and maintainability. While the performance impact is minimal, using the direct cloning approach makes the code more idiomatic and easier to understand for other developers.
Pass the Date object directly to the Date constructor instead of calling getTime() first.
const originalDate = new Date(); const clonedDate = new Date(originalDate.getTime()); // Noncompliant
const originalDate = new Date(); const clonedDate = new Date(originalDate);