Skip to content
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

📎 Implement stylelint/no-descending-specificity #2810

Closed
Tracked by #2511
togami2864 opened this issue May 10, 2024 · 8 comments · Fixed by #4097
Closed
Tracked by #2511

📎 Implement stylelint/no-descending-specificity #2810

togami2864 opened this issue May 10, 2024 · 8 comments · Fixed by #4097
Assignees
Labels
A-Analyzer Area: analyzer A-Linter Area: linter L-CSS Language: CSS S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@togami2864
Copy link
Contributor

togami2864 commented May 10, 2024

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.

@togami2864 togami2864 added S-Help-wanted Status: you're familiar with the code base and want to help the project A-Linter Area: linter L-CSS Language: CSS A-Analyzer Area: analyzer labels May 10, 2024
@Conaclos Conaclos changed the title 📎 Implement no-descending-specificity 📎 Implement stylelintno-descending-specificity Sep 16, 2024
@tunamaguro
Copy link
Contributor

Hi, Can I work on this?

@dyc3
Copy link
Contributor

dyc3 commented Sep 24, 2024

Absolutely, assigned.

@Conaclos Conaclos changed the title 📎 Implement stylelintno-descending-specificity 📎 Implement stylelint/no-descending-specificity Sep 24, 2024
@tunamaguro
Copy link
Contributor

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.

#[derive(Clone, PartialEq, Eq, Hash, Serialize)]
pub enum AnyCssSelector {
CssBogusSelector(CssBogusSelector),
CssComplexSelector(CssComplexSelector),
CssCompoundSelector(CssCompoundSelector),
CssMetavariable(CssMetavariable),
}

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.

},
colon_token: COLON@16..18 ":" [] [Whitespace(" ")],
value: CssGenericComponentValueList [
CssMetavariable {
value_token: GRIT_METAVARIABLE@18..25 "µcolor" [] [],
},
],

@ematipico
Copy link
Member

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

/// Represents a CSS selector.
/// /// ```css
/// span {
/// ^^^^
/// color: red;
/// }
/// ```
#[derive(Debug, Clone)]
pub struct Selector {
/// The name of the selector.
pub name: String,
/// The text range of the selector in the source document.
pub range: TextRange,
/// The specificity of the selector.
pub specificity: Specificity,
}

@tunamaguro
Copy link
Contributor

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

@tunamaguro
Copy link
Contributor

tunamaguro commented Sep 25, 2024

I realized that the specificity calculation has not been implemented yet.

fn add_selector_event(&mut self, name: Cow<str>, range: TextRange) {
self.stash.push_back(SemanticEvent::SelectorDeclaration {
name: name.into_owned(),
range,
specificity: Specificity(0, 0, 0), // TODO: Implement this
});
}

Is there anyone already working on this implementation? If not, I would like to give it a try.

@ematipico
Copy link
Member

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

@tunamaguro
Copy link
Contributor

Okay, I'll try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Analyzer Area: analyzer A-Linter Area: linter L-CSS Language: CSS S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants