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

Feature Request: Remove unnecessary parentheses #15

Open
karlhorky opened this issue Dec 5, 2023 · 1 comment
Open

Feature Request: Remove unnecessary parentheses #15

karlhorky opened this issue Dec 5, 2023 · 1 comment

Comments

@karlhorky
Copy link

karlhorky commented Dec 5, 2023

Copied from original sql-formatter issue: sql-formatter-org/sql-formatter#684

Describe the Feature

New default behavior in prettier-plugin-sql-cst to remove unnecessary parentheses in SQL (maybe with a way to disable):

-- Before
SELECT
  sessions.id
FROM
  sessions
WHERE
  (
    (sessions.token = 'abc123')
    AND (sessions.user_id = 17)
    AND (sessions.expiry_timestamp > now())
  );

-- After
SELECT
  sessions.id
FROM
  sessions
WHERE
  sessions.token = 'abc123'
  AND sessions.user_id = 17
  AND sessions.expiry_timestamp > now();

Why do you want this feature?

Removing extra unnecessary parentheses can make code simpler and less nested

Prior art

Prettier does this:

288022812-3e896557-bb2e-49e4-9bdc-75a5de463228

Other projects also have had similar requests / implementation:

Keywords for Search

Operator precedence, operators, parenthesis

@nene
Copy link
Owner

nene commented Apr 17, 2024

FYI: Currently there exists some very basic support for unnecessary parentheses removal, which covers cases like these:

-- removal of repeated parenthesis
a + ((b + c))  --> a + (b + c)

-- removal of parenthesis around function parameters
my_func(a, (b), ((c + d)))  -->  my_func(a, b, c + d)

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

2 participants