-
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grit): add formatting of more nodes
- Loading branch information
Showing
36 changed files
with
990 additions
and
92 deletions.
There are no files selected for viewing
21 changes: 20 additions & 1 deletion
21
crates/biome_grit_formatter/src/grit/auxiliary/sequential.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,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
24
crates/biome_grit_formatter/src/grit/patterns/pattern_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,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
19
crates/biome_grit_formatter/src/grit/patterns/pattern_contains.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,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(()) | ||
} | ||
} |
20 changes: 17 additions & 3 deletions
20
crates/biome_grit_formatter/src/grit/predicates/curly_predicate_list.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,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
24
crates/biome_grit_formatter/src/grit/predicates/predicate_any.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,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
21
crates/biome_grit_formatter/src/grit/predicates/predicate_call.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,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() | ||
] | ||
) | ||
} | ||
} |
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
8 changes: 5 additions & 3 deletions
8
crates/biome_grit_formatter/src/grit/value/boolean_literal.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,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()]) | ||
} | ||
} |
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,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()]) | ||
} | ||
} |
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,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()]) | ||
} | ||
} |
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,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()]) | ||
} | ||
} |
8 changes: 5 additions & 3 deletions
8
crates/biome_grit_formatter/src/grit/value/negative_int_literal.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,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()]) | ||
} | ||
} |
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
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()]) | ||
} | ||
} |
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
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()]) | ||
} | ||
} |
8 changes: 5 additions & 3 deletions
8
crates/biome_grit_formatter/src/grit/value/undefined_literal.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,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()]) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
crates/biome_grit_formatter/tests/specs/grit/patterns/contains.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 @@ | ||
`function ($args) { $body }` where { $args <: contains `x` } | ||
|
||
`console.$_($content)` where { $content <: contains `secret` until `sanitized($_)` } |
Oops, something went wrong.