コンテンツにスキップ

useDateNow (since v1.8.0)

このコンテンツはまだ日本語訳がありません。

Diagnostic Category: lint/nursery/useDateNow

Sources:

Use Date.now() to get the number of milliseconds since the Unix Epoch.

Date.now() is more readable than new Date().getTime() and its variants, it also avoids unnecessary instantiation of Date object.

const foo = new Date().getTime();
code-block.js:1:13 lint/nursery/useDateNow  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Use Date.now() instead of new Date().getTime.
  
  > 1 │ const foo = new Date().getTime();
               ^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Date.now() is more readable and also avoids unnecessary instantiation of Dateobject.
  
   Unsafe fix: Replace with Date.now().
  
    1  - const·foo·=·new·Date().getTime();
      1+ const·foo·=·Date.now();
    2 2  
  
const foo = new Date().valueOf();
code-block.js:1:13 lint/nursery/useDateNow  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Use Date.now() instead of new Date().valueOf.
  
  > 1 │ const foo = new Date().valueOf();
               ^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Date.now() is more readable and also avoids unnecessary instantiation of Dateobject.
  
   Unsafe fix: Replace with Date.now().
  
    1  - const·foo·=·new·Date().valueOf();
      1+ const·foo·=·Date.now();
    2 2  
  
const foo = +new Date();
code-block.js:1:13 lint/nursery/useDateNow  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Use Date.now() instead of new Date().
  
  > 1 │ const foo = +new Date();
               ^^^^^^^^^^^
    2 │ 
  
   Date.now() is more readable and also avoids unnecessary instantiation of Dateobject.
  
   Unsafe fix: Replace with Date.now().
  
    1  - const·foo·=·+new·Date();
      1+ const·foo·=·Date.now();
    2 2  
  
const foo = Number(new Date());
code-block.js:1:13 lint/nursery/useDateNow  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Use Date.now() instead of Number(new Date()).
  
  > 1 │ const foo = Number(new Date());
               ^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Date.now() is more readable and also avoids unnecessary instantiation of Dateobject.
  
   Unsafe fix: Replace with Date.now().
  
    1  - const·foo·=·Number(new·Date());
      1+ const·foo·=·Date.now();
    2 2  
  
const foo = new Date() * 2;
code-block.js:1:13 lint/nursery/useDateNow  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Use Date.now() instead of new Date().
  
  > 1 │ const foo = new Date() * 2;
               ^^^^^^^^^^
    2 │ 
  
   Date.now() is more readable and also avoids unnecessary instantiation of Dateobject.
  
   Unsafe fix: Replace with Date.now().
  
    1  - const·foo·=·new·Date()·*·2;
      1+ const·foo·=·Date.now()*·2;
    2 2  
  
const foo = Date.now();
const foo = Date.now() * 2;