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(grit): add formatting of more nodes #4472

Merged
merged 1 commit into from
Nov 5, 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
21 changes: 20 additions & 1 deletion crates/biome_grit_formatter/src/grit/auxiliary/sequential.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
use crate::prelude::*;
use biome_grit_syntax::GritSequential;
use biome_rowan::AstNode;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritSequential;
impl FormatNodeRule<GritSequential> for FormatGritSequential {
fn fmt_fields(&self, node: &GritSequential, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)

// TODO: investigate the verbatim panic when this code runs
// let GritSequentialFields {
// l_curly_token,
// sequential_token,
// sequential,
// r_curly_token,
// } = node.as_fields();
//
// write!(
// f,
// [
// sequential_token.format(),
// space(),
// l_curly_token.format(),
// sequential.format(),
// r_curly_token.format()
// ]
// )
}
}
24 changes: 21 additions & 3 deletions crates/biome_grit_formatter/src/grit/patterns/pattern_and.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
use crate::prelude::*;
use biome_grit_syntax::GritPatternAnd;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritPatternAnd, GritPatternAndFields};
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritPatternAnd;
impl FormatNodeRule<GritPatternAnd> for FormatGritPatternAnd {
fn fmt_fields(&self, node: &GritPatternAnd, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritPatternAndFields {
patterns,
and_token,
l_curly_token,
r_curly_token,
} = node.as_fields();

write!(
f,
[
and_token.format(),
space(),
l_curly_token.format(),
space(),
patterns.format(),
space(),
r_curly_token.format()
]
)
}
}
19 changes: 16 additions & 3 deletions crates/biome_grit_formatter/src/grit/patterns/pattern_contains.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
use crate::prelude::*;
use biome_grit_syntax::GritPatternContains;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritPatternContains, GritPatternContainsFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritPatternContains;
impl FormatNodeRule<GritPatternContains> for FormatGritPatternContains {
fn fmt_fields(&self, node: &GritPatternContains, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritPatternContainsFields {
contains,
contains_token,
until_clause,
} = node.as_fields();

write!(f, [contains_token.format(), space(), contains.format()])?;

if let Some(until_clause) = until_clause {
write!(f, [space(), until_clause.format()])?;
}

Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
use crate::prelude::*;
use biome_grit_syntax::GritCurlyPredicateList;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritCurlyPredicateList, GritCurlyPredicateListFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritCurlyPredicateList;
impl FormatNodeRule<GritCurlyPredicateList> for FormatGritCurlyPredicateList {
fn fmt_fields(&self, node: &GritCurlyPredicateList, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritCurlyPredicateListFields {
predicates,
r_curly_token,
l_curly_token,
} = node.as_fields();

write!(
f,
[
l_curly_token.format(),
predicates.format(),
r_curly_token.format()
]
)
}
}
24 changes: 21 additions & 3 deletions crates/biome_grit_formatter/src/grit/predicates/predicate_any.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
use crate::prelude::*;
use biome_grit_syntax::GritPredicateAny;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritPredicateAny, GritPredicateAnyFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritPredicateAny;
impl FormatNodeRule<GritPredicateAny> for FormatGritPredicateAny {
fn fmt_fields(&self, node: &GritPredicateAny, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritPredicateAnyFields {
any_token,
l_curly_token,
predicates,
r_curly_token,
} = node.as_fields();
write!(
f,
[
l_curly_token.format(),
hard_line_break(),
any_token.format(),
hard_line_break(),
soft_block_indent(&predicates.format()),
hard_line_break(),
r_curly_token.format()
]
)
}
}
21 changes: 18 additions & 3 deletions crates/biome_grit_formatter/src/grit/predicates/predicate_call.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
use crate::prelude::*;
use biome_grit_syntax::GritPredicateCall;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritPredicateCall, GritPredicateCallFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritPredicateCall;
impl FormatNodeRule<GritPredicateCall> for FormatGritPredicateCall {
fn fmt_fields(&self, node: &GritPredicateCall, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritPredicateCallFields {
name,
l_paren_token,
named_args,
r_paren_token,
} = node.as_fields();
write!(
f,
[
name.format(),
l_paren_token.format(),
named_args.format(),
r_paren_token.format()
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_grit_syntax::GritBacktickSnippetLiteral;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritBacktickSnippetLiteral, GritBacktickSnippetLiteralFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritBacktickSnippetLiteral;
impl FormatNodeRule<GritBacktickSnippetLiteral> for FormatGritBacktickSnippetLiteral {
Expand All @@ -9,6 +10,7 @@ impl FormatNodeRule<GritBacktickSnippetLiteral> for FormatGritBacktickSnippetLit
node: &GritBacktickSnippetLiteral,
f: &mut GritFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritBacktickSnippetLiteralFields { value_token } = node.as_fields();
write!(f, [value_token.format()])
}
}
8 changes: 5 additions & 3 deletions crates/biome_grit_formatter/src/grit/value/boolean_literal.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::prelude::*;
use biome_grit_syntax::GritBooleanLiteral;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritBooleanLiteral, GritBooleanLiteralFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritBooleanLiteral;
impl FormatNodeRule<GritBooleanLiteral> for FormatGritBooleanLiteral {
fn fmt_fields(&self, node: &GritBooleanLiteral, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritBooleanLiteralFields { value } = node.as_fields();
write!(f, [value.format()])
}
}
8 changes: 5 additions & 3 deletions crates/biome_grit_formatter/src/grit/value/code_snippet.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::prelude::*;
use biome_grit_syntax::GritCodeSnippet;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritCodeSnippet, GritCodeSnippetFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritCodeSnippet;
impl FormatNodeRule<GritCodeSnippet> for FormatGritCodeSnippet {
fn fmt_fields(&self, node: &GritCodeSnippet, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritCodeSnippetFields { source } = node.as_fields();
write!(f, [source.format()])
}
}
8 changes: 5 additions & 3 deletions crates/biome_grit_formatter/src/grit/value/double_literal.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::prelude::*;
use biome_grit_syntax::GritDoubleLiteral;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritDoubleLiteral, GritDoubleLiteralFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritDoubleLiteral;
impl FormatNodeRule<GritDoubleLiteral> for FormatGritDoubleLiteral {
fn fmt_fields(&self, node: &GritDoubleLiteral, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritDoubleLiteralFields { value_token } = node.as_fields();
write!(f, [value_token.format()])
}
}
8 changes: 5 additions & 3 deletions crates/biome_grit_formatter/src/grit/value/int_literal.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::prelude::*;
use biome_grit_syntax::GritIntLiteral;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritIntLiteral, GritIntLiteralFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritIntLiteral;
impl FormatNodeRule<GritIntLiteral> for FormatGritIntLiteral {
fn fmt_fields(&self, node: &GritIntLiteral, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritIntLiteralFields { value_token } = node.as_fields();
write!(f, [value_token.format()])
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::prelude::*;
use biome_grit_syntax::GritNegativeIntLiteral;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritNegativeIntLiteral, GritNegativeIntLiteralFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritNegativeIntLiteral;
impl FormatNodeRule<GritNegativeIntLiteral> for FormatGritNegativeIntLiteral {
fn fmt_fields(&self, node: &GritNegativeIntLiteral, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritNegativeIntLiteralFields { value_token } = node.as_fields();
write!(f, [value_token.format()])
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_grit_syntax::GritRawBacktickSnippetLiteral;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritRawBacktickSnippetLiteral, GritRawBacktickSnippetLiteralFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritRawBacktickSnippetLiteral;
impl FormatNodeRule<GritRawBacktickSnippetLiteral> for FormatGritRawBacktickSnippetLiteral {
Expand All @@ -9,6 +10,7 @@ impl FormatNodeRule<GritRawBacktickSnippetLiteral> for FormatGritRawBacktickSnip
node: &GritRawBacktickSnippetLiteral,
f: &mut GritFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritRawBacktickSnippetLiteralFields { value_token } = node.as_fields();
write!(f, [value_token.format()])
}
}
8 changes: 5 additions & 3 deletions crates/biome_grit_formatter/src/grit/value/regex_literal.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::prelude::*;
use biome_grit_syntax::GritRegexLiteral;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritRegexLiteral, GritRegexLiteralFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritRegexLiteral;
impl FormatNodeRule<GritRegexLiteral> for FormatGritRegexLiteral {
fn fmt_fields(&self, node: &GritRegexLiteral, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritRegexLiteralFields { value_token } = node.as_fields();
write!(f, [value_token.format()])
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;
use biome_grit_syntax::GritSnippetRegexLiteral;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritSnippetRegexLiteral, GritSnippetRegexLiteralFields};
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritSnippetRegexLiteral;
impl FormatNodeRule<GritSnippetRegexLiteral> for FormatGritSnippetRegexLiteral {
Expand All @@ -9,6 +9,7 @@ impl FormatNodeRule<GritSnippetRegexLiteral> for FormatGritSnippetRegexLiteral {
node: &GritSnippetRegexLiteral,
f: &mut GritFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritSnippetRegexLiteralFields { value_token } = node.as_fields();
write!(f, [value_token.format()])
}
}
8 changes: 5 additions & 3 deletions crates/biome_grit_formatter/src/grit/value/string_literal.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::prelude::*;
use biome_grit_syntax::GritStringLiteral;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritStringLiteral, GritStringLiteralFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritStringLiteral;
impl FormatNodeRule<GritStringLiteral> for FormatGritStringLiteral {
fn fmt_fields(&self, node: &GritStringLiteral, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritStringLiteralFields { value_token } = node.as_fields();
write!(f, [value_token.format()])
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::prelude::*;
use biome_grit_syntax::GritUndefinedLiteral;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritUndefinedLiteral, GritUndefinedLiteralFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritUndefinedLiteral;
impl FormatNodeRule<GritUndefinedLiteral> for FormatGritUndefinedLiteral {
fn fmt_fields(&self, node: &GritUndefinedLiteral, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritUndefinedLiteralFields { token_token } = node.as_fields();
write!(f, [token_token.format()])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
`function ($args) { $body }` where { $args <: contains `x` }

`console.$_($content)` where { $content <: contains `secret` until `sanitized($_)` }
Loading