From fed41733dbcd42224e6b2054ebdfb903fdd4ac4e Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 3 Oct 2019 01:24:58 +0100 Subject: [PATCH] Add fixer for `no-now` See #115 --- docs/no-now.md | 2 ++ rules/no-now.js | 6 +++++- tests/no-now.js | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/no-now.md b/docs/no-now.md index bf577755..8578ef53 100644 --- a/docs/no-now.md +++ b/docs/no-now.md @@ -4,6 +4,8 @@ Disallows the $.now utility. Prefer (new Date).getTime() to $.now. This rule is enabled in `plugin:no-jquery/deprecated-3.3`. +🔧 The `--fix` option can be used to fix problems reported by this rule. + ## Rule details ❌ The following patterns are considered errors: diff --git a/rules/no-now.js b/rules/no-now.js index f7b6558b..3708bc9e 100644 --- a/rules/no-now.js +++ b/rules/no-now.js @@ -4,5 +4,9 @@ const utils = require( './utils.js' ); module.exports = utils.createUtilMethodRule( 'now', - 'Prefer (new Date).getTime() to $.now' + 'Prefer (new Date).getTime() to $.now', + 'code', + function ( node, fixer ) { + return fixer.replaceText( node.callee, 'Date.now' ); + } ); diff --git a/tests/no-now.js b/tests/no-now.js index 91dff449..aaac0910 100644 --- a/tests/no-now.js +++ b/tests/no-now.js @@ -11,7 +11,8 @@ ruleTester.run( 'no-now', rule, { invalid: [ { code: '$.now()', - errors: [ { message: error, type: 'CallExpression' } ] + errors: [ { message: error, type: 'CallExpression' } ], + output: 'Date.now()' } ] } );