arnetheduck / nph

An opinionated code formatter for Nim
Other
77 stars 12 forks source link

Comment at last item of a complex list makes it formatted differently #64

Closed kdeme closed 4 months ago

kdeme commented 4 months ago

Adding a comment next to the last item of a list appears to influence the formatting rules of that list (more like a simple list?).

Pre-formatting:

type TestType = object
  fieldWithSomeName1: string
  fieldWithSomeName2: int
  fieldWithSomeName3: bool
  fieldWithSomeName4: int

let test = TestType(
  fieldWithSomeName1: "test",
  fieldWithSomeName2: 1,
  fieldWithSomeName3: true,
  fieldWithSomeName4: 2, # great comment here
)

const test2 = [
  1000.uint64(),
  2000.uint64(),
  3000,
  4000,
  5000,
  6000,
  7000,
  8000,
  9000,
  10000,
  20000,
  30000, # yikes!
]

Post-formatting:

type TestType = object
  fieldWithSomeName1: string
  fieldWithSomeName2: int
  fieldWithSomeName3: bool
  fieldWithSomeName4: int

let test = TestType(
  fieldWithSomeName1: "test", fieldWithSomeName2: 1, fieldWithSomeName3: true, fieldWithSomeName4:
    2 # great comment here
)

const test2 = [
  1000.uint64(), 2000.uint64(), 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000
    # yikes!
]

Note that adding no comments results in what I would expect:

type TestType = object
  fieldWithSomeName1: string
  fieldWithSomeName2: int
  fieldWithSomeName3: bool
  fieldWithSomeName4: int

let test = TestType(
  fieldWithSomeName1: "test",
  fieldWithSomeName2: 1,
  fieldWithSomeName3: true,
  fieldWithSomeName4: 2,
)

const test2 = [
  1000.uint64(),
  2000.uint64(),
  3000,
  4000,
  5000,
  6000,
  7000,
  8000,
  9000,
  10000,
  20000,
  30000,
]

Also when adding multiple comments the formatting is as expected:

type TestType = object
  fieldWithSomeName1: string
  fieldWithSomeName2: int
  fieldWithSomeName3: bool
  fieldWithSomeName4: int

let test = TestType(
  fieldWithSomeName1: "test",
  fieldWithSomeName2: 1,
  fieldWithSomeName3: true, # awesome bool
  fieldWithSomeName4: 2, # great comment here
)