-
-
Notifications
You must be signed in to change notification settings - Fork 929
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
Add no-invalid-position-var-function
#6859
Comments
If stylelint had a proper parsers like proposed in stylelint/css-parser#2, this case wouldn't even need a rule, as the invalid syntax would trip that parser. |
@silverwind Thanks for the proposal. Could you please comment on a link to the CSS spec you quoted? Also, does this syntax error occur with other at-rules? |
Spec links are: https://drafts.csswg.org/css-syntax-3/ As for Here is what I tested: @page {
margin-top: var(--foo);
}
@font-face {
font-weight: var(--foo);
}
@counter-style foo {
system: var(--foo);
} Firefox accepts the first syntax, but not the other two. |
@silverwind yeah, I think it is more about grammar parsing than linting, so I hope in future we resolve problems with our parser and will catch this on the parser side (or will have rule to apply grammar parsing to each things in your CSS) |
Agree, syntax errors are topics for a parser, not a linter. |
@ybiquitous We might want to keep this one open and add a rule for it regardless of anything that might be done for parsing CSS in general? Thoughts? |
@romainmenke Surely, this rule might help people to notice mistakes of But, I'm concerning about the @silverwind's comment:
Can we solve this problem? Anyway, I agree with reopening this and keeping it until we find a good solution. 👍🏼 |
If I recall correctly this is the difference between descriptors and properties. https://www.w3.org/TR/css-variables-1/#using-variables
https://www.w3.org/TR/css-fonts-4/#font-face-rule Edit :
|
Ah, I see! Some at-rules accept properties, while some at-rules accept descriptors. If so, we can likely manage at-rules accepting descriptors in |
If this rule is limited to at-rule, starting the rule name with Ref: |
no-invalid-descriptor-declaration
at-rule-no-invalid-descriptor
Agree, renamed title to |
Okay, I suggest a blueprint:
Example: @font-face {
font-weight: var(--font-weight-normal);
/* ^~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected invalid descriptor within "@font-face"
*/
} {
"at-rule-no-invalid-descriptor": true
} Please feel free to give me any feedback. |
at-rule-no-invalid-descriptor
at-rule-no-invalid-descriptor
rule
at-rule-no-invalid-descriptor
ruleat-rule-no-invalid-descriptor
rule
Not sure if this is the right name because :root {
--lol: 6in;
}
@page {
size : 4in var(--lol); /* size is a descriptor */
} seems to be valid. |
Right, it's only refering to the right side, so |
at-rule-no-invalid-descriptor
ruleat-rule-no-invalid-descriptor-value
rule
What I was trying to say is that the scope of |
Ah, misunderstood you. If Regarding rule name, I think |
We had the inverse problem with |
Maybe it can be approached from a different perspective? Part of the issue here is that A rule that warns on invalid locations of
I think this is also easier to test and verify so that it is correct with the CSS specification. |
Hum, @romainmenke's suggestion sounds good. So, how about |
at-rule-no-invalid-descriptor-value
rulevar()
in descriptors
That's a good summary.
I agree.
SGTM. It'll tie into the "The I had thought
Our closest existing rule is no-invalid-position-at-import-rule, so called because it's scoped to the whole source like this rule. Suggested blueprint:
The This rule checks:
We'll want to ensure we don't needlessly call any of the constructor parsers when checking any of the above. According to the CSS tree reference, the following at-rule have descriptors:
Shall I label as ready to implement? |
I agree with @jeddy3's suggestion 👍🏼 |
var()
in descriptorsno-invalid-position-var-function
This issue is older than one month. Please ask before opening a pull request, as it may no longer be relevant. |
What is the problem you're trying to solve?
Using the
var()
function inside a@
rule block is a CSS syntax error that should be detectable:Firefox will raise a
Unknown descriptor ‘var(’ in @font-face rule. Skipped to next declaration.
.What solution would you like to see?
A rule that detects such cases. I dug through the CSS specs and found:
I'm sure there are more functions besides
var
that would be invalid for a descriptor declaration, but a rule that just warns forvar
would be a good start.The text was updated successfully, but these errors were encountered: