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

Make INLINE_MAX_LENGTH configurable #5

Closed
nene opened this issue Sep 16, 2016 · 6 comments
Closed

Make INLINE_MAX_LENGTH configurable #5

nene opened this issue Sep 16, 2016 · 6 comments
Labels
Milestone

Comments

@nene
Copy link
Collaborator

nene commented Sep 16, 2016

This should clearly be configurable.

But the current implementation is a bit lacking. It considers the length of the parenthesized expression in isolation, but it should also consider the current indentation, because the whole point of it is really to limit how long the lines can be. By taking the indentation into the picture, we can name the config option to something like maxLineLength which would be instantly understandable, v/s something like maxParenthesizedExpressionLength.

@ukupat
Copy link
Contributor

ukupat commented Sep 25, 2016

We know that we have the same issue jdorn/sql-formatter#59.

I was thinking about keeping AND and OR on the same line when the line is smaller than maxLineLength. This could solve that issue. What do you think @nene?

@ukupat ukupat added the feature label Nov 11, 2016
nene pushed a commit that referenced this issue Apr 27, 2022
Add Typescript config fixes for Travis-CI
@nene nene added this to the Version 6 milestone May 8, 2022
@nene
Copy link
Collaborator Author

nene commented May 8, 2022

This is now configurable through the lineWidth option. Though for now this configuration has all the problems listed above.

@nene nene closed this as completed May 8, 2022
@jonahx
Copy link

jonahx commented Mar 6, 2023

@nene

Quick question: I was trying to specify a global line length limit (similar to prettier's printWidth) and tried the lineWidth option, but it didn't work. Based on your comment that it "has all the problems listed above", I am assuming this is simply not supported... is this correct? Thanks!

@nene
Copy link
Collaborator Author

nene commented Mar 6, 2023

This option has been renamed to expressionWidth, but it's behavior is far from intuitive.

Perhaps you're interested in trying out a new SQL formatting tool that I've written, which does support the printWidth option as it's implemented as a Prettier plugin and uses the same layout algorithm as Prettier.

@jonahx
Copy link

jonahx commented Mar 6, 2023

Thanks for the reply.

Perhaps you're interested in trying out a new SQL formatting tool that I've written

In theory yes, but I have a couple of requirements that brought me to the cmdline tool here....

  1. Need pg and tsql support
  2. We have a lot of SQL that exists within template literals in JS files. So with the command-line version, I can use a VS Code (or vim, etc) plugins to highlight lines of code inside template literals, pre-process them (eg, to replace interpolated ${vars}), run through sql-formatter, post-process, then replace the original text with formatted text.

2 is working great, except that there is no way to tell sql-formatter to respect the projects overall prettier printWidth, which would be ideal. I am open to other solutions if you know of any.

@nene
Copy link
Collaborator Author

nene commented Mar 6, 2023

The only other feasible option that I know of is SQLFluff. But that one is really primarily a linter and not really that great of an option for completely reformatting SQL code. Though it does have a max_line_length option and it's auto-fixable.

I'm planning to add Postgres support, but that will take time as Postgres is kinda big amongst SQL dialects. Transact-SQL is likely even more work as there are actually many dialects under this label and I find the syntax diagrams in Microsoft docs to be among the more confusing ones. However, currently Postgres support is definitely the most requested feature, so there's hope.

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

3 participants