Skip to content

Commit 8ec6748

Browse files
mattxwangybiquitousjeddy3
authoredDec 22, 2023
Add ignore: ["keyframe-selectors"] to selector-disallowed-list (#7417)
Closes #7162. --------- Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>
1 parent 548b221 commit 8ec6748

File tree

5 files changed

+122
-4
lines changed

5 files changed

+122
-4
lines changed
 

‎.changeset/sixty-lamps-type.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stylelint": minor
3+
---
4+
5+
Added: `ignore: ["keyframe-selectors"]` to `selector-disallowed-list`

‎lib/rules/selector-disallowed-list/README.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ For example, with `true`.
8080
Given:
8181

8282
```json
83-
[".foo"]
83+
[".foo", { "splitList": true }]
8484
```
8585

8686
The following pattern is considered a problem:
@@ -104,7 +104,7 @@ Ignore selectors that are inside a block.
104104
Given:
105105

106106
```json
107-
[".foo"]
107+
[".foo", { "ignore": ["inside-block"] }]
108108
```
109109

110110
The following pattern is _not_ considered a problem:
@@ -115,3 +115,22 @@ The following pattern is _not_ considered a problem:
115115
.foo {}
116116
}
117117
```
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+
```

‎lib/rules/selector-disallowed-list/__tests__/index.mjs

+72
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import rule from '../index.mjs';
2+
import { stripIndent } from 'common-tags';
3+
24
const { messages, ruleName } = rule;
35

46
testRule({
@@ -220,3 +222,73 @@ testRule({
220222
},
221223
],
222224
});
225+
226+
testRule({
227+
ruleName,
228+
config: [[/[A-Za-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: [/from/, { 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+
});

‎lib/rules/selector-disallowed-list/index.cjs

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
'use strict';
44

55
const validateTypes = require('../../utils/validateTypes.cjs');
6+
const isKeyframeRule = require('../../utils/isKeyframeRule.cjs');
67
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule.cjs');
78
const matchesStringOrRegExp = require('../../utils/matchesStringOrRegExp.cjs');
89
const optionsMatches = require('../../utils/optionsMatches.cjs');
@@ -33,7 +34,7 @@ const rule = (primary, secondaryOptions) => {
3334
{
3435
actual: secondaryOptions,
3536
possible: {
36-
ignore: ['inside-block'],
37+
ignore: ['inside-block', 'keyframe-selectors'],
3738
splitList: [validateTypes.isBoolean],
3839
},
3940
optional: true,
@@ -45,13 +46,23 @@ const rule = (primary, secondaryOptions) => {
4546
}
4647

4748
const ignoreInsideBlock = optionsMatches(secondaryOptions, 'ignore', 'inside-block');
49+
const ignoreKeyframeSelectors = optionsMatches(
50+
secondaryOptions,
51+
'ignore',
52+
'keyframe-selectors',
53+
);
54+
4855
const splitList = secondaryOptions && secondaryOptions.splitList;
4956

5057
root.walkRules((ruleNode) => {
5158
if (!isStandardSyntaxRule(ruleNode)) {
5259
return;
5360
}
5461

62+
if (ignoreKeyframeSelectors && isKeyframeRule(ruleNode)) {
63+
return;
64+
}
65+
5566
if (ignoreInsideBlock) {
5667
const { parent } = ruleNode;
5768
const isInsideBlock = parent && parent.type !== 'root';

‎lib/rules/selector-disallowed-list/index.mjs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isBoolean, isRegExp, isString } from '../../utils/validateTypes.mjs';
2+
import isKeyframeRule from '../../utils/isKeyframeRule.mjs';
23
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs';
34
import matchesStringOrRegExp from '../../utils/matchesStringOrRegExp.mjs';
45
import optionsMatches from '../../utils/optionsMatches.mjs';
@@ -29,7 +30,7 @@ const rule = (primary, secondaryOptions) => {
2930
{
3031
actual: secondaryOptions,
3132
possible: {
32-
ignore: ['inside-block'],
33+
ignore: ['inside-block', 'keyframe-selectors'],
3334
splitList: [isBoolean],
3435
},
3536
optional: true,
@@ -41,13 +42,23 @@ const rule = (primary, secondaryOptions) => {
4142
}
4243

4344
const ignoreInsideBlock = optionsMatches(secondaryOptions, 'ignore', 'inside-block');
45+
const ignoreKeyframeSelectors = optionsMatches(
46+
secondaryOptions,
47+
'ignore',
48+
'keyframe-selectors',
49+
);
50+
4451
const splitList = secondaryOptions && secondaryOptions.splitList;
4552

4653
root.walkRules((ruleNode) => {
4754
if (!isStandardSyntaxRule(ruleNode)) {
4855
return;
4956
}
5057

58+
if (ignoreKeyframeSelectors && isKeyframeRule(ruleNode)) {
59+
return;
60+
}
61+
5162
if (ignoreInsideBlock) {
5263
const { parent } = ruleNode;
5364
const isInsideBlock = parent && parent.type !== 'root';

0 commit comments

Comments
 (0)
Please sign in to comment.