Skip to content

Commit

Permalink
Add rule for no-ready-shorthand and include in deprecated-3.0
Browse files Browse the repository at this point in the history
Part of #32 and #52
  • Loading branch information
edg2s committed Jan 21, 2019
1 parent d86ac30 commit 158ea9a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Alternatively, you can pick out rules individually:
"jquery/no-prop": 2,
"jquery/no-proxy": 2,
"jquery/no-ready": 2,
"jquery/no-ready-shorthand": 2,
"jquery/no-global-selector": 2,
"jquery/no-serialize": 2,
"jquery/no-show": 2,
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module.exports = {
'no-prop': require('./rules/no-prop'),
'no-proxy': require('./rules/no-proxy'),
'no-ready': require('./rules/no-ready'),
'no-ready-shorthand': require('./rules/no-ready-shorthand'),
'no-serialize': require('./rules/no-serialize'),
'no-global-selector': require('./rules/no-global-selector'),
'no-show': require('./rules/no-show'),
Expand Down Expand Up @@ -93,6 +94,7 @@ module.exports = {
'jquery/no-undelegate': 2,
// FIXME: `$.fx.interval`
'jquery/no-parse-json': 2,
'jquery/no-ready-shorthand': 2,
'jquery/no-unique': 2
}
},
Expand Down
27 changes: 27 additions & 0 deletions rules/no-ready-shorthand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

const utils = require('./utils.js')

module.exports = {
meta: {
docs: {},
schema: []
},

create: function(context) {
return {
CallExpression: function(node) {
if (node.callee.type !== 'MemberExpression') return
if (node.callee.object.name === '$') return
if (node.callee.property.name !== 'ready') return

if (utils.isjQuery(node)) {
context.report({
node: node,
message: 'Prefer $ to $.ready'
})
}
}
}
}
}
37 changes: 37 additions & 0 deletions tests/no-ready-shorthand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict'

const rule = require('../rules/no-ready-shorthand')
const RuleTester = require('eslint').RuleTester

const error = 'Prefer $ to $.ready'

const ruleTester = new RuleTester()
ruleTester.run('no-ready-shorthand', rule, {
valid: [
'ready()',
'[].ready()',
'div.ready()',
'div.ready',
'$.ready()',
'$(document).on("ready", function(){})',
'$(function(){})'
],
invalid: [
{
code: '$(document).ready()',
errors: [{message: error, type: 'CallExpression'}]
},
{
code: '$div.ready()',
errors: [{message: error, type: 'CallExpression'}]
},
{
code: '$("div").first().ready()',
errors: [{message: error, type: 'CallExpression'}]
},
{
code: '$("div").append($("input").ready())',
errors: [{message: error, type: 'CallExpression'}]
}
]
})

0 comments on commit 158ea9a

Please sign in to comment.