Skip to content

Commit

Permalink
Fix keyframe-selector-notation false positives for named timeline r…
Browse files Browse the repository at this point in the history
…ange (#6605)
  • Loading branch information
kimulaco committed Feb 4, 2023
1 parent 3358401 commit 731a4c4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-baboons-train.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `keyframe-selector-notation` false positives for named timeline ranges
26 changes: 26 additions & 0 deletions lib/rules/keyframe-selector-notation/__tests__/index.js
Expand Up @@ -2,6 +2,29 @@

const { messages, ruleName } = require('..');

const ACCEPT_TIMELINE_RANGE_NAME_TEST_CASES = [
{
code: '@keyframes foo { cover 0% {} cover 100% {} }',
description: 'timeline-range-name cover',
},
{
code: '@keyframes foo { contain 0% {} contain 100% {} }',
description: 'timeline-range-name contain',
},
{
code: '@keyframes foo { entry 0% {} entry 100% {} }',
description: 'timeline-range-name entry',
},
{
code: '@keyframes foo { enter 0% {} enter 100% {} }',
description: 'timeline-range-name enter',
},
{
code: '@keyframes foo { exit 0% {} exit 100% {} }',
description: 'timeline-range-name exit',
},
];

testRule({
ruleName,
config: ['keyword'],
Expand Down Expand Up @@ -29,6 +52,7 @@ testRule({
code: '@keyframes foo { from, to {} }',
description: 'selector lists',
},
...ACCEPT_TIMELINE_RANGE_NAME_TEST_CASES,
],

reject: [
Expand Down Expand Up @@ -166,6 +190,7 @@ testRule({
code: '@keyframes foo { 0%, 100% {} }',
description: 'selector lists',
},
...ACCEPT_TIMELINE_RANGE_NAME_TEST_CASES,
],

reject: [
Expand Down Expand Up @@ -301,6 +326,7 @@ testRule({
{
code: '@keyframes foo { from,to {} }',
},
...ACCEPT_TIMELINE_RANGE_NAME_TEST_CASES,
],

reject: [
Expand Down
9 changes: 9 additions & 0 deletions lib/rules/keyframe-selector-notation/index.js
Expand Up @@ -19,6 +19,7 @@ const meta = {

const PERCENTAGE_SELECTORS = new Set(['0%', '100%']);
const KEYWORD_SELECTORS = new Set(['from', 'to']);
const NAMED_TIMELINE_RANGE_SELECTORS = new Set(['cover', 'contain', 'entry', 'enter', 'exit']);
const PERCENTAGE_TO_KEYWORD = new Map([
['0%', 'from'],
['100%', 'to'],
Expand Down Expand Up @@ -73,7 +74,15 @@ const rule = (primary, _, context) => {

atRuleKeyframes.walkRules((keyframeRule) => {
transformSelector(result, keyframeRule, (selectors) => {
let first = true;

selectors.walkTags((selectorTag) => {
if (first && NAMED_TIMELINE_RANGE_SELECTORS.has(selectorTag.value)) {
return false;
}

first = false;

checkSelector(
selectorTag.value,
optionFuncs[primary],
Expand Down

0 comments on commit 731a4c4

Please sign in to comment.