Open borkdude opened 3 weeks ago
I think it's using rule 3 for the vector. And I think that's a bug, @oakmac? 😄
Thank you for the report. While the code here looks "off", I am not sure this is a bug with the formatter.
I think it's using rule 3 for the vector.
Yes - this is exactly what is happening in this case. y
is vertically aligned with 1
on the line above, so Standard Clojure Style assumes that is an intentional choice from the developer.
Some more examples to clarify:
Input | After formatting |
(let [x 1 y 2 z 4] :foo) |
(let [x 1 y 2 z 4] :foo) |
Input | After formatting |
(let [x 1 y 2 z 4] :foo) |
(let [x 1 y 2 z 4] :foo) |
Maybe Rule 3 should not apply to Vectors? I need to give this a think.
Curious if @shaunlebron has any thoughts about this?
Eh, hiccups use vectors too, so I wouldn't disable rule three for them.
Chris if you have a rule to columnate let-bindings (I think I saw this in your talk), I suppose there would be enough semantic detection in place to add an exception for this as well.
hiccups use vectors too, so I wouldn't disable rule three for them
This is a great point - thank you!
if you have a rule to columnate let-bindings (I think I saw this in your talk), I suppose there would be enough semantic detection in place to add an exception for this as well.
Standard Clojure Style does not vertically align let
bindings by default. If you pass in vertically-aligned let
bindings, it does not change them, but it does not do that formatting for you (relevant test case for this behavior).
There is enough information from the parser in order to determine "Does this look like a let
binding?", but I am not sure it is a great idea to add an exception for this. I need to give this a think.
I also wonder if this a case of "is this a realistic scenario? or a theoretical concern?" Standard Clojure Style is not a pretty-printer, so if you pass in strange-looking code you may get some strange looking code as the output.
I also wonder if this a case of "is this a realistic scenario? or a theoretical concern?" Standard Clojure Style is not a pretty-printer, so if you pass in strange-looking code you may get some strange looking code as the output.
Someone at the conj asked me what would happen if you passed in a file that was all on one line. In this case, Standard Clojure Style will pretty-print the ns
form and then leave the rest of the file printed on one line. This output is "weird" code by any reasonable definition, but it is also not a meaningful use case for this tool in any realistic scenario. No one writes code all on one line, and if they do they are likely not the intended audience for something like Standard Clojure Style.
zprint is an excellent project for "from scratch" pretty-printing. And some people / teams may prefer using it over Standard Clojure Style.
What should happen in the following case after you format it?
See squint playground