Skip to content

Commit

Permalink
Add suggestions
Browse files Browse the repository at this point in the history
Includes only low-hanging fruit
  • Loading branch information
cnpryer committed Aug 24, 2023
1 parent 6ea3e44 commit 9385e63
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/ruff_formatter/src/format_element/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl Format<IrFormatContext<'_>> for &[FormatElement] {
}

StartLineSuffix(_) => {
write!(f, [text("line_suffix(")])?; // TODO(cnpryer): Would it be useful to have this info in the IR display?
write!(f, [text("line_suffix(")])?; // TODO(cnpryer)
}

StartVerbatim(_) => {
Expand Down
3 changes: 0 additions & 3 deletions crates/ruff_formatter/src/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,8 +1177,6 @@ impl<'a, 'print> FitsMeasurer<'a, 'print> {
}

FormatElement::Tag(StartLineSuffix(line_suffix)) => {
// TODO(cnpryer): Need to understand the relationship between fits checks and prints.
// Not sure if I've ruled out any redundancy or if state should be handled better here.
self.state.line_width += line_suffix.reserved_width;
if self.state.line_width > self.options().print_width.into() {
return Ok(Fits::No);
Expand Down Expand Up @@ -1696,7 +1694,6 @@ two lines`,
);
}

// TODO(cnpryer): Would it make sense to add a test to the printer for measured line suffix?
#[test]
fn line_suffix_printed_at_end() {
let printed = format(&format_args![
Expand Down
19 changes: 5 additions & 14 deletions crates/ruff_python_formatter/src/comments/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,12 @@ impl Format<PyFormatContext<'_>> for FormatTrailingComments<'_> {
empty_lines(lines_before_comment),
format_comment(trailing)
],
0
0 // Own-line comments never need their width measured during formatting, so it's okay to avoid the computation here.
),
expand_parent()
]
)?;
} else {
// TODO(cnpryer): Reserved width should be used when breaking is expected. Breaking may not be
// expected when a trailing end of line comment is not at the end of a collapsed node.
// ```python
// def fn():
// return np.divide(
// view.variance,
// view.sum_of_weights,
// out=np.full(view.sum_of_weights.shape, np.nan),
// where=view.sum_of_weights**2 > view.sum_of_weights_squared, # This shouldn't force a break
// )
// ```
//
// ```
// A trailing comment at the end of a line has a reserved width to consider during line measurement.
// ```python
Expand Down Expand Up @@ -285,7 +273,10 @@ impl Format<PyFormatContext<'_>> for FormatDanglingOpenParenthesisComments<'_> {
write!(
f,
[
line_suffix(&format_args!(space(), space(), format_comment(comment)), 0),
line_suffix(
&format_args!(space(), space(), format_comment(comment)),
comment.range().len().into() // This is safe since we expect the comment to be end of line
),
expand_parent()
]
)?;
Expand Down

0 comments on commit 9385e63

Please sign in to comment.