Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
refactor: Use LineSuffixBoundary to bound inline comments
Browse files Browse the repository at this point in the history
Use the `LineSuffixBoundary` for comments instead of having a special case for `LineSuffix` in flat mode.
  • Loading branch information
Micha Reiser authored and MichaReiser committed May 18, 2022
1 parent 9deb82c commit c1b267a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
8 changes: 1 addition & 7 deletions crates/rome_formatter/src/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ fn fits_on_line<'a>(
pending_indent: printer.state.pending_indent,
pending_space: printer.state.pending_space,
line_width: printer.state.line_width,
has_line_suffix: printer.state.line_suffixes.len() > 0,
has_line_suffix: !printer.state.line_suffixes.is_empty(),
};

let result = loop {
Expand Down Expand Up @@ -747,12 +747,6 @@ fn fits_element_on_line<'a, 'rest>(
}

FormatElement::LineSuffix(_) => {
// The current behavior is to return `false` for all line suffixes if trying to print
// something in "flat" mode.
if args.mode.is_flat() {
return Fits::No;
}

state.has_line_suffix = true;
}

Expand Down
5 changes: 4 additions & 1 deletion crates/rome_js_formatter/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ where
]),
]
} else {
line_suffix(format_elements![space_token(), comment, space_token()])
format_elements![
line_suffix(format_elements![space_token(), comment]),
expand_parent()
]
};

elements.push(crate::comment(content));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl FormatNodeFields<JsAssignmentExpression> for FormatNodeRule<JsAssignmentExp
left.format(),
space_token(),
operator_token.format(),
line_suffix_boundary(),
group_elements(soft_line_indent_or_space(formatted![
formatter,
[right.format()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl FormatNodeFields<JsxExpressionAttributeValue> for FormatNodeRule<JsxExpress
[
l_curly_token.format(),
formatted_expression,
line_suffix_boundary(),
r_curly_token.format(),
]
]?))
Expand Down

0 comments on commit c1b267a

Please sign in to comment.