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

fix(sql): printer to handle eol correctly #358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LazyRichard
Copy link

I have the original document like below (with CRLF eol)

CREATE TABLE `CHANGELOG` (
  `ID` NUMERIC(20, 0) PRIMARY KEY NOT NULL,
  `APPLIED_AT` VARCHAR(25) NOT NULL,
  `DESCRIPTION` VARCHAR(256) NOT NULL
) ENGINE = INNODB DEFAULT CHARSET = UTF8MB4;

when I set endOfLine config to crlf than result like below

CREATE TABLE `CHANGELOG` (

  `ID` NUMERIC(20, 0) PRIMARY KEY NOT NULL,

  `APPLIED_AT` VARCHAR(25) NOT NULL,

  `DESCRIPTION` VARCHAR(256) NOT NULL

) ENGINE = INNODB DEFAULT CHARSET = UTF8MB4;

when I debug,

sql printer handle eol correctly, but I can find \r\n is replaced by \r\r\n after return formatted value.

actually I didn't find any reference but I guess prettier gives nomalized input as LF and process eol after printer printed.

this patch remove any eol conversion. so, prettier will handle it.

Copy link

changeset-bot bot commented Apr 14, 2024

⚠️ No Changeset found

Latest commit: da99fb3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

codesandbox-ci bot commented Apr 14, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@LazyRichard
Copy link
Author

Hello, @JounQin could you review this PR?

formatted = formatted.replaceAll(/\r\n?|\n/g, ending)

return formatted.endsWith(ending) ? formatted : formatted + ending
return formatted + '\n'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't read endOfLine option at all?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tested it, EOL doesn't needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the tests do not cover endOfLine option which could be different with git source codes.

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

Successfully merging this pull request may close these issues.

None yet

2 participants