-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathno-animate.js
More file actions
72 lines (67 loc) · 1.76 KB
/
no-animate.js
File metadata and controls
72 lines (67 loc) · 1.76 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
const utils = require( '../utils.js' );
const methods = [ 'animate', 'stop', 'finish' ];
module.exports = {
meta: {
type: 'suggestion',
docs: {
description:
'Disallows the ' + methods.map( utils.jQueryCollectionLink ).join( '/' ) +
' methods. Use the `allowScroll` option to allow animations which are just used for scrolling. Prefer CSS transitions.'
},
schema: [
{
type: 'object',
properties: {
allowScroll: {
type: 'boolean',
description: 'Allow animations which are just used for scrolling'
}
},
additionalProperties: false
}
],
defaultOptions: [
{ allowScroll: false }
]
},
create: ( context ) => ( {
'CallExpression:exit': ( node ) => {
if (
node.callee.type !== 'MemberExpression' ||
!methods.includes( node.callee.property.name )
) {
return;
}
const allowScroll = context.options[ 0 ] && context.options[ 0 ].allowScroll;
const name = node.callee.property.name;
if ( allowScroll ) {
if ( name === 'stop' || name === 'finish' ) {
// We can't tell what animation we are stopping, so assume
// it is an allowed scroll
return;
} else if ( name === 'animate' ) {
const arg = node.arguments[ 0 ];
// Check properties list has more than just scrollTop/scrollLeft
if ( arg && arg.type === 'ObjectExpression' ) {
if (
arg.properties.every(
( prop ) => prop.key.name === 'scrollTop' || prop.key.name === 'scrollLeft'
)
) {
return;
}
}
}
}
if ( utils.isjQuery( context, node ) ) {
context.report( {
node,
message: allowScroll ?
'Prefer CSS transitions to .animate' :
'Prefer CSS transitions or CSS scroll-behaviour to .animate'
} );
}
}
} )
};