-
-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(format/grit): add basic formatting for where pattern (#4095)
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Antony David <antonydavid945@gmail.com> Co-authored-by: Victorien Elvinger <victorien@elvinger.fr> Co-authored-by: matsuura <79092292+tunamaguro@users.noreply.github.com>
- Loading branch information
1 parent
c97a4af
commit d7cc01f
Showing
16 changed files
with
217 additions
and
93 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
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
23 changes: 20 additions & 3 deletions
23
crates/biome_grit_formatter/src/grit/patterns/pattern_where.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 |
---|---|---|
@@ -1,10 +1,27 @@ | ||
use crate::prelude::*; | ||
use biome_grit_syntax::GritPatternWhere; | ||
use biome_rowan::AstNode; | ||
use biome_formatter::write; | ||
use biome_grit_syntax::{GritPatternWhere, GritPatternWhereFields}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatGritPatternWhere; | ||
impl FormatNodeRule<GritPatternWhere> for FormatGritPatternWhere { | ||
fn fmt_fields(&self, node: &GritPatternWhere, f: &mut GritFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let GritPatternWhereFields { | ||
pattern, | ||
side_condition, | ||
where_token, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
space(), | ||
pattern.format(), | ||
space(), | ||
where_token.format(), | ||
space(), | ||
side_condition.format(), | ||
] | ||
) | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
crates/biome_grit_formatter/src/grit/predicates/predicate_and.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
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
7 changes: 0 additions & 7 deletions
7
crates/biome_grit_formatter/tests/specs/grit/patterns/if_pattern.grit
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
crates/biome_grit_formatter/tests/specs/grit/patterns/if_pattern.grit.snap
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
crates/biome_grit_formatter/tests/specs/grit/patterns/where_pattern.grit
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,3 @@ | ||
`$method('$message')`where{ | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
crates/biome_grit_formatter/tests/specs/grit/patterns/where_pattern.grit.snap
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,40 @@ | ||
--- | ||
source: crates/biome_formatter_test/src/snapshot_builder.rs | ||
info: grit/patterns/where_pattern.grit | ||
--- | ||
# Input | ||
|
||
```grit | ||
`$method('$message')`where{ | ||
} | ||
``` | ||
|
||
|
||
============================= | ||
|
||
# Outputs | ||
|
||
## Output 1 | ||
|
||
----- | ||
Indent style: Tab | ||
Indent width: 2 | ||
Line ending: LF | ||
Line width: 80 | ||
Attribute Position: Auto | ||
----- | ||
|
||
```grit | ||
`$method('$message')` where { | ||
} | ||
``` | ||
|
||
|
||
|
||
## Unimplemented nodes/tokens | ||
|
||
"`$method('$message')`" => 0..21 | ||
" {\n\n" => 27..31 |
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.