Skip to content

Commit

Permalink
feat(biome_css_analyzer): initilize css linter infra (#2111)
Browse files Browse the repository at this point in the history
  • Loading branch information
togami2864 authored Mar 19, 2024
1 parent d14a4c6 commit 98d53ae
Show file tree
Hide file tree
Showing 25 changed files with 381 additions and 86 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ biome_aria = { version = "0.5.7", path = "./crates/biome_aria"
biome_aria_metadata = { version = "0.5.7", path = "./crates/biome_aria_metadata" }
biome_console = { version = "0.5.7", path = "./crates/biome_console" }
biome_control_flow = { version = "0.5.7", path = "./crates/biome_control_flow" }
biome_css_analyze = { version = "0.5.7", path = "./crates/biome_css_analyze" }
biome_css_factory = { version = "0.5.7", path = "./crates/biome_css_factory" }
biome_css_formatter = { version = "0.5.7", path = "./crates/biome_css_formatter" }
biome_css_parser = { version = "0.5.7", path = "./crates/biome_css_parser" }
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_css_analyze/src/analyzers/nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

use biome_analyze::declare_group;

pub mod noop;
pub mod no_color_invalid_hex;

declare_group! {
pub Nursery {
name : "nursery" ,
rules : [
self :: noop :: Noop ,
self :: no_color_invalid_hex :: NoColorInvalidHex ,
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic};
use biome_console::markup;
use biome_css_syntax::CssDeclarationOrRuleBlock;
use biome_rowan::AstNode;

declare_rule! {
/// Succinct description of the rule.
///
/// Put context and details about the rule.
/// As a starting point, you can take the description of the corresponding _ESLint_ rule (if any).
///
/// Try to stay consistent with the descriptions of implemented rules.
///
/// Add a link to the corresponding stylelint rule (if any):
///
/// ## Examples
///
/// ### Invalid
///
/// ```css,expect_diagnostic
/// p {}
/// ```
///
/// ### Valid
///
/// ```css
/// p {
/// color: red;
/// }
/// ```
///
pub NoColorInvalidHex {
version: "next",
name: "noColorInvalidHex",
recommended: false,
}
}

impl Rule for NoColorInvalidHex {
type Query = Ast<CssDeclarationOrRuleBlock>;
type State = CssDeclarationOrRuleBlock;
type Signals = Option<Self::State>;
type Options = ();

fn run(ctx: &RuleContext<Self>) -> Option<Self::State> {
let node = ctx.query();
if node.items().into_iter().next().is_none() {
return Some(node.clone());
}
None
}

fn diagnostic(_: &RuleContext<Self>, node: &Self::State) -> Option<RuleDiagnostic> {
//
// Read our guidelines to write great diagnostics:
// https://docs.rs/biome_analyze/latest/biome_analyze/#what-a-rule-should-say-to-the-user
//
let span = node.range();
Some(
RuleDiagnostic::new(
rule_category!(),
span,
markup! {
"Unexpected empty block is not allowed"
},
)
.note(markup! {
"This note will give you more information."
}),
)
}
}
21 changes: 0 additions & 21 deletions crates/biome_css_analyze/src/analyzers/nursery/noop.rs

This file was deleted.

1 change: 1 addition & 0 deletions crates/biome_css_analyze/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod analyzers;
pub mod options;
mod registry;

pub use crate::registry::visit_registry;
Expand Down
6 changes: 6 additions & 0 deletions crates/biome_css_analyze/src/options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use crate::analyzers;

pub type NoColorInvalidHex =
<analyzers::nursery::no_color_invalid_hex::NoColorInvalidHex as biome_analyze::Rule>::Options;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
p {
color: red;
text-align: center;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ expression: invalid.css
---
# Input
```css
p {
color: red;
text-align: center;
}
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* should not generate diagnostics */
p {
color: red;
text-align: center;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ expression: valid.css
---
# Input
```css
/* should not generate diagnostics */
p {
color: red;
text-align: center;
}
```


Empty file.
Empty file.
4 changes: 3 additions & 1 deletion crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ define_categories! {
"lint/correctness/useIsNan": "https://biomejs.dev/linter/rules/use-is-nan",
"lint/correctness/useValidForDirection": "https://biomejs.dev/linter/rules/use-valid-for-direction",
"lint/correctness/useYield": "https://biomejs.dev/linter/rules/use-yield",
"lint/nursery/colorNoInvalidHex": "https://biomejs.dev/linter/rules/color-no-invalid-hex",
"lint/nursery/noApproximativeNumericConstant": "https://biomejs.dev/linter/rules/no-approximative-numeric-constant",
"lint/nursery/noBarrelFile": "https://biomejs.dev/linter/rules/no-barrel-file",
"lint/nursery/noColorInvalidHex": "https://biomejs.dev/linter/rules/no-color-invalid-hex",
"lint/nursery/noConsole": "https://biomejs.dev/linter/rules/no-console",
"lint/nursery/noDuplicateElseIf": "https://biomejs.dev/linter/rules/no-duplicate-else-if",
"lint/nursery/noDoneCallback": "https://biomejs.dev/linter/rules/no-done-callback",
"lint/nursery/noDuplicateElseIf": "https://biomejs.dev/linter/rules/no-duplicate-else-if",
"lint/nursery/noDuplicateJsonKeys": "https://biomejs.dev/linter/rules/no-duplicate-json-keys",
"lint/nursery/noDuplicateTestHooks": "https://biomejs.dev/linter/rules/no-duplicate-test-hooks",
"lint/nursery/noExcessiveNestedTestSuites": "https://biomejs.dev/linter/rules/no-excessive-nested-test-suites",
Expand Down
1 change: 1 addition & 0 deletions crates/biome_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ version = "0.0.0"
[dependencies]
biome_analyze = { workspace = true, features = ["serde"] }
biome_console = { workspace = true }
biome_css_analyze = { workspace = true }
biome_css_formatter = { workspace = true }
biome_css_parser = { workspace = true }
biome_css_syntax = { workspace = true }
Expand Down
Loading

0 comments on commit 98d53ae

Please sign in to comment.