@@ -12,6 +12,18 @@ export const messages = utils.ruleMessages(ruleName, {
1212} ) ;
1313const targetProperties = [ 'transition' , 'animation' , 'animation-name' ] ;
1414
15+ function checkChildrenNodes ( childrenNodes , currentSelector , parentNode ) {
16+ return childrenNodes . some ( declaration => {
17+ const index = targetProperties . indexOf ( declaration . prop ) ;
18+ if ( currentSelector === 'animation-name' && targetProperties [ index ] === 'animation' )
19+ return true ;
20+ if ( currentSelector !== targetProperties [ index ] ) return false ;
21+ if ( declaration . value !== 'none' ) return false ;
22+
23+ return index >= 0 && parentNode . params . indexOf ( 'prefers-reduced-motion' ) >= 0 ;
24+ } ) ;
25+ }
26+
1527function check ( selector , node ) {
1628 const declarations = node . nodes ;
1729 const params = node . parent . params ;
@@ -48,24 +60,29 @@ function check(selector, node) {
4860 return parentNode . nodes . some ( childrenNode => {
4961 const childrenNodes = childrenNode . nodes ;
5062
63+ if (
64+ childrenNode . type === 'atrule' &&
65+ childrenNode . params . indexOf ( 'prefers-reduced-motion' ) >= 0
66+ ) {
67+ return childrenNodes . some ( declaration => {
68+ const index = targetProperties . indexOf ( declaration . prop ) ;
69+ if ( currentSelector === 'animation-name' && targetProperties [ index ] === 'animation' )
70+ return true ;
71+ if ( currentSelector !== targetProperties [ index ] ) return false ;
72+ if ( declaration . value !== 'none' ) return false ;
73+
74+ return index >= 0 ;
75+ } ) ;
76+ }
77+
5178 if (
5279 ! parentNode . params ||
5380 ! Array . isArray ( childrenNodes ) ||
5481 selector !== childrenNode . selector
5582 )
5683 return false ;
5784
58- const matchedChildrenNodes = childrenNodes . some ( declaration => {
59- const index = targetProperties . indexOf ( declaration . prop ) ;
60- if ( currentSelector === 'animation-name' && targetProperties [ index ] === 'animation' )
61- return true ;
62- if ( currentSelector !== targetProperties [ index ] ) return false ;
63- if ( declaration . value !== 'none' ) return false ;
64-
65- return index >= 0 && parentNode . params . indexOf ( 'prefers-reduced-motion' ) >= 0 ;
66- } ) ;
67-
68- return matchedChildrenNodes ;
85+ return checkChildrenNodes ( childrenNodes , currentSelector , parentNode ) ;
6986 } ) ;
7087 } ) ;
7188
0 commit comments