Prettier JOINs and other formatting improvements#92
Prettier JOINs and other formatting improvements#92rinu wants to merge 11 commits intodoctrine:1.5.xfrom
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.
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:
JOINs theONpart and other conditions are on a new line and indentedON DUPLICATE KEY UPDATEis one tokenCASE WHENand the like are blocks with indented contents