Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-cases-lead.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#5981](https://github.com/biomejs/biome/issues/5981), where `noUnknownPseudoClass` didn't take `:global` into consideration when `cssModules` is enabled.
7 changes: 7 additions & 0 deletions crates/biome_analyze/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct RuleContext<'a, R: Rule> {
preferred_quote: &'a PreferredQuote,
preferred_jsx_quote: &'a PreferredQuote,
jsx_runtime: Option<JsxRuntime>,
css_modules: bool,
}

impl<'a, R> RuleContext<'a, R>
Expand All @@ -36,6 +37,7 @@ where
preferred_quote: &'a PreferredQuote,
preferred_jsx_quote: &'a PreferredQuote,
jsx_runtime: Option<JsxRuntime>,
css_modules: bool,
) -> Result<Self, Error> {
let rule_key = RuleKey::rule::<R>();
Ok(Self {
Expand All @@ -49,6 +51,7 @@ where
preferred_quote,
preferred_jsx_quote,
jsx_runtime,
css_modules,
})
}

Expand Down Expand Up @@ -176,6 +179,10 @@ where
self.preferred_jsx_quote
}

pub fn is_css_modules(&self) -> bool {
self.css_modules
}

/// Attempts to retrieve a service from the current context
///
/// ```no_test
Expand Down
18 changes: 15 additions & 3 deletions crates/biome_analyze/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,22 @@ pub struct AnalyzerConfiguration {
/// A list of rules and their options
pub(crate) rules: AnalyzerRules,

/// A collections of bindings that the analyzers should consider as "external".
/// A collection of bindings that the analyzers should consider as "external".
///
/// For example, lint rules should ignore them.
globals: Vec<Box<str>>,

/// Allows to choose a different quote when applying fixes inside the lint rules
/// Allows choosing a different quote when applying fixes inside the lint rules
preferred_quote: PreferredQuote,

/// Allows to choose a different JSX quote when applying fixes inside the lint rules
/// Allows choosing a different JSX quote when applying fixes inside the lint rules
pub preferred_jsx_quote: PreferredQuote,

/// Indicates the type of runtime or transformation used for interpreting JSX.
jsx_runtime: Option<JsxRuntime>,

/// Whether the CSS files contain CSS Modules
css_modules: bool,
}

impl AnalyzerConfiguration {
Expand Down Expand Up @@ -98,6 +101,11 @@ impl AnalyzerConfiguration {
self.preferred_jsx_quote = preferred_jsx_quote;
self
}

pub fn with_css_modules(mut self, css_modules: bool) -> Self {
self.css_modules = css_modules;
self
}
}

/// A set of information useful to the analyzer infrastructure
Expand Down Expand Up @@ -171,6 +179,10 @@ impl AnalyzerOptions {
pub fn preferred_jsx_quote(&self) -> &PreferredQuote {
&self.configuration.preferred_jsx_quote
}

pub fn css_modules(&self) -> bool {
self.configuration.css_modules
}
}

#[derive(Debug, Default)]
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_analyze/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ impl<L: Language + Default> RegistryRule<L> {
let preferred_quote = params.options.preferred_quote();
let preferred_jsx_quote = params.options.preferred_jsx_quote();
let jsx_runtime = params.options.jsx_runtime();
let css_modules = params.options.css_modules();
let options = params.options.rule_options::<R>().unwrap_or_default();
let ctx = RuleContext::new(
&query_result,
Expand All @@ -418,6 +419,7 @@ impl<L: Language + Default> RegistryRule<L> {
preferred_quote,
preferred_jsx_quote,
jsx_runtime,
css_modules,
)?;

for result in R::run(&ctx) {
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_analyze/src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ where
preferred_quote,
preferred_jsx_quote,
self.options.jsx_runtime(),
self.options.css_modules(),
)
.ok()?;

Expand Down Expand Up @@ -403,6 +404,7 @@ where
self.options.preferred_quote(),
self.options.preferred_jsx_quote(),
self.options.jsx_runtime(),
self.options.css_modules(),
)
.ok();
let mut actions = Vec::new();
Expand Down Expand Up @@ -466,6 +468,7 @@ where
self.options.preferred_quote(),
self.options.preferred_jsx_quote(),
self.options.jsx_runtime(),
self.options.css_modules(),
)
.ok();
if let Some(ctx) = ctx {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ impl Rule for NoUnknownPseudoClass {

fn run(ctx: &RuleContext<Self>) -> Option<Self::State> {
let pseudo_class = ctx.query();
let is_css_modules = ctx.is_css_modules();
let span = pseudo_class.name_range()?;
let name = pseudo_class.name()?;

Expand Down Expand Up @@ -221,7 +222,9 @@ impl Rule for NoUnknownPseudoClass {
}
};

if is_valid_class {
let is_valid_global = lower_name == "global" && is_css_modules;

if is_valid_class || is_valid_global {
None
} else {
Some(NoUnknownPseudoClassSelectorState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ b > .foo:error { }
:placeholder {}
@page :blank:unknown { }
@page foo:unknown { }
:horizontal:decrement {}
:horizontal:decrement {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ b > .foo:error { }
@page :blank:unknown { }
@page foo:unknown { }
:horizontal:decrement {}

```

# Diagnostics
Expand Down Expand Up @@ -216,6 +217,7 @@ invalid.css:16:2 lint/correctness/noUnknownPseudoClass ━━━━━━━━
15 │ @page foo:unknown { }
> 16 │ :horizontal:decrement {}
│ ^^^^^^^^^^
17 │

i See MDN web docs for more details.

Expand All @@ -231,6 +233,7 @@ invalid.css:16:13 lint/correctness/noUnknownPseudoClass ━━━━━━━━
15 │ @page foo:unknown { }
> 16 │ :horizontal:decrement {}
│ ^^^^^^^^^
17 │

i See MDN web docs for more details.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* should not generate diagnostics */
.meow :global(.global) {
color: blue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/biome_css_analyze/tests/spec_tests.rs
expression: validGlobal.css
---
# Input
```css
/* should not generate diagnostics */
.meow :global(.global) {
color: blue;
}

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"css": {
"parser": {
"cssModules": true
}
}
}
11 changes: 9 additions & 2 deletions crates/biome_service/src/file_handlers/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ impl ServiceLanguage for CssLanguage {

fn resolve_analyzer_options(
global: Option<&Settings>,

_language: Option<&Self::LinterSettings>,
_environment: Option<&Self::EnvironmentSettings>,

Expand Down Expand Up @@ -217,7 +216,15 @@ impl ServiceLanguage for CssLanguage {
.map(|g| to_analyzer_rules(g, file_path.as_path()))
.unwrap_or_default(),
)
.with_preferred_quote(preferred_quote);
.with_preferred_quote(preferred_quote)
.with_css_modules(global.is_some_and(|global| {
global
.languages
.css
.parser
.css_modules_enabled
.is_some_and(|css_modules_enabled| css_modules_enabled.into())
}));

AnalyzerOptions::default()
.with_file_path(file_path.as_path())
Expand Down