-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathno-ready.js
43 lines (38 loc) · 920 Bytes
/
no-ready.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
'use strict';
const utils = require( '../utils.js' );
// $(function(){})
function isDirect( context, node ) {
return (
node.callee.type === 'Identifier' &&
utils.isjQueryConstructor( context, node.callee.name ) &&
node.arguments[ 0 ] &&
utils.isFunction( node.arguments[ 0 ] )
);
}
// $(document).ready()
function isChained( context, node ) {
return (
node.callee.type === 'MemberExpression' &&
node.callee.property.name === 'ready' &&
utils.isjQuery( context, node )
);
}
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallows the document ready event, either `$( function() {} )` or `$( document ).ready()`.'
},
schema: []
},
create: ( context ) => ( {
'CallExpression:exit': ( node ) => {
if ( isDirect( context, node ) || isChained( context, node ) ) {
context.report( {
node,
message: '.ready is not allowed'
} );
}
}
} )
};