-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathjquery-no-input-event-shorthand.js
52 lines (45 loc) · 1.73 KB
/
jquery-no-input-event-shorthand.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
48
49
50
51
52
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow the use of shortcuts to input events via keyboard/mouse trigger events',
category: 'jQuery deprecated functions',
recommended: true,
url: 'https://api.jquery.com/bind/'
},
schema: []
},
/**
* Executes the function to check if shortcuts are used to trigger events.
*
* @param {Object} context
* @returns {Object}
*/
create: function (context) {
'use strict';
var utils = require('./utils.js');
return {
/**
* Checks if shortcuts are used to trigger events and reports it.
*
* @param {Object} node - The node to check.
*/
CallExpression: function (node) {
var names, name;
names = ['blur', 'focus', 'focusin', 'focusout', 'resize', 'scroll', 'dblclick', 'mousedown',
'mouseup', 'mousemove','mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'change', 'select',
'submit', 'keydown', 'keypress', 'keyup', 'contextmenu', 'click'];
if (node.callee.type !== 'MemberExpression') {return;}
if (!names.includes(node.callee.property.name)) {return;}
if (utils.isjQuery(node)) {
name = node.callee.property.name;
context.report({
node: node,
message: 'Instead of .' + name + '(fn) use .on("' + name + '", fn). Instead of .' + name +
'() use .trigger("' + name + '")'
});
}
}
};
}
};