Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keyframe-selector-notation false positives for named timeline range #6605

Merged
merged 7 commits into from Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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% {} }',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

ybiquitous marked this conversation as resolved.
Show resolved Hide resolved
selectors.walkTags((selectorTag) => {
if (first && NAMED_TIMELINE_RANGE_SELECTORS.has(selectorTag.value)) {
return false;
}

first = false;

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