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 #684

Closed
karlhorky opened this issue Dec 5, 2023 · 2 comments
Closed

Feature Request: Remove unnecessary parentheses #684

karlhorky opened this issue Dec 5, 2023 · 2 comments
Labels

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Dec 5, 2023

Describe the Feature

New default behavior in sql-formatter 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:

Screenshot 2023-12-05 at 12 24 44

Other projects also have had similar requests / implementation:

Keywords for Search

Operator precedence, operators, parenthesis

@nene
Copy link
Collaborator

nene commented Dec 5, 2023

This is pretty much out of scope for SQL Formatter. In the sense that implementing this would require proper parsing of SQL which SQL Formatter doesn't do.

Elimination of extra parenthesis is at least partly implemented by the prettier-plugin-sql-cst. Like converting ((a + b)) to (a + b). I don't recall right now if I also implemented something else besides this most basic stuff.

I suggest you open this issue in prettier-plugin-sql-cst.

I'm closing this, as there's really no hope for it happening in SQL Formatter.

@karlhorky
Copy link
Contributor Author

Ok thanks for the answer!

I suggest you open this issue in prettier-plugin-sql-cst.

Duplicated issue open here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants