Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(format/grit): add formatting for predicate assignment and predicate and #4238

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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