mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
![]() ## Summary This is a rewrite of the main comment placement logic. `place_comment` now has three parts: - place own line comments - between branches - after a branch - place end-of-line comments - after colon - after a branch - place comments for specific nodes (that include module level comments) The rewrite fixed three bugs: `class A: # trailing comment` comments now stay end-of-line, `try: # comment` remains end-of-line and deeply indented try-else-finally comments remain with the right nested statement. It will be much easier to give more alternative branches nodes since this is abstracted away by `is_node_with_body` and the first/last child helpers. Adding new node types can now be done by adding an entry to the `place_comment` match. The code went from 1526 lines before #6033 to 1213 lines now. It thinks it easier to just read the new `placement.rs` rather than reviewing the diff. ## Test Plan The existing fixtures staying the same or improving plus new ones for the bug fixes. |
||
---|---|---|
.. | ||
snapshots | ||
visitor | ||
all.rs | ||
call_path.rs | ||
cast.rs | ||
comparable.rs | ||
docstrings.rs | ||
function.rs | ||
hashable.rs | ||
helpers.rs | ||
identifier.rs | ||
imports.rs | ||
lib.rs | ||
node.rs | ||
relocate.rs | ||
statement_visitor.rs | ||
stmt_if.rs | ||
str.rs | ||
traversal.rs | ||
types.rs | ||
visitor.rs | ||
whitespace.rs |