bpfmt: Preserve line of comment when sorting arrays
When given as an input ``` array: [ "a", // Unicorn "b", ] ``` bpfmt with `-s` option was outputing ``` array: [ "a", // Unicorn "b", ] ``` Which is not ideal because the comment was targetting the second value and now it seems to be targetting the first one This patch preserve the difference in line number between the value and the comment to give the same output when ``` array: [ "a", // Unicorn "b", ] ``` is given as input Test: Manual tests + run bpfmt -w -s on packages/modules/Bluetooth Change-Id: I2b58f20da463bea77c22a4e6978aa9beb4b4fcc8
This commit is contained in:
parent
2621c909e5
commit
65aa5a505f
1 changed files with 2 additions and 1 deletions
|
@ -227,7 +227,8 @@ func sortSubList(values []Expression, nextPos scanner.Position, file *File) {
|
|||
values[i].(*String).LiteralPos = curPos
|
||||
for j, c := range copyComments {
|
||||
if c.Pos().Offset > e.pos.Offset && c.Pos().Offset < e.nextPos.Offset {
|
||||
file.Comments[j].Comments[0].Slash.Line = curPos.Line
|
||||
file.Comments[j].Comments[0].Slash.Line = curPos.Line + c.Pos().Line - e.pos.Line
|
||||
curPos.Line += c.Pos().Line - e.pos.Line
|
||||
file.Comments[j].Comments[0].Slash.Offset += values[i].Pos().Offset - e.pos.Offset
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue