-
-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(biome_css_analyzer): initilize css linter infra (#2111)
- Loading branch information
1 parent
d14a4c6
commit 98d53ae
Showing
25 changed files
with
381 additions
and
86 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
crates/biome_css_analyze/src/analyzers/nursery/no_color_invalid_hex.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
}), | ||
) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
4 changes: 4 additions & 0 deletions
4
crates/biome_css_analyze/tests/specs/nursery/noColorInvalidHex/invalid.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
p { | ||
color: red; | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ expression: invalid.css | |
--- | ||
# Input | ||
```css | ||
p { | ||
color: red; | ||
text-align: center; | ||
} | ||
``` | ||
|
||
|
5 changes: 5 additions & 0 deletions
5
crates/biome_css_analyze/tests/specs/nursery/noColorInvalidHex/valid.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* should not generate diagnostics */ | ||
p { | ||
color: red; | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.