Comment placement in argument lists causes ordering issues
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 446
- Forks
- 32
- Avg merge
- 16h 48m
- Merged PRs (30d)
- 1
Description
This call:
list(
# comment0
foo # comment1
=1, bar # comment2
= # comment3
# comment4
2 #comment5
#comment6
, #comment7
#comment8
)
Is currently formatted as:
list(
# comment0
# comment1
foo = 1,
# comment3
# comment4
# comment2
bar = 2, #comment5 #comment7
#comment8
#comment6
)
We need to fix these issues:
-
comment2is pulled down because it becomes a leading comment of the whole argument node -
comment6is pulled down because it becomes a leading comment of the empty argument, I think because it's an own-line and the default placement puts it on the next node. -
comment7is formatted on the same line ascomment5, because they both become trailing comments of the same node, and both havelines_before = 0. This happens here: https://github.com/posit-dev/air/blob/e3655e9a68f18ba7caea0aa6680817553bc97bee/crates/air_r_formatter/src/comments.rs#L951
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in crates/air_r_formatter/src/comments.rs at the referenced logic around line 951, using the issue's R call as the reproduction. Trace how comments around argument nodes and the empty argument are assigned, then verify that comment2, comment6, and comment7 retain the intended order and line placement without combining comments incorrectly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100