Skip to content

Commit

Permalink
Add no-on-ready rule and add to deprecated 1.8
Browse files Browse the repository at this point in the history
Part of #32
  • Loading branch information
edg2s committed Jan 24, 2019
1 parent 058487a commit c57d22f
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 @@ -89,6 +89,7 @@ Alternatively, you can pick out rules individually:
"jquery/no-merge": 2,
"jquery/no-noop": 2,
"jquery/no-now": 2,
"jquery/no-on-ready": 2,
"jquery/no-param": 2,
"jquery/no-parent": 2,
"jquery/no-parents": 2,
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module.exports = {
'no-merge': require('./rules/no-merge'),
'no-noop': require('./rules/no-noop'),
'no-now': require('./rules/no-now'),
'no-on-ready': require('./rules/no-on-ready'),
'no-param': require('./rules/no-param'),
'no-parent': require('./rules/no-parent'),
'no-parents': require('./rules/no-parents'),
Expand Down Expand Up @@ -131,6 +132,7 @@ module.exports = {
// FIXME: `deferred.pipe()`
'jquery/no-error-shorthand': 2,
'jquery/no-load-shorthand': 2,
'jquery/no-on-ready': 2,
'jquery/no-size': 2,
// FIXME: `$(...).toggle(fn,fn) (excluding https://api.jquery.com/toggle/)
'jquery/no-unload-shorthand': 2
Expand Down
28 changes: 28 additions & 0 deletions rules/no-on-ready.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'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.property.name !== 'on') return
const arg = node.arguments[0]
if (!arg || arg.value !== 'ready') return

if (utils.isjQuery(node)) {
context.report({
node: node,
message: '.on("ready") is not allowed'
})
}
}
}
}
}
36 changes: 36 additions & 0 deletions tests/no-on-ready.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'

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

const error = '.on("ready") is not allowed'

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

0 comments on commit c57d22f

Please sign in to comment.