Skip to content

Comment placement in argument lists causes ordering issues #435

@lionel-

Description

@lionel-

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:

  • comment2 is pulled down because it becomes a leading comment of the whole argument node
  • comment6 is 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.
  • comment7 is formatted on the same line as comment5, because they both become trailing comments of the same node, and both have lines_before = 0. This happens here:
    return CommentPlacement::trailing(previous, comment);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions