Skip to content

feat: add new rule no-duplicate-keyframe-selectors #143

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

snitin315
Copy link

Prerequisites checklist

What is the purpose of this pull request?

Add new rule no-duplicate-keyframe-selectors.

What changes did you make? (Give an overview)

Examples of incorrect code for this rule:

/* eslint css/no-duplicate-keyframe-selectors: "error" */

@keyframes test {
	0% {
		opacity: 0;
	}

	0% {
		opacity: 1;
	}
}

@keyframes test {
	from {
		opacity: 0;
	}

	from {
		opacity: 1;
	}
}

@keyframes test {
	from {
		opacity: 0;
	}

	from {
		opacity: 1;
	}
}

Examples of correct code for this rule:

/* eslint css/no-duplicate-keyframe-selectors: "error" */

@keyframes test {
	0% {
		opacity: 0;
	}

	100% {
		opacity: 1;
	}
}

@keyframes test {
	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}

Related Issues

Fix #141

Is there anything you'd like reviewers to focus on?

@@ -30,7 +31,7 @@ const eslintPluginTestsRecommendedConfig =

export default [
{
ignores: ["**/tests/fixtures/", "**/dist/"],
ignores: ["**/tests/fixtures/", "**/dist/", "test.css"],
Copy link
Author

@snitin315 snitin315 May 21, 2025

Choose a reason for hiding this comment

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

Added this test.css for local testing purposes, similar to the eslint repo

Screenshot 2025-05-22 at 12 41 02 AM

Comment on lines +42 to +43
// @ts-ignore - prelude is a valid property
const selector = child.prelude.children[0].children[0];
Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure why TS reports error here, it seems to be valid. AST

Screenshot 2025-05-22 at 12 43 22 AM

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to add conditions here to check the types

Suggested change
// @ts-ignore - prelude is a valid property
const selector = child.prelude.children[0].children[0];
// @ts-ignore - prelude is a valid property
const selector = child.type === "Rule" && child.prelude.type === "SelectorList" && child.prelude.children[0].type === "Selector" && child.prelude.children[0].children[0];

@lumirlumir lumirlumir added the accepted There is consensus among the team that this change meets the criteria for inclusion label May 22, 2025
@Tanujkanti4441 Tanujkanti4441 moved this from Needs Triage to Implementing in Triage May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion feature
Projects
Status: Implementing
Development

Successfully merging this pull request may close these issues.

New Rule: no-duplicate-keyframe-selectors
3 participants