-
-
Notifications
You must be signed in to change notification settings - Fork 512
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):
useConsistentGridAreas
- Loading branch information
Showing
12 changed files
with
212 additions
and
26 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
80 changes: 80 additions & 0 deletions
80
crates/biome_css_analyze/src/lint/nursery/use_consistent_grid_areas.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,80 @@ | ||
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic}; | ||
use biome_console::markup; | ||
use biome_css_syntax::CssGenericComponentValueList; | ||
use biome_rowan::TextRange; | ||
|
||
declare_rule! { | ||
/// Disallowing invalid named grid areas in CSS Grid Layouts. | ||
/// | ||
/// For a named grid area to be valid, all strings must define: | ||
/// | ||
/// - the same number of cell tokens | ||
/// - at least one cell token | ||
/// | ||
/// And all named grid areas that spans multiple grid cells must form a single filled-in rectangle. | ||
/// | ||
/// ## Examples | ||
/// | ||
/// ### Invalid | ||
/// | ||
/// ```css,expect_diagnostic | ||
/// a { grid-template-areas: "a a" | ||
/// "b b b"; } | ||
/// ``` | ||
/// | ||
/// ```css,expect_diagnostic | ||
/// a { grid-template-areas: "b b b" | ||
/// ""; } | ||
/// ``` | ||
/// | ||
/// ```css,expect_diagnostic | ||
/// a { grid-template-areas: "a a a" | ||
/// "a . a"; } | ||
/// ``` | ||
/// | ||
/// ### Valid | ||
/// | ||
/// ```css | ||
/// a { grid-template-areas: "a a a" | ||
/// "b b b"; } | ||
/// ``` | ||
/// | ||
/// ```css | ||
/// a { grid-template-areas: "a a a" | ||
/// "a a a"; } | ||
/// ``` | ||
/// | ||
pub UseConsistentGridAreas { | ||
version: "next", | ||
name: "useConsistentGridAreas", | ||
language: "css", | ||
recommended: false, | ||
} | ||
} | ||
|
||
impl Rule for UseConsistentGridAreas { | ||
type Query = Ast<CssGenericComponentValueList>; | ||
type State = TextRange; | ||
type Signals = Option<Self::State>; | ||
type Options = (); | ||
|
||
fn run(ctx: &RuleContext<Self>) -> Option<Self::State> { | ||
let _node = ctx.query(); | ||
None | ||
} | ||
|
||
fn diagnostic(_: &RuleContext<Self>, range: &Self::State) -> Option<RuleDiagnostic> { | ||
Some( | ||
RuleDiagnostic::new( | ||
rule_category!(), | ||
range, | ||
markup! { | ||
"Unconsitent grid areas are not allowed." | ||
}, | ||
) | ||
.note(markup! { | ||
"Consider ensuring that each row contains the same number of cell tokens and includes at least one cell token." | ||
}), | ||
) | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
crates/biome_css_analyze/tests/specs/nursery/useConsistentGridAreas/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,13 @@ | ||
a { grid-template-areas: "a a" | ||
"b b b"; } | ||
a { grid-template-areas: "b b b" | ||
""; } | ||
a { grid-template-areas: "a a a" | ||
"a . a"; } | ||
a { grid-template-areas: "o o o ," | ||
"p , p p" | ||
"q q , q"; } | ||
a { grid-template-areas: "s s t t" | ||
"s s t t" | ||
"u v v" | ||
"u u v v"; } |
22 changes: 22 additions & 0 deletions
22
crates/biome_css_analyze/tests/specs/nursery/useConsistentGridAreas/invalid.css.snap.new
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,22 @@ | ||
--- | ||
source: crates/biome_css_analyze/tests/spec_tests.rs | ||
assertion_line: 83 | ||
expression: invalid.css | ||
--- | ||
# Input | ||
```css | ||
a { grid-template-areas: "a a" | ||
"b b b"; } | ||
a { grid-template-areas: "b b b" | ||
""; } | ||
a { grid-template-areas: "a a a" | ||
"a . a"; } | ||
a { grid-template-areas: "o o o ," | ||
"p , p p" | ||
"q q , q"; } | ||
a { grid-template-areas: "s s t t" | ||
"s s t t" | ||
"u v v" | ||
"u u v v"; } | ||
|
||
``` |
11 changes: 11 additions & 0 deletions
11
crates/biome_css_analyze/tests/specs/nursery/useConsistentGridAreas/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,11 @@ | ||
a { grid-template-areas: "a a a" | ||
"b b b"; } | ||
a { grid-template-areas: "a a a" | ||
"a a a"; } | ||
a { grid-template-areas: "o o o o" | ||
"p p p p" | ||
"q q q q"; } | ||
a { grid-template-areas: "s s t t" | ||
"s s" | ||
"v v v" | ||
"u u v"; } |
Oops, something went wrong.