Skip to content

Commit

Permalink
Merge pull request #456 from flying-sheep/fix-comment-with-bracket
Browse files Browse the repository at this point in the history
  • Loading branch information
panekj committed Aug 19, 2023
2 parents d363946 + cb156c3 commit 051ce9f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
6 changes: 2 additions & 4 deletions crates/taplo/src/formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,10 +1106,8 @@ fn format_array(node: SyntaxNode, options: &Options, context: &Context) -> impl
skip_newlines = 0;
}

if !formatted.ends_with(']') {
formatted
.extend(options.newlines(newline_count.saturating_sub(skip_newlines)));
}
formatted
.extend(options.newlines(newline_count.saturating_sub(skip_newlines)));
}
COMMENT => {
let newline_before = t
Expand Down
23 changes: 23 additions & 0 deletions crates/taplo/src/tests/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,3 +1108,26 @@ my_array = [

assert_format!(expected, &formatted);
}

#[test]
fn test_comment_with_brackets() {
let src = r#"
my_array = [
# [x]
"y",
]
"#;

let expected = r#"
my_array = [
# [x]
"y",
]
"#;

let formatted = crate::formatter::format(
src, Default::default()
);

assert_format!(expected, &formatted);
}

0 comments on commit 051ce9f

Please sign in to comment.