Skip to content

Commit

Permalink
Add fixer for no-size
Browse files Browse the repository at this point in the history
See #115
  • Loading branch information
edg2s committed Oct 12, 2019
1 parent c9e0261 commit 34f196a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion rules/no-size.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.createCollectionMethodRule(
'size',
'Prefer length to $.size'
'Prefer length to $.size',
'code',
function ( node, fixer ) {
return fixer.replaceTextRange( [ node.callee.property.start, node.end ], 'length' );
}
);
12 changes: 8 additions & 4 deletions tests/no-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
}
]
} );

0 comments on commit 34f196a

Please sign in to comment.