Add new formatting options: colors, compactParenthesis, maxOperatorArgsLength#940
Add new formatting options: colors, compactParenthesis, maxOperatorArgsLength#940foul11 wants to merge 5 commits intosql-formatter-org:masterfrom
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
|
Hi there. Thanks for the pull request. However, this is too much functionality bundled into one large change. I can immediately say the following: Syntax highlightingThis is a no. There are other libraries out there to do syntax highlighting. I can't point to any specific one off the top of my head, but I'm pretty certain this area is well covered. I really want to limit the scope of this library to just formatting. Limit on the maximum number of elements in a tupleThis seems something very specific to your use-case. I generally want to avoid having options that change what the code does. Currently a single odd exception to this is the Block layout, like inline layout but blockThis part I don't quite understand. Could you give me a better overview of what this does and perhaps also how it was implemented. |
|
It's a shame you have this opinion even about basic syntax highlighting.
console.log(
format(`INSERT INTO user VALUES (${'?'.repeat(10).split('').join(',')})`, {
compactParenthesis: true, // new option, activate block layout
expressionWidth: 10,
})
)-- with new options, block layout
INSERT INTO
user
VALUES
( ?, ?, ?, ?,
?, ?, ?, ?,
?, ?
)-- default behivator, inline layout
INSERT INTO
user
VALUES
(
?,
?,
?,
?,
?,
?,
?,
?,
?,
?
) |
|
In my case, I'm formatting a query in which the number of params can reach up to 30,000, so it would be nice to be able to reduce the output |
I'm sure it would be very convenient. But so would be many other features that this library could have. I don't want to come across as somebody who just pushes back on all the feature proposals. However I do think it is better for a library to concentrate on doing one task well. And frankly I think SQL Formatter is struggling even with that single task. |
Wow 😲 🌋 Care to provide some context as to how one ends up with so many parameters? Like in PostgreSQL there's a limit of just 1600 columns per table. |
|
Regarding this "Block layout" feature, this I could very well consider. But I first need to understand it a bit more. I kinda see how it's working with a huge amount of I could figure this all out by reading & running the code, but it really should be up to you to convince me that it's a great feature this formatter should have. Plus I'm currently away from a computer and will likely be mostly offline for the rest of this week. |
I use sqlite in my application, it is application-parser, and sometimes I need to iterate through quite a few rows in a table using their id, I get a query like About "Block layout" I used it as a replacement for "Inline layout". I only found one place where it was used, in the formatParenthesis function, so I simply added a switch that changes the behavior from "try to fit everything on one line and if that doesn't work, fall back to writing each argument on a new line" to "we try to fit everything on one line and if it doesn't fit, go to a new line and try to keep stuffing arguments while there's room." That is, it is a kind of change in the node placement strategy, and since it uses only the length of the incoming token (as the "Inline layout" does), it should not cause problems. |
Hi, the library is good.
I use it to debug the output from kysely, to display nice error messages.
For this I was missing some options similar to options from util.inspect.
below is a visual demonstration of what I added:
Specifically:
All changes are under flags that are disabled by default, so the changes will not affect dependent projects.
Let me know if any further improvements need to be made.