Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support de-indenting/indenting block comments according to their leading line indentation #678

Closed
bartlomieju opened this issue Oct 26, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@bartlomieju
Copy link
Collaborator

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 denoland/deno#26560

@bartlomieju
Copy link
Collaborator Author

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.

@dsherret
Copy link
Member

dprint-plugin-typescript doesn't modify block comments. This is an issue somewhere else.

@dsherret dsherret closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2024
@dsherret dsherret added enhancement New feature or request and removed working as intended labels Oct 28, 2024
@dsherret dsherret changed the title Multi-line comment with leading spaces causes drift and unstable format Support de-indenting/indenting block comments according to their leading line indentation Oct 28, 2024
@dsherret dsherret reopened this Oct 28, 2024
@dsherret
Copy link
Member

After discussion, we're going to improve dprint-plugin-typescript to handle de-indenting/indenting these kind of block comments. Initially we were thinking markup_fmt should de-indent itself, but it wouldn't be able to handle scenarios like:

<script>
  const test = `
  test
`;
  console.log(test);
</script>

@bartlomieju
Copy link
Collaborator Author

A few more examples of inputs that cause unstable format:

  "{"; // This line cause panic
  `
    `;

  `{
  }`;
  ``;

@bartlomieju
Copy link
Collaborator Author

@dsherret FYI I opened an issue with markup_fmt and it appears these strings are passed in this way on purpose - g-plane/markup_fmt#74 (comment).

I'm beginning to think that dprint-plugin-typescript could use a separate API like format_text_for_external_block that would be aware of the indentation requirements, but I haven't figured it out yet.

@bartlomieju
Copy link
Collaborator Author

Closing as this can now be solved with #689.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants