-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add no-on-ready rule and add to deprecated 1.8 (#62)
* Add no-on-ready rule and add to deprecated 1.8 Part of #32 * no-animate-on -> no-on-ready in test name
- Loading branch information
1 parent
f21d3eb
commit e7c3c0f
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-on-ready', 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'}] | ||
} | ||
] | ||
}) |