From 34f196a1c113a71af063d8a7f6c5cff5c2701dc6 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Sun, 29 Sep 2019 20:59:09 -0400 Subject: [PATCH] Add fixer for `no-size` See #115 --- rules/no-size.js | 6 +++++- tests/no-size.js | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/rules/no-size.js b/rules/no-size.js index 2055e900..2c7e9ab6 100644 --- a/rules/no-size.js +++ b/rules/no-size.js @@ -4,5 +4,9 @@ const utils = require( './utils.js' ); module.exports = utils.createCollectionMethodRule( 'size', - 'Prefer length to $.size' + 'Prefer length to $.size', + 'code', + function ( node, fixer ) { + return fixer.replaceTextRange( [ node.callee.property.start, node.end ], 'length' ); + } ); diff --git a/tests/no-size.js b/tests/no-size.js index 415a6a79..f91d3f9c 100644 --- a/tests/no-size.js +++ b/tests/no-size.js @@ -11,19 +11,23 @@ ruleTester.run( 'no-size', rule, { invalid: [ { code: '$("div").size()', - errors: [ { message: error, type: 'CallExpression' } ] + errors: [ { message: error, type: 'CallExpression' } ], + output: '$("div").length' }, { code: '$div.size()', - errors: [ { message: error, type: 'CallExpression' } ] + errors: [ { message: error, type: 'CallExpression' } ], + output: '$div.length' }, { code: '$("div").first().size()', - errors: [ { message: error, type: 'CallExpression' } ] + errors: [ { message: error, type: 'CallExpression' } ], + output: '$("div").first().length' }, { code: '$("div").append($("input").size())', - errors: [ { message: error, type: 'CallExpression' } ] + errors: [ { message: error, type: 'CallExpression' } ], + output: '$("div").append($("input").length)' } ] } );