-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathjquery-no-bind-unbind.js
47 lines (42 loc) · 1.32 KB
/
jquery-no-bind-unbind.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow the use of the deprecated $.bind and $.unbind',
category: 'jQuery deprecated functions',
recommended: true,
url: 'https://api.jquery.com/bind/',
},
schema: [],
messages: {
bind: 'jQuery $.bind and $.unbind are deprecated, use $.on and $.off instead',
},
},
/**
* Executes the function to check if bind and unbind are used.
*
* @param {Object} context
* @returns {Object}
*/
create: function (context) {
'use strict';
const utils = require('./utils.js');
return {
/**
* Checks if bind and unbind are used in the node and reports it.
*
* @param {Object} node - The node to check.
*/
CallExpression: function (node) {
if (node.callee.type !== 'MemberExpression') { return; }
if (!['bind', 'unbind'].includes(node.callee.property.name)) { return; }
if (utils.isjQuery(node)) {
context.report({
node: node,
messageId: 'bind',
});
}
},
};
},
};