Skip to content

Commit

Permalink
chore(linter): rename noCssEmptyBlock -> noEmptyBlock (#2945)
Browse files Browse the repository at this point in the history
  • Loading branch information
togami2864 authored May 22, 2024
1 parent 417a174 commit e64ab12
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 437 deletions.
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

0 comments on commit e64ab12

Please sign in to comment.