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 whitespace handing in comments #897

Merged
merged 1 commit into from Jul 20, 2021

Conversation

zregvart
Copy link
Contributor

This fixes several issues to how whitespace was formatted related to
comments in SQL formatter:

  • A line after the comment would get an additional leading space, this
    was especially visible for multi-line comments. For example:
    -- comment
    CREATE TABLE ...
    
    Would be formatted as:
    -- comment
     CREATE TABLE ...
    
  • An inline comment would be indented and placed on a separate line.
    For example:
    CREATE TABLE products (
        category_id INTEGER, -- lookup in categories table
        color VARCHAR(50),
    )
    
    Would be formatted as:
    CREATE TABLE products (
        category_id INTEGER,
        -- lookup in categories table
    color VARCHAR(50),
    )
    

@zregvart zregvart force-pushed the pr/comment-whitespace-in-sql branch 2 times, most recently from 533fcd1 to c526bb8 Compare July 19, 2021 13:07
@nedtwigg
Copy link
Member

nedtwigg commented Jul 19, 2021

Thanks for the PR! A few nits before we can merge:

  • Move the changelog entry under a ### Fixed header
  • Copy the changelog entry to plugin-gradle/CHANGES.md and plugin-maven/CHANGES.md
  • Fix the tests on windows.

This fixes several issues to how whitespace was formatted related to
comments in SQL formatter:

 - A line after the comment would get an additional leading space, this
   was especially visible for multi-line comments. For example:
   ```
   -- comment
   CREATE TABLE ...
   ```
   Would be formatted as:
   ```
   -- comment
    CREATE TABLE ...
   ```
 - An inline comment would be indented and placed on a separate line.
   For example:
   ```
   CREATE TABLE products (
       category_id INTEGER, -- lookup in categories table
       color VARCHAR(50),
   )
   ```
   Would be formatted as:
   ```
   CREATE TABLE products (
       category_id INTEGER,
       -- lookup in categories table
   color VARCHAR(50),
   )
   ```

This fixes those issues in by patching these specific cases.
@zregvart zregvart force-pushed the pr/comment-whitespace-in-sql branch from c526bb8 to 39a1102 Compare July 20, 2021 07:54
@zregvart
Copy link
Contributor Author

@nedtwigg fixed

@nedtwigg nedtwigg merged commit 5fe0566 into diffplug:main Jul 20, 2021
@nedtwigg
Copy link
Member

Thanks for the PR. Released in plugin-maven 2.12.2 and plugin-gradle 5.14.2

@zregvart zregvart deleted the pr/comment-whitespace-in-sql branch July 20, 2021 16:27
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