Repository navigation
feat: add no-unknown-animations rule #535
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
Gaic4o
wants to merge
8
commits into
eslint:main
Choose a base branch
from
Gaic4o:feat/no-unknown-animations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,406
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c242e9b
feat: add no-unknown-animations rule
Gaic4o 0d95fde
feat: check vendor-prefixed animation properties and var() fallbacks
Gaic4o 662db51
feat: check -ms- prefixed animation properties and keyframes
Gaic4o 94bd3d3
refactor: find animation names without the lexer
Gaic4o 57120fe
docs: fix MDN link and tighten wording in no-unknown-animations
Gaic4o 04d8403
fix: handle var() fallbacks in no-unknown-animations
Gaic4o 61bc4fb
fix: resolve nested var() fallbacks in no-unknown-animations
Gaic4o 62e5a84
test: cover parsed var() fallbacks in no-unknown-animations
Gaic4o File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| # no-unknown-animations | ||
|
|
||
| Disallow unknown animation names. | ||
|
|
||
| ## Background | ||
|
|
||
| CSS animations are created by assigning a [`@keyframes`](https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes) rule's name to the [`animation-name`](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-name) property or the [`animation`](https://developer.mozilla.org/en-US/docs/Web/CSS/animation) shorthand property, as in this example: | ||
|
|
||
| ```css | ||
| .card { | ||
| animation: fade-in 300ms ease; | ||
| } | ||
|
|
||
| .button { | ||
| animation-name: fade-in; | ||
| } | ||
|
|
||
| @keyframes fade-in { | ||
| from { | ||
| opacity: 0; | ||
| } | ||
|
|
||
| to { | ||
| opacity: 1; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| If an animation name doesn't match any `@keyframes` rule, for example because of a typo or because the `@keyframes` rule was renamed or removed, the animation doesn't run and the browser reports no error. | ||
|
|
||
| ## Rule Details | ||
|
|
||
| This rule warns when an animation name used in `animation` or `animation-name` doesn't match any `@keyframes` rule defined in the same source. Vendor-prefixed properties such as `-webkit-animation` are checked too, and a vendor-prefixed `@keyframes` rule defines an animation name just like an unprefixed one does. | ||
|
|
||
| Animation names are case-sensitive, and quoted and unquoted names refer to the same animation, so `animation-name: "fade-in"` matches `@keyframes fade-in`. | ||
|
|
||
| In the `animation` shorthand, keywords are assigned to their corresponding sub-properties first. If a sub-property already has a value, another keyword for that sub-property is treated as the animation name: | ||
|
|
||
| ```css | ||
| /* `ease-in` sets the timing function; `ease-out` is checked as the animation name */ | ||
| animation: ease-in ease-out; | ||
| ``` | ||
|
|
||
| The rule only checks animation names that can be determined statically. When a value contains `var()`, the names in its fallback are checked if there is one, and so is the rest of the value: | ||
|
|
||
| ```css | ||
| /* `fade-in` is checked, the duration is not */ | ||
| animation: fade-in var(--duration); | ||
|
|
||
| /* the fallback names an animation, so `slide-in` is checked */ | ||
| animation-name: var(--animation-name, slide-in); | ||
|
|
||
| /* a nested fallback names an animation too, so `slide-in` is checked */ | ||
| animation-name: var(--animation-name, var(--fallback-name, slide-in)); | ||
|
|
||
| /* both fallback names are checked */ | ||
| animation-name: var(--animation-name, fade-in, slide-in); | ||
|
|
||
| /* no name can be determined, so nothing is checked */ | ||
| animation-name: var(--animation-name); | ||
| ``` | ||
|
|
||
| Examples of **incorrect** code for this rule: | ||
|
|
||
| ```css | ||
| /* eslint css/no-unknown-animations: "error" */ | ||
|
|
||
| .card { | ||
| animation: fade-in 300ms ease; | ||
| } | ||
|
|
||
| .button { | ||
| animation-name: slide-up; | ||
| } | ||
|
|
||
| @keyframes fade-out { | ||
| from { | ||
| opacity: 1; | ||
| } | ||
|
|
||
| to { | ||
| opacity: 0; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Examples of **correct** code for this rule: | ||
|
|
||
| ```css | ||
| /* eslint css/no-unknown-animations: "error" */ | ||
|
|
||
| .card { | ||
| animation: fade-in 300ms ease; | ||
| } | ||
|
|
||
| .button { | ||
| animation-name: slide-up; | ||
| } | ||
|
|
||
| @keyframes fade-in { | ||
| from { | ||
| opacity: 0; | ||
| } | ||
|
|
||
| to { | ||
| opacity: 1; | ||
| } | ||
| } | ||
|
|
||
| @keyframes slide-up { | ||
| from { | ||
| transform: translateY(8px); | ||
| } | ||
|
|
||
| to { | ||
| transform: translateY(0); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
|
Tanujkanti4441 marked this conversation as resolved.
|
||
| ## Options | ||
|
|
||
| This rule has no options. | ||
|
|
||
| ## When Not to Use It | ||
|
|
||
| This rule only checks `@keyframes` rules in the same source, so it can't find animations defined in another stylesheet. If your `@keyframes` rules live in a different file from the animations that use them, you can disable this rule. | ||
|
|
||
| ## Prior Art | ||
|
|
||
| - [`no-unknown-animations`](https://stylelint.io/user-guide/rules/no-unknown-animations/) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.