|
1 | 1 | module.exports = {
|
2 |
| - meta: { |
3 |
| - type: 'suggestion', |
4 |
| - docs: { |
5 |
| - description: 'Disallow the use of shortcuts to trigger events', |
6 |
| - category: 'jQuery deprecated functions', |
7 |
| - recommended: true, |
8 |
| - url: 'https://api.jquery.com/bind/' |
| 2 | + meta: { |
| 3 | + type: 'suggestion', |
| 4 | + docs: { |
| 5 | + description: 'Disallow the use of shortcuts to trigger events', |
| 6 | + category: 'jQuery deprecated functions', |
| 7 | + recommended: true, |
| 8 | + url: 'https://api.jquery.com/bind/' |
| 9 | + }, |
| 10 | + schema: [] |
9 | 11 | },
|
10 |
| - schema: [], |
11 |
| - }, |
12 | 12 |
|
13 |
| - create: function(context) { |
14 |
| - 'use strict'; |
15 |
| - var utils = require('./utils.js'); |
| 13 | + /** |
| 14 | + * Executes the function to check if shortcuts are used to trigger events. |
| 15 | + * |
| 16 | + * @param {Object} context |
| 17 | + * @returns {Object} |
| 18 | + */ |
| 19 | + create: function (context) { |
| 20 | + 'use strict'; |
16 | 21 |
|
17 |
| - return { |
18 |
| - CallExpression: function(node) { |
19 |
| - var names, name; |
| 22 | + var utils = require('./utils.js'); |
20 | 23 |
|
21 |
| - names = [ |
22 |
| - 'blur', 'focus', 'focusin', 'focusout', 'resize', 'scroll', 'dblclick', 'mousedown', 'mouseup', 'mousemove', |
23 |
| - 'mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'change', 'select', 'submit', 'keydown', 'keypress', |
24 |
| - 'keyup', 'contextmenu', 'click' |
25 |
| - ]; |
| 24 | + return { |
| 25 | + /** |
| 26 | + * Checks if shortcuts are used to trigger events and reports it. |
| 27 | + * |
| 28 | + * @param {Object} node - The node to check. |
| 29 | + */ |
| 30 | + CallExpression: function (node) { |
| 31 | + var names, name; |
26 | 32 |
|
27 |
| - if (node.callee.type !== 'MemberExpression') return; |
28 |
| - if (!names.includes(node.callee.property.name)) return; |
29 |
| - if (utils.isjQuery(node)) { |
30 |
| - name = node.callee.property.name; |
31 |
| - context.report({ |
32 |
| - node: node, |
33 |
| - message: |
34 |
| - 'Instead of .' + name + '(fn) use .on("' + name + '", fn). Instead of .' + name |
35 |
| - + '() use .trigger("' + name + '")' |
36 |
| - }); |
37 |
| - } |
38 |
| - } |
39 |
| - }; |
40 |
| - } |
| 33 | + names = ['blur', 'focus', 'focusin', 'focusout', 'resize', 'scroll', 'dblclick', 'mousedown', |
| 34 | + 'mouseup', 'mousemove','mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'change', 'select', |
| 35 | + 'submit', 'keydown', 'keypress', 'keyup', 'contextmenu', 'click']; |
| 36 | + |
| 37 | + // jscs:disable requireCurlyBraces |
| 38 | + if (node.callee.type !== 'MemberExpression') return; |
| 39 | + |
| 40 | + if (!names.includes(node.callee.property.name)) return; |
| 41 | + // jscs:enable requireCurlyBraces |
| 42 | + |
| 43 | + if (utils.isjQuery(node)) { |
| 44 | + name = node.callee.property.name; |
| 45 | + context.report({ |
| 46 | + node: node, |
| 47 | + message: |
| 48 | + 'Instead of .' + name + '(fn) use .on("' + name + '", fn). Instead of .' + name + |
| 49 | + '() use .trigger("' + name + '")' |
| 50 | + }); |
| 51 | + } |
| 52 | + } |
| 53 | + }; |
| 54 | + } |
41 | 55 | };
|
0 commit comments