dprint-plugin-typescript icon indicating copy to clipboard operation
dprint-plugin-typescript copied to clipboard

Interpretation of trailing comments with ASI formatting

Open cjpearson opened this issue 1 year ago • 0 comments
trafficstars

Describe the bug

dprint-plugin-typescript version: 0.88.10

When using the "asi" option for semicolons, formatters will sometimes have to insert a semicolon at the beginning of a line. An example with dprint:

Input

let line1 = 'hello';

// Comment
[].filter(x => x)

Formatted

let line1 = "hello"

// Comment
;[].filter(x => x)

However, if the code is already formatted, dprint will attach the comment to the first statement. Although technically the comment may be contained within the first statement, developers would typically understand the comment to belong to the latter statement and it would nice if dprint could handle this case.

Input Code

let line1 = "hello"

// Comment
;[].filter(x => x)

Expected Output

let line1 = "hello"

// Comment
;[].filter(x => x)

Actual Output

let line1 = "hello" // Comment
;[].filter(x => x)

cjpearson avatar Jan 30 '24 16:01 cjpearson