Format shebangs correctly

Fixes the regression I described in [#1135].

[#1135]: https://github.com/roc-lang/roc/issues/1135
This commit is contained in:
Evan Relf 2024-06-19 15:02:29 -07:00
parent a55be77509
commit d678f1c049

View file

@ -149,6 +149,14 @@ pub fn fmt_comments_only<'a, 'buf, I>(
}
fn fmt_comment(buf: &mut Buf, comment: &str) {
// Format shebangs without whitespace. We look for " !" as well to fix incorrect formatting from
// the past.
if buf.is_empty() && (comment.starts_with('!') || comment.starts_with(" !")) {
buf.push('#');
buf.push_str(comment.trim());
return;
}
// The '#' in a comment should always be preceded by a newline or a space,
// unless it's the very beginning of the buffer.
if !buf.is_empty() && !buf.ends_with_space() && !buf.ends_with_newline() {