-
-
Notifications
You must be signed in to change notification settings - Fork 541
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 formatting for predicate assignment and predic…
…ate and (#4238)
- Loading branch information
Showing
5 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
23 changes: 21 additions & 2 deletions
23
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
use crate::prelude::*; | ||
use biome_grit_syntax::GritPredicateAnd; | ||
use biome_formatter::write; | ||
use biome_grit_syntax::{GritPredicateAnd, GritPredicateAndFields}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatGritPredicateAnd; | ||
impl FormatNodeRule<GritPredicateAnd> for FormatGritPredicateAnd { | ||
fn fmt_fields(&self, node: &GritPredicateAnd, f: &mut GritFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let GritPredicateAndFields { | ||
l_curly_token, | ||
and_token, | ||
predicates, | ||
r_curly_token, | ||
} = node.as_fields(); | ||
write!( | ||
f, | ||
[ | ||
l_curly_token.format(), | ||
hard_line_break(), | ||
and_token.format(), | ||
hard_line_break(), | ||
soft_block_indent(&predicates.format()), | ||
hard_line_break(), | ||
r_curly_token.format() | ||
] | ||
) | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
crates/biome_grit_formatter/tests/specs/grit/predicates/assignment.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,2 @@ | ||
`console.log($message)` as $log where{ | ||
$new_log_call=`logger.log($message)`} |
39 changes: 39 additions & 0 deletions
39
crates/biome_grit_formatter/tests/specs/grit/predicates/assignment.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,39 @@ | ||
--- | ||
source: crates/biome_formatter_test/src/snapshot_builder.rs | ||
info: grit/predicates/assignment.grit | ||
--- | ||
# Input | ||
|
||
```grit | ||
`console.log($message)` as $log where{ | ||
$new_log_call=`logger.log($message)`} | ||
``` | ||
|
||
|
||
============================= | ||
|
||
# Outputs | ||
|
||
## Output 1 | ||
|
||
----- | ||
Indent style: Tab | ||
Indent width: 2 | ||
Line ending: LF | ||
Line width: 80 | ||
Attribute Position: Auto | ||
----- | ||
|
||
```grit | ||
`console.log($message)` as $log where { | ||
$new_log_call = `logger.log($message)` | ||
} | ||
``` | ||
|
||
|
||
|
||
## Unimplemented nodes/tokens | ||
|
||
"`console.log($message)` as $log " => 0..32 | ||
"\t$new_log_call" => 40..54 | ||
" `logger.log($message)" => 56..78 |