Skip to content

Commit

Permalink
fix: use view! indentation settings when formatting syn expression (#141
Browse files Browse the repository at this point in the history
)

BREAKING CHANGE: When the indentation style is set to "Tabs", the formatter will print `pending_indentation / 4` hard tabs and the remainder (`pending_indentation % 4`) in spaces.  

The `tab_spaces` configuration property specifies the indentation size _in spaces_. This means that if you want an indentation of 1 hard tab (`\t`), you need to set `indentation_style = "Tabs"` and `tab_spaces = 4` (which is already the default).
  • Loading branch information
bram209 authored Aug 31, 2024
1 parent 6f6c6b4 commit 6e050a3
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion formatter/src/formatter/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ mod tests {

#[test]
fn key_value_expr_attr_always_unless_lit_braces() {
// sinle expr without braces
// single expr without braces
let f = format_attr_with_brace_style! { AlwaysUnlessLit => on:click=move |_| set_value(0) };
assert_snapshot!(f, @"on:click={move |_| set_value(0)}");

// single expr without braces
let f = format_attr_with_brace_style! { AlwaysUnlessLit => foo=bar };
assert_snapshot!(f, @"foo={bar}");

// single expr with braces
let f =
format_attr_with_brace_style! { AlwaysUnlessLit => on:click={move |_| set_value(0)} };
Expand Down
4 changes: 2 additions & 2 deletions formatter/src/formatter/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ mod tests {
let formatted = format_element_from_string!(indoc! {"
<div key=a
// width
width=100></div>
width=100></div>
"});

insta::assert_snapshot!(formatted, @r###"
Expand Down Expand Up @@ -361,7 +361,7 @@ mod tests {
let formatted = format_element_from_string!(indoc! {"
<div>
Unquoted text
with spaces
with spaces
</div>
"});

Expand Down
5 changes: 1 addition & 4 deletions formatter/src/formatter/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,9 @@ impl Formatter<'_> {

#[cfg(test)]
mod tests {
use rstml::node::Node;

use crate::formatter::*;
use crate::test_helpers::{
element, element_from_string, format_element_from_string, format_with,
};
use crate::test_helpers::format_element_from_string;

macro_rules! format_element {

Check warning on line 160 in formatter/src/formatter/expr.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused macro definition: `format_element`
($($tt:tt)*) => {{
Expand Down
Loading

0 comments on commit 6e050a3

Please sign in to comment.