-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvariable-pattern.js
More file actions
40 lines (36 loc) · 920 Bytes
/
variable-pattern.js
File metadata and controls
40 lines (36 loc) · 920 Bytes
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
'use strict';
const utils = require( '../utils.js' );
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallows variable names which don\'t match `variablePattern` in settings (by default a `$`-prefix).'
},
schema: []
},
create: ( context ) => {
function test( node, left, right ) {
if (
!utils.isjQuery( context, left ) &&
// If the variable name is computed (e.g. foo[bar]) we
// can't be sure this is not correctly named.
!left.computed &&
// right can be null, e.g. `var x;`
right && utils.isjQuery( context, right )
) {
context.report( {
node,
message: 'jQuery collection names must match the variablePattern'
} );
}
}
return {
'AssignmentExpression:exit': ( node ) => {
test( node, node.left, node.right );
},
'VariableDeclarator:exit': ( node ) => {
test( node, node.id, node.init );
}
};
}
};