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 declaration-property-value-no-unknown #6511
Conversation
|
@jeddy3 I've pushed a |
This rule is the final piece of the v15 puzzle now that we merged #6561 & #6573. Let's decide whether we want it in. As mentioned in #6511, including it now will help communicate to people the type of problems Stylelint can help them with going forward. We've closed two issues (#6591 & #6576) just in the last couple of weeks requesting it, and there's a desire for it in this Twitter thread. People expect and want Stylelint to do this. However, it comes at the cost of a larger package size and likely some maintenance. For example, CSSTree flags these two:
Support for Fortunately, the syntax that CSSTree uses can be extended. So, CSSTree can do the heavy lifting in most cases, and we can maintain our own references for things that we can't quickly patch in CSSTree. There will be edge cases, but we can limit their impact. Regardless, this rule will be beneficial to most people. What does everyone think? Unfortunately, I will not be as available as I thought I would be over the coming weeks. If we decide we want this rule in, would someone like to pick it up and get it over the finish line? |
We will probably have a regular stream of issues regarding false positives that will end up being upstreamed to csstree. If that's the case I am all for it. |
@jeddy3 Sorry for the late reply. I also believe this rule will benefit most people, but I'm a bit concerned about potential false positives and inactivity of the CSSTree repo, as @Mouvedia says.
The math functions support like if (/^(clamp|min|max)\(/i.test(value)) return; Extending via
CSSTree seems not to support the legacy keyword for if (/^-moz-initial$/i.test(value)) return; Sending a patch to CSSTree may be possible, but this is an edge case, so I believe it is sufficient to add the workaround code to this rule. Additionally, I find this rule may be duplicated with a { color: #4f; }
To summarize, despite potential false positives, I believe this rule has a big value for most people, and CSSTree is suitable to achieve it now. Perhaps, the author of CSSTree and stylelint-validator may collaborate with us because stylelint-validator could be replaced with this rule and future built-in rules using CSSTree.
I can do it. ✋🏼 |
@lahmatiy what's your opinion on that?
Nice catch. If
Ill add all the unsupported keywords/functions that I know of. e.g. I won't add stuff that I consider out of scope though. |
@Mouvedia I'm open for a collaboration. CSSTree is out of my focus currently. That primally affects my ability to work on complex features, I have no enough time for it at the moment. However, I can review simple PRs and publish releases when needed.
Let me start with how syntax matching (a validation is based on it) works. There is no specific code in CSSTree for a property matching/validation, like many other libraries do. Instead, it uses a general solution based on Value Definition Syntax defined in Values and Units Module. Using this approach, you can easily add new properties or change existing by making changes in a dictionary. Mentioned CSSTree uses mdn-data as a primary dictionary of syntax definitions, with some additions and fixes. In most cases, you need to add/fix a definition in mdn-data dictionary. However, mdn-data's releases a pretty rare events, so it may be much faster to make changes in CSSTree as well. In fact, in my opinion, the dictionary should be a separate project, which will be aimed at providing a dictionary for use in tools. mdn has no such goal, although it is used in tools (with hacks, like in CSSTree) for lack of a better one. But this is a topic for a separate discussion. 4 cases above is about 3 different areas. Last two is most simple, it's about a missing in the dictionary. You can see current definition for width and height properties in CSSTree syntax reference dashboard. The width property is already patched by CSSTree to add some non-standard values: So you can add missing keywords to these properties the same way.
Btw, I believe that there are much more missing parts in dictionaries. Some time ago I started working on a project to automate the synchronization of syntaxes with CSS specs. Also worked on a project to collect CSS usage data from real web sites. I believe that such projects can be helpful to fill the gaps.
Avoid using fixes like this. |
Here's an example of such a case :
I reckon we will need to add around 10 exceptions, at first. @lahmatiy What method would you recommend for that?
What we want is to avoid rebuttals/refusals/delays on csstree's side. The goal is to have the lowest number of steps.
This is great to hear.
If you have a list for values specifically, please provide it. |
@lahmatiy Thank you for chiming in and explaining everything so clearly. It's fantastic that you're open to collaboration. I think we can bring more awareness to your work on dictionaries, usage and syntax as Stylelint is often the entry point to CSS tooling for people. This will hopefully lead to more people contributing to the dictionary (and even the possibility of it becoming a separate project). I typically use your syntax reference website when proposing new rules for Stylelint and I think it's great!
I agree. Out of curiosity, is It sounds like we can:
Am I right about the last one? Is that what you meant with:
I agree with @ybiquitous when he said:
The rule will benefit most people and we now have an outline for handling future syntaxes and edge cases. |
I touched on this in #6376 (comment). The rule also overlaps with We could either leave the rules in, deprecate them or limit them to at-rules. (The latter opens up a broader discussion about a new We can leave them in for now to keep things simple. We already have overlapping rules, e.g. all the |
We won't be able to deprecate them right away.
IMHO we should keep them as is.
👍 |
Thanks a lot, everyone. It's great to hear about this open collaboration! 🙌🏼 So now, I'd like to hear your thoughts on whether we should include this Because this collaboration will likely take more time and the rule is duplicated with rules like |
We usually have at least one release per month; January was release-less. |
I've skipped a |
What I can do now is finished. Please mention me if more work comes. |
|
||
// NOTE: CSSTree's `fork()` doesn't support `-moz-initial`, but it may be possible in the future. | ||
// See https://github.com/stylelint/stylelint/pull/6511#issuecomment-1412921062 | ||
if (/^-moz-initial$/i.test(value)) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wait for csstree/csstree#243 to settle on this.
Iv done the PRs that I was talking about in #6511 (comment). The
i.e.
Hence Ill postpone it. |
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
{ | ||
// TODO: CSSTree doesn't support math functions like `clamp()` yet, but the future update will support them. | ||
// See https://github.com/stylelint/stylelint/pull/6511#issuecomment-1412921062 | ||
skip: true, | ||
code: 'a { font-size: clamp(1rem, 1vw + 1rem, 3rem); }', | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's favour false negatives over positives.
If we can't use fork()
in this instance, let's return early if we find a clamp
, min
or max
function in the value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing the nice way to find functions. Fixed via 9317140.
@ybiquitous & @Mouvedia Thank you for making commits or pull requests here elsewhere. I've pushed a commit 5872036 to update the docs to address suggestions in #6511 (comment) & #6511 (comment). I've made one suggestion. Otherwise, I think we're almost there! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, everyone. LGTM 👍🏼
I believe we can later apply the patches by @Mouvedia that CSSTree will include.
+ matchProperty(propertyName: string, value: string): MatchResult; | ||
+} | ||
+ | ||
+export function fork(extension: Record<string, Record<string, string>>): { lexer: Lexer }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll request this change to the upstream @types/css-tree
package later.
Thanks, everyone. Looks good enough for me too. |
What I was afraid of has happened. |
@lahmatiy What do you think about delegating CSSTree's maintenance to someone passionate? Since CSSTree is a great product, I believe people in the front-end community hope to make CSSTree sustainable. |
@ybiquitous in the meantime what about forking the repo and using a github branch as a dependency ? |
@Mouvedia Um, it may be better at this point.
|
Now that becomes annoying. It would require to use GitHub actions to build it every time a PR is merged.
Nah that's overkill; I'd prefer waiting for the pending PRs to be merged. |
Closes #6376
I figured it'd be a good idea to include this rule in
v15
. It is a significant change in our direction to offer more validation rules and a change that counterweighs our decision to deprecate most of the stylistic rules. It'll be useful for people to see that in our migration guide. Additionally, the rule is doing a lot and will flag problems for people using values not defined in the CSS specifications. We can help these people by including an entry in the migration guideAs discussed in #6376 (comment), the scoped is limited to checking for mismatched property-value pairs.
Most test cases come from issues people have opened in our tracker over the years.
I've marked as draft as I'm unsure about two things:
is-plain-object
importAny advice?