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 5 commits into
base: main
Choose a base branch
from

Conversation

snitin315
Copy link
Contributor

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?

eslint.config.js Outdated
@@ -30,7 +31,7 @@ const eslintPluginTestsRecommendedConfig =

export default [
{
ignores: ["**/tests/fixtures/", "**/dist/"],
ignores: ["**/tests/fixtures/", "**/dist/", "test.css"],
Copy link
Contributor 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

@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
@snitin315 snitin315 force-pushed the no-dup-keyframe-selectors branch from 62ec302 to 470e3a9 Compare May 31, 2025 17:26
@nzakas
Copy link
Member

nzakas commented Jun 3, 2025

@snitin315 can you check the merge conflicts?

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

export default defineConfig([
globalIgnores(["**/tests/fixtures/", "**/dist/"]),
globalIgnores(["**/tests/fixtures/", "**/dist/", "test.css"]),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@snitin315
Copy link
Contributor Author

@nzakas resolved.

{
files: ["**/*.css"],
language: "css/css",
...css.configs.recommended,
Copy link
Member

Choose a reason for hiding this comment

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

can we use extends here instead?


create(context) {
return {
Atrule(node) {
Copy link
Member

Choose a reason for hiding this comment

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

This method is traversing the at-rule itself instead of letting the rule do so.

It would be more efficient to do "Atrule[name=keyframes]", "Atrule[name=keyframes]:exit" and then look for the selectors in between.

See https://github.com/eslint/css/blob/main/src/rules/use-layers.js as an example.

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
4 participants