10000 Column formatting breaks with unary operators · Issue #550 · tconbeer/sqlfmt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Column formatting breaks with unary operators #550

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

Open
albertsgrc opened this issue Jan 22, 2024 · 3 comments
Open

Column formatting breaks with unary operators #550

albertsgrc opened this issue Jan 22, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@albertsgrc
Copy link
albertsgrc commented Jan 22, 2024

Describe the bug
When unary operators are used in column definition X, X is formatted to be in the same line as the previous column definition.

A space is also added in between the unary operator and the operand (not sure if this is expected).

To Reproduce

select
    amount_in_cents / 100.0 as amount, 
    -amount as charged_amount,
    resulting_balance_in_cents / 100.0 as resulting_balance
from mytable

Expected behavior
I expect the code above to remain unchanged after formatting with a maximum line length of 88

Actual behavior
This is sqlfmt's output:

select
    amount_in_cents / 100.0 as amount, - amount as charged_amount,
    resulting_balance_in_cents / 100.0 as resulting_balance
from mytable

Additional context
This is reproducible from https://sqlfmt.com/

@tconbeer
Copy link
Owner

Thanks for the report -- this one should be an easy fix.

@tconbeer tconbeer added the bug Something isn't working label Jan 22, 2024
@tconbeer
Copy link
Owner

this one should be an easy fix

Famous last words. This requires changes in quite a few places. Right now we support unaries in front of numbers by lexing the operator as a part of the number, but that approach won't work generally, since we have to support any expression after the operator. So this will require a new token type and maybe a new lexing ruleset, and then a close look at the line merging logic.

@tconbeer
Copy link
Owner

This was partially fixed in 0.22.0, released yesterday. The current output from the example above is now:

select
    amount_in_cents / 100.0 as amount,
    - amount as charged_amount,
    resulting_balance_in_cents / 100.0 as resulting_balance
from mytable

(so there is still a space between - and amount, but it is no longer merged onto the previous line)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
0