Skip to content

Commit

Permalink
Add fixer for no-now
Browse files Browse the repository at this point in the history
See #115
  • Loading branch information
edg2s committed Oct 3, 2019
1 parent c315d71 commit fed4173
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/no-now.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion rules/no-now.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
);
3 changes: 2 additions & 1 deletion tests/no-now.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()'
}
]
} );

0 comments on commit fed4173

Please sign in to comment.