biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
15.42k stars 478 forks source link

📎 Implement `stylelint/no-descending-specificity` #2810

Closed togami2864 closed 1 month ago

togami2864 commented 6 months ago

Description

Implement no-descending-specificity

[!IMPORTANT]

  • Please skip implementing options for now since we will evaluate users actually want them later.
  • Please ignore handling extended CSS language cases such as sass and less.
  • Please skip custom function since we haven't syntax model yet.

Want to contribute? Lets you know you are interested! We will assign you to the issue to prevent several people to work on the same issue. Don't worry, we can unassign you later if you are no longer interested in the issue! Read our contributing guide and analyzer contributing guide.

tunamaguro commented 1 month ago

Hi, Can I work on this?

dyc3 commented 1 month ago

Absolutely, assigned.

tunamaguro commented 1 month ago

I have a question.

In the process of implementing this feature, I started by creating a function to calculate the specificity of CSS selectors. During this process, I noticed that there is something called CssMetavariable within AnyCssSelector. https://github.com/biomejs/biome/blob/ab0f96ea51a576456a6aa7c439bc292d61a0ec42/crates/biome_css_syntax/src/generated/nodes.rs#L8285-L8291

Since I'm not very familiar with CSS, I'm unsure how to handle the specificity calculation for CssMetavariable. Could you please advise me on how to process the specificity of CssMetavariable?

I found where it is used, but I don't fully understand what it represents. https://github.com/biomejs/biome/blob/ab0f96ea51a576456a6aa7c439bc292d61a0ec42/crates/biome_css_parser/tests/css_test_suite/ok/grit_metavariable/metavar.css.snap#L55-L61

ematipico commented 1 month ago

The specificity of selectors should be already available in the semantic model

https://github.com/biomejs/biome/blob/d03c6cd029dd273ba6a3a270ab82e7f02b24b8d5/crates/biome_css_semantic/src/semantic_model/model.rs#L113-L128

tunamaguro commented 1 month ago

I completely missed that... Thank you for letting me know!

tunamaguro commented 1 month ago

I realized that the specificity calculation has not been implemented yet. https://github.com/biomejs/biome/blob/d03c6cd029dd273ba6a3a270ab82e7f02b24b8d5/crates/biome_css_semantic/src/events.rs#L201-L207 Is there anyone already working on this implementation? If not, I would like to give it a try.

ematipico commented 1 month ago

@tunamaguro I don't think there's someone working on it, you're more than welcome to tackle it

tunamaguro commented 1 month ago

Okay, I'll try it.