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

A handful of formatting issues I've discovered recently relating to anonymous code blocks, comments, and multi-row inserts statements. #317

Open
paulgelardi opened this issue Apr 19, 2023 · 0 comments

Comments

@paulgelardi
Copy link

paulgelardi commented Apr 19, 2023

I noticed a handful of issues and I wanted to bring them to attention. I'm unfamiliar with Perl so it'd be a bit much to make the fixes myself - I'd be happy to be a tester if needed.

Command line arguments specified:

  • --keep-newline
  • --nogrouping (I don't think this actually has any affect, but I used it so I'm including it in reproduction notes)

Issues noticed:

  • Newlines are not preserved if they occur before a comment
  • Inconsistent indentation of INSERT statements
    • Without a preceeding comment, they are one level less indented than desired..
    • With a preceding comment, they are indented as desiredd
  • Multi-row insert statements have an alignment issue with the first row and subsequent rows because the VALUES keyword is included on the first row. (This issue is minor)
  • (Not included in example below) - The lines following a CROSS JOIN are indented one level less than desired. I believe this may be due to the lack of the ON keyword.

I'm unsure how much of this is related to the use of an anonymous code block, but that does help highlight the indentation issue - it may also occur elsewhere. I have confirmed these issues still occur in the latest version of Beautify.pm as of the time of this submission.

I've prepared some SQL below to demonstrate this

Expected output (also the input):

DO $$
DECLARE
    _variable int := 42;
BEGIN

    -- This is a comment
    CREATE TEMP TABLE IF NOT EXISTS tempy_mc_tempface (
        test text
    );
    TRUNCATE TABLE tempy_mc_tempface;

    INSERT INTO tempy_mc_tempface
    VALUES
        ('tempy'),
        ('mc'),
        ('tempface');
        
    -- Another Comment
    INSERT INTO tempy_mc_tempface
        VALUES ('another');

END
$$;

Actual output:

DO $$
DECLARE
    _variable int := 42;
BEGIN
    -- This is a comment
    CREATE TEMP TABLE IF NOT EXISTS tempy_mc_tempface (
        test text
    );
    TRUNCATE TABLE tempy_mc_tempface;

INSERT INTO tempy_mc_tempface
    VALUES ('tempy'),
    ('mc'),
    ('tempface');
    -- Another Comment
    INSERT INTO tempy_mc_tempface
        VALUES ('another');

END
$$;
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

1 participant