File tree 5 files changed +122
-4
lines changed
lib/rules/selector-disallowed-list
5 files changed +122
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " stylelint " : minor
3
+ ---
4
+
5
+ Added: ` ignore: ["keyframe-selectors"] ` to ` selector-disallowed-list `
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ For example, with `true`.
80
80
Given:
81
81
82
82
``` json
83
- [" .foo" ]
83
+ [" .foo" , { "splitList" : true } ]
84
84
```
85
85
86
86
The following pattern is considered a problem:
@@ -104,7 +104,7 @@ Ignore selectors that are inside a block.
104
104
Given:
105
105
106
106
``` json
107
- [" .foo" ]
107
+ [" .foo" , { "ignore" : [ " inside-block " ] } ]
108
108
```
109
109
110
110
The following pattern is _ not_ considered a problem:
@@ -115,3 +115,22 @@ The following pattern is _not_ considered a problem:
115
115
.foo {}
116
116
}
117
117
```
118
+
119
+ ### ` ignore: ["keyframe-selectors"] `
120
+
121
+ Ignore keyframe selectors.
122
+
123
+ Given:
124
+
125
+ ``` json
126
+ [" /from/" , { "ignore" : [" keyframe-selectors" ] }]
127
+ ```
128
+
129
+ The following pattern is _ not_ considered a problem:
130
+
131
+ <!-- prettier-ignore -->
132
+ ``` css
133
+ @keyframes fade-in {
134
+ from {}
135
+ }
136
+ ```
Original file line number Diff line number Diff line change 1
1
import rule from '../index.mjs' ;
2
+ import { stripIndent } from 'common-tags' ;
3
+
2
4
const { messages, ruleName } = rule ;
3
5
4
6
testRule ( {
@@ -220,3 +222,73 @@ testRule({
220
222
} ,
221
223
] ,
222
224
} ) ;
225
+
226
+ testRule ( {
227
+ ruleName,
228
+ config : [ [ / [ A - Z a - z ] / ] , { ignore : [ 'keyframe-selectors' ] } ] ,
229
+
230
+ accept : [
231
+ {
232
+ code : stripIndent `
233
+ @keyframes fade-in {
234
+ from {}
235
+ }
236
+ ` ,
237
+ } ,
238
+ {
239
+ code : stripIndent `
240
+ @keyframes fade-in {
241
+ to {}
242
+ }
243
+ ` ,
244
+ } ,
245
+ {
246
+ code : stripIndent `
247
+ @keyframes fade-in {
248
+ from, to {}
249
+ }
250
+ ` ,
251
+ } ,
252
+ ] ,
253
+
254
+ reject : [
255
+ {
256
+ code : '.from {}' ,
257
+ message : messages . rejected ( '.from' ) ,
258
+ line : 1 ,
259
+ column : 1 ,
260
+ endLine : 1 ,
261
+ endColumn : 6 ,
262
+ } ,
263
+ {
264
+ code : '.to {}' ,
265
+ message : messages . rejected ( '.to' ) ,
266
+ line : 1 ,
267
+ column : 1 ,
268
+ endLine : 1 ,
269
+ endColumn : 4 ,
270
+ } ,
271
+ ] ,
272
+ } ) ;
273
+
274
+ testRule ( {
275
+ ruleName,
276
+ config : [ / f r o m / , { ignore : [ 'keyframe-selectors' ] , splitList : true } ] ,
277
+
278
+ accept : [
279
+ {
280
+ code : stripIndent `
281
+ @keyframes fade-in {
282
+ from {}
283
+ }
284
+ ` ,
285
+ } ,
286
+ {
287
+ code : stripIndent `
288
+ @keyframes fade-in {
289
+ from, to {}
290
+ }
291
+ ` ,
292
+ } ,
293
+ ] ,
294
+ } ) ;
Original file line number Diff line number Diff line change 3
3
'use strict' ;
4
4
5
5
const validateTypes = require ( '../../utils/validateTypes.cjs' ) ;
6
+ const isKeyframeRule = require ( '../../utils/isKeyframeRule.cjs' ) ;
6
7
const isStandardSyntaxRule = require ( '../../utils/isStandardSyntaxRule.cjs' ) ;
7
8
const matchesStringOrRegExp = require ( '../../utils/matchesStringOrRegExp.cjs' ) ;
8
9
const optionsMatches = require ( '../../utils/optionsMatches.cjs' ) ;
@@ -33,7 +34,7 @@ const rule = (primary, secondaryOptions) => {
33
34
{
34
35
actual : secondaryOptions ,
35
36
possible : {
36
- ignore : [ 'inside-block' ] ,
37
+ ignore : [ 'inside-block' , 'keyframe-selectors' ] ,
37
38
splitList : [ validateTypes . isBoolean ] ,
38
39
} ,
39
40
optional : true ,
@@ -45,13 +46,23 @@ const rule = (primary, secondaryOptions) => {
45
46
}
46
47
47
48
const ignoreInsideBlock = optionsMatches ( secondaryOptions , 'ignore' , 'inside-block' ) ;
49
+ const ignoreKeyframeSelectors = optionsMatches (
50
+ secondaryOptions ,
51
+ 'ignore' ,
52
+ 'keyframe-selectors' ,
53
+ ) ;
54
+
48
55
const splitList = secondaryOptions && secondaryOptions . splitList ;
49
56
50
57
root . walkRules ( ( ruleNode ) => {
51
58
if ( ! isStandardSyntaxRule ( ruleNode ) ) {
52
59
return ;
53
60
}
54
61
62
+ if ( ignoreKeyframeSelectors && isKeyframeRule ( ruleNode ) ) {
63
+ return ;
64
+ }
65
+
55
66
if ( ignoreInsideBlock ) {
56
67
const { parent } = ruleNode ;
57
68
const isInsideBlock = parent && parent . type !== 'root' ;
Original file line number Diff line number Diff line change 1
1
import { isBoolean , isRegExp , isString } from '../../utils/validateTypes.mjs' ;
2
+ import isKeyframeRule from '../../utils/isKeyframeRule.mjs' ;
2
3
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs' ;
3
4
import matchesStringOrRegExp from '../../utils/matchesStringOrRegExp.mjs' ;
4
5
import optionsMatches from '../../utils/optionsMatches.mjs' ;
@@ -29,7 +30,7 @@ const rule = (primary, secondaryOptions) => {
29
30
{
30
31
actual : secondaryOptions ,
31
32
possible : {
32
- ignore : [ 'inside-block' ] ,
33
+ ignore : [ 'inside-block' , 'keyframe-selectors' ] ,
33
34
splitList : [ isBoolean ] ,
34
35
} ,
35
36
optional : true ,
@@ -41,13 +42,23 @@ const rule = (primary, secondaryOptions) => {
41
42
}
42
43
43
44
const ignoreInsideBlock = optionsMatches ( secondaryOptions , 'ignore' , 'inside-block' ) ;
45
+ const ignoreKeyframeSelectors = optionsMatches (
46
+ secondaryOptions ,
47
+ 'ignore' ,
48
+ 'keyframe-selectors' ,
49
+ ) ;
50
+
44
51
const splitList = secondaryOptions && secondaryOptions . splitList ;
45
52
46
53
root . walkRules ( ( ruleNode ) => {
47
54
if ( ! isStandardSyntaxRule ( ruleNode ) ) {
48
55
return ;
49
56
}
50
57
58
+ if ( ignoreKeyframeSelectors && isKeyframeRule ( ruleNode ) ) {
59
+ return ;
60
+ }
61
+
51
62
if ( ignoreInsideBlock ) {
52
63
const { parent } = ruleNode ;
53
64
const isInsideBlock = parent && parent . type !== 'root' ;
You can’t perform that action at this time.
0 commit comments