Skip to content

Commit

Permalink
feat(format/grit): add formatting for predicate assignment and predic…
Browse files Browse the repository at this point in the history
…ate and (#4238)
  • Loading branch information
branberry authored Oct 10, 2024
1 parent 6e69622 commit fbe5552
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 7 deletions.
23 changes: 21 additions & 2 deletions crates/biome_grit_formatter/src/grit/predicates/predicate_and.rs
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()
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_grit_syntax::GritPredicateAssignment;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritPredicateAssignment, GritPredicateAssignmentFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritPredicateAssignment;
impl FormatNodeRule<GritPredicateAssignment> for FormatGritPredicateAssignment {
Expand All @@ -9,6 +10,21 @@ impl FormatNodeRule<GritPredicateAssignment> for FormatGritPredicateAssignment {
node: &GritPredicateAssignment,
f: &mut GritFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritPredicateAssignmentFields {
container,
eq_token,
pattern,
} = node.as_fields();

write!(
f,
[
container.format(),
space(),
eq_token.format(),
space(),
pattern.format()
]
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Attribute Position: Auto

```grit
`$method('$message')` where {
}
```

Expand All @@ -37,4 +36,3 @@ Attribute Position: Auto
## Unimplemented nodes/tokens

"`$method('$message')`" => 0..21
" {\n\n" => 27..31
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)`}
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

0 comments on commit fbe5552

Please sign in to comment.