ruff/crates/ruff_python_formatter/src/comments
Charlie Marsh d3aa8b4ee0
Add API to chain comment placement operations (#6319)
## Summary

This PR adds an API for chaining comment placement methods based on the
[`then_with`](https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.then_with)
from `Ordering` in the standard library.

For example, you can now do:

```rust
try_some_case(comment).then_with(|comment| try_some_other_case_if_still_default(comment))
```

This lets us avoid this kind of pattern, which I've seen in
`placement.rs` and used myself before:

```rust
let comment = match handle_own_line_comment_between_branches(comment, preceding, locator) {
    CommentPlacement::Default(comment) => comment,
    placement => return placement,
};
```
2023-08-03 21:08:50 -04:00
..
snapshots Rename Arguments to Parameters in the AST (#6253) 2023-08-01 13:53:28 -04:00
debug.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
format.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
map.rs Correctly associate own-line comments in bodies (#4671) 2023-06-01 08:12:53 +02:00
mod.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
node_key.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
placement.rs Add API to chain comment placement operations (#6319) 2023-08-03 21:08:50 -04:00
visitor.rs Add API to chain comment placement operations (#6319) 2023-08-03 21:08:50 -04:00