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

chore(linter): rename noCssEmptyBlock -> noEmptyBlock #2945

Merged
merged 4 commits into from
May 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ lint ━━━━━━━━━━━━━━━━━━━━━━━━━
# Emitted Messages

```block
input.css:1:6 lint/nursery/noCssEmptyBlock ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
input.css:1:6 lint/nursery/noEmptyBlock ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Empty blocks aren't allowed.
× An empty block isn't allowed.

> 1 │ html {}
│ ^^
Expand Down
56 changes: 28 additions & 28 deletions crates/biome_configuration/src/linter/rules.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/biome_css_analyze/src/lint/nursery.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_css_syntax::stmt_ext::CssBlockLike;
use biome_deserialize_macros::Deserializable;
use biome_rowan::AstNode;
use serde::{Deserialize, Serialize};

declare_rule! {
/// Disallow CSS empty blocks.
Expand Down Expand Up @@ -44,64 +42,24 @@ declare_rule! {
/// @media print { a { color: pink; } }
/// ```
///
/// ## Options
///
/// If false, exclude comments from being treated as content inside of a block.
///
/// ```json
/// {
/// "noCssEmptyBlock": {
/// "options": {
/// "allowComments": false
/// }
/// }
/// }
/// ```
///
pub NoCssEmptyBlock {
pub NoEmptyBlock {
version: "next",
name: "noCssEmptyBlock",
name: "noEmptyBlock",
language: "css",
recommended: true,
sources: &[RuleSource::Stylelint("no-empty-block")],
}
}

#[derive(Debug, Clone, Deserialize, Deserializable, Eq, PartialEq, Serialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct NoCssEmptyBlockOptions {
pub allow_comments: bool,
}

impl Default for NoCssEmptyBlockOptions {
fn default() -> Self {
Self {
allow_comments: true,
}
}
}

impl Rule for NoCssEmptyBlock {
impl Rule for NoEmptyBlock {
type Query = Ast<CssBlockLike>;
type State = CssBlockLike;
type Signals = Option<Self::State>;
type Options = NoCssEmptyBlockOptions;
type Options = ();

fn run(ctx: &RuleContext<Self>) -> Option<Self::State> {
let node = ctx.query();
let options = ctx.options();
let allow_comments_inside_empty_block = options.allow_comments;
if allow_comments_inside_empty_block {
let has_comments_inside_block = node.r_curly_token().ok()?.has_leading_comments()
|| node.l_curly_token().ok()?.has_trailing_comments();

if !node.is_empty() || has_comments_inside_block {
return None;
} else {
return Some(node.clone());
}
} else if node.is_empty() {
if node.is_empty() {
return Some(node.clone());
}

Expand All @@ -115,7 +73,7 @@ impl Rule for NoCssEmptyBlock {
rule_category!(),
span,
markup! {
"Empty blocks aren't allowed."
"An empty block isn't allowed."
},
)
.note(markup! {
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_css_analyze/src/options.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Loading