dprint / dprint-plugin-typescript

TypeScript and JavaScript code formatting plugin for dprint.
https://dprint.dev/plugins/typescript
MIT License
256 stars 57 forks source link

Multi-line comment with leading spaces causes drift and unstable format #678

Open bartlomieju opened 4 hours ago

bartlomieju commented 4 hours ago

Describe the bug

dprint-plugin-typescript version: 0.93.0

Input Code


            /* some multiline comment
            with function below it */
            someFunc();

Expected Output

            /* some multiline comment
            with function below it */
            someFunc();

Actual Output

      /* some multiline comment
                  with function below it */
      someFunc();

Then after using the "Actual output" as input to check for format stability we get:

      /* some multiline comment
                        with function below it */
      someFunc();

and then again:

      /* some multiline comment
                              with function below it */
      someFunc();

And it continues...

This is the root cause for https://github.com/denoland/deno/issues/26560

bartlomieju commented 3 hours ago

I guess one work-around that could be done in Deno itself is to split into lines, trim them and then join. That will however make some comments formatting off. I'm gonna apply it for now to get rid of panics, but I think it'd be better to fix it in dprint itself.