-
Notifications
You must be signed in to change notification settings - Fork 28
Prettier JOINs and other formatting improvements #92
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
base: 1.5.x
Are you sure you want to change the base?
Conversation
Thank you. This is a feature, so we should target the 1.2.x branch. 1.1.x is for bugfixes. |
There was a mention of breaking changes in the description. Can you please detail what they are and why they should be considered breaking? Also, please read the contributing guide, especially the part about commit messages. |
The public interface of the |
Conflicts with |
Can you elaborate on this? |
I use this formatter to lint SQL in my project. My linter will look at every string in the project and if it looks like SQL it will apply this formatting. There are probably thousands of these so a consistent style is very useful. |
I had no idea this project was used that way… in that particular case, any change does seem like a breaking change, but I'm not sure this means that's the case for most consumers of this project. |
I think this is ready now. This logic of blocks could be used in the future to give better context for both formatting and highligting. For example in the case of |
} | ||
|
||
public function withValue(string $value): self | ||
public function isBlockStart(): ?Condition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this is fully possible this way. There are ambiguous tokens (and group of tokens) as we never know the full grammar nor parse the full grammar.
With this said, we cannot tell if a token represents a "block start/end" or not by just looking around. In order to implement this and fix #118 (and prevent related issues), I think we need to parse the tokens into some intermediate tree data structure in "try consume" fashion first.
With this approach the tree of parsed blocks will always be correct (otherwise they will be kept unparsed/as tokens) and the formatter can then be hugely simplified.
Fixed lots of issues with formatting non-trivial SQL queries. This is NOT backwards compatible, there are many breaking changes. This is more in line with what looks good to me and what prettier is doing.
Highlights include:
JOIN
s theON
part and other conditions are on a new line and indentedON DUPLICATE KEY UPDATE
is one tokenCASE WHEN
and the like are blocks with indented contents