-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathjquery-no-event-shorthand.js
53 lines (47 loc) · 1.56 KB
/
jquery-no-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
53
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow the use of shorthand event methods',
category: 'jQuery deprecated functions',
recommended: true,
url: 'https://api.jquery.com/load/',
},
schema: [],
},
/**
* Executes the function to check if shorthand event methods are used.
*
* @param {Object} context
* @returns {Object}
*/
create: function (context) {
'use strict';
var utils = require('./utils.js');
return {
/**
* Checks if shorthand event methods are used.
*
* @param {Object} node - The node to check.
*/
CallExpression: function (node) {
var namesToMsg = {
'unload': 'jQuery.unload() was removed, use .on("unload", fn) instead.',
'ready': 'jQuery.ready(handler) is deprecated and should be replaced with jQuery(handler)',
},
name,
message;
if (node.callee.type !== 'MemberExpression') {return;}
name = node.callee.property.name;
if (!namesToMsg.hasOwnProperty(name)) {return;}
message = namesToMsg[name];
if (utils.isjQuery(node)) {
context.report({
node: node,
message: message,
});
}
},
};
},
};