Skip to content

Fix SQL whitespace handing in comments#897

Merged
nedtwigg merged 1 commit intodiffplug:mainfrom
zregvart:pr/comment-whitespace-in-sql
Jul 20, 2021
Merged

Fix SQL whitespace handing in comments#897
nedtwigg merged 1 commit intodiffplug:mainfrom
zregvart:pr/comment-whitespace-in-sql

Conversation

@zregvart
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

@nedtwigg fixed

@nedtwigg nedtwigg merged commit 5fe0566 into diffplug:main Jul 20, 2021
@nedtwigg
Copy link
Copy Markdown
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.

2 participants