Skip to content

Conversation

@lionel-
Copy link
Collaborator

@lionel- lionel- commented Oct 27, 2025

Progress towards solving the idempotence panic mentioned in #434
Progress towards #435

Comments in:

foo(
  name = # comment
    value
)

foo(
  name =
    # comment
    value
)

are currently placed on the RArgument node. This causes them to move higher in the tree, and they get formatted as:

foo(
  # comment
  name = value
)

foo(
  # comment
  name = value
)

This displacement is particularly problematic in:

list(
  foo  # comment1
  =1, bar  # comment2
  =  # comment3
  2,
)

as the comment ordering becomes:

list(
  # comment1
  foo = 1,
  # comment3
  # comment2
  bar = 2,
)

To solve this, the PR:

  • Places trailing name clause comments as leading comments of argument values
  • Introduces a line break and an indent in arguments with both name clauses and leading comments on values

This solves the ordering issue in the last example which is now formatted as:

list(
  # comment1
  foo = 1,
  # comment2
  bar =
    # comment3
    2,
)

Remaining issues: in the following example, comment 6 is still formatted out of order, and comment 7 is still on the same line as comment 5:

# fmt: table
list(
  # comment0
  foo  # comment1
  =1, bar  # comment2
  =  # comment3
  # comment4
  2 #comment5
  #comment6
  , #comment7
  #comment8
)

becomes:

# fmt: table
list(
  # comment0
  # comment1
  foo = 1,
  # comment2
  bar =
    # comment3
    # comment4
    2, #comment5 #comment7
  #comment8
  #comment6
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants