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

Bug Report: Formatting moves comments unexpectedly #9

Open
Anthony-Fiddes opened this issue Oct 11, 2023 · 4 comments
Open

Bug Report: Formatting moves comments unexpectedly #9

Anthony-Fiddes opened this issue Oct 11, 2023 · 4 comments

Comments

@Anthony-Fiddes
Copy link

I'm experiencing a curious bug where comments don't end up where I expect. In addition, if I keep formatting the text, the comments keep moving until they all settle on the same line.

Language: BigQuery

Text to format:

CREATE TEMP TABLE blah
-- comments
-- more comments
-- even more comments
(
date DATE NOT NULL
) AS
(
SELECT
bleep
FROM
bloop
);

Expected output:

CREATE TEMP TABLE blah 
-- comments
-- more comments
-- even more comments
(
  date DATE NOT NULL
) AS
  (
    SELECT
      bleep
    FROM bloop
  );

Actual output:

CREATE TEMP TABLE blah -- comments
-- more comments
-- even more comments
(
  date DATE NOT NULL
) AS
  (
    SELECT
      bleep
    FROM bloop
  );
@Anthony-Fiddes Anthony-Fiddes changed the title Bug Report: Formatting eats comments Bug Report: Formatting moves comments unexpectedly Oct 11, 2023
@nene
Copy link
Owner

nene commented Oct 11, 2023

Thanks for reporting.

Comments being moved slightly is one thing, but getting multiple line-comments on a single line and their order changed is a much more serious issue. Like currently this SQL:

CREATE TABLE foo -- comment1
-- comment2
(
  bar INT
);

gets formatted as:

CREATE TABLE foo -- comment2 -- comment1
(
  bar INT
);

@nene
Copy link
Owner

nene commented Oct 11, 2023

I don't really know why this happens, because I've left the handling of comments to the Prettier engine. Two line-comments one-after-another seems like a bug in Prettier itself. Though possibly my input of comments data might be incorrect for Prettier.

One hope is that perhaps this works better in Prettier 3.x. Should first upgrade to latest Prettier and then investigate further.

nene added a commit that referenced this issue Oct 11, 2023
@nene
Copy link
Owner

nene commented Oct 11, 2023

Tried upgrading to Prettier 3. Bunch of problems there... but I did find out that it won't fix this comments formatting issue.

@nene
Copy link
Owner

nene commented Jan 24, 2024

Related to prettier/prettier#15978

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

No branches or pull requests

2 participants