ruff/crates/ruff_python_ast/src
konsti 13f9a16e33
Rewrite placement logic (#6040)
## 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.
2023-07-26 16:21:23 +00:00
..
snapshots Implement visitation of type aliases and parameters (#5927) 2023-07-25 17:11:26 +00:00
visitor Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
all.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
call_path.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
cast.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
comparable.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
docstrings.rs Move Python whitespace utilities into new ruff_python_whitespace crate (#4993) 2023-06-10 00:59:57 +00:00
function.rs Format Function definitions (#4951) 2023-06-08 16:07:33 +00:00
hashable.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
helpers.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
identifier.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
imports.rs Include alias when formatting import-from structs (#5786) 2023-07-15 15:53:21 -04:00
lib.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
node.rs Rewrite placement logic (#6040) 2023-07-26 16:21:23 +00:00
relocate.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
statement_visitor.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
stmt_if.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
str.rs Basic string formatting 2023-06-23 09:46:05 +02:00
traversal.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
types.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
visitor.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
whitespace.rs Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00