-
Notifications
You must be signed in to change notification settings - Fork 8
/
no-animate-toggle.js
56 lines (51 loc) · 1.28 KB
/
no-animate-toggle.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
54
55
56
'use strict';
const utils = require( '../utils.js' );
module.exports = {
meta: {
type: 'suggestion',
docs: {
description:
'Disallows the duration argument when using the ' + utils.jQueryCollectionLink( 'show' ) +
', ' + utils.jQueryCollectionLink( 'hide' ) + ' & ' + utils.jQueryCollectionLink( 'toggle' ) +
' methods. Prefer CSS transitions.'
},
schema: []
},
create: ( context ) => {
const forbidden = [ 'show', 'hide', 'toggle' ];
return {
'CallExpression:exit': ( node ) => {
if (
node.callee.type !== 'MemberExpression' ||
!forbidden.includes( node.callee.property.name ) ||
node.arguments.length === 0
) {
return;
}
if (
node.arguments.length === 1 &&
node.callee.property.name === 'toggle'
) {
let possibleBool = true;
const arg = node.arguments[ 0 ];
if ( arg.type === 'Literal' ) {
possibleBool = typeof arg.value === 'boolean';
}
if ( arg.type === 'ObjectExpression' ) {
possibleBool = false;
}
if ( possibleBool ) {
return;
}
}
if ( utils.isjQuery( context, node ) ) {
context.report( {
node,
message: 'Prefer CSS transitions to .{{method}}',
data: { method: node.callee.property.name }
} );
}
}
};
}
};