Fix single-column-line? behavior for last elements#411
Fix single-column-line? behavior for last elements#411beatriz wants to merge 4 commits intoweavejester:masterfrom
single-column-line? behavior for last elements#411Conversation
cljfmt/src/cljfmt/core.cljc
Outdated
| (let [right* (z/right* zloc)] | ||
| (and (or (nil? right*) | ||
| (line-break? (skip-whitespace-and-commas right* z/right*))) | ||
| (line-break? (skip-whitespace-and-commas (z/left* zloc) z/left*))))) |
There was a problem hiding this comment.
Please correct me if I'm wrong, but wouldn't we want to check for nil after skipping the whitespace and commas? i.e.
(and (let [zloc (skip-whitespace-and-commas (z/right* zloc) z/right*)]
(or (nil? zloc) (line-break? zloc)))
(line-break? (skip-whitespace-and-commas (z/left* zloc) z/left*)))Otherwise a single column line ending in a comma or whitespace wouldn't trigger this rule.
There was a problem hiding this comment.
Yes, you are correct! Fixed it.
There was a problem hiding this comment.
Thanks! Could you use the code I suggested in my previous comment? It makes it a little more concise and constrains the scope of the let clause.
There was a problem hiding this comment.
This is ready to review, when you have the chance 🙂
cljfmt/test/cljfmt/core_test.cljc
Outdated
| ["{:key1 1" | ||
| " :key3 3" | ||
| " :key2" | ||
| " (fn [a b c d e]" | ||
| " (+ a b c d e))}"] | ||
| ["{:key1 1" | ||
| " :key3 3" | ||
| " :key2" | ||
| " (fn [a b c d e]" | ||
| " (+ a b c d e))}"] | ||
| {:align-map-columns? true}))) |
There was a problem hiding this comment.
Ideally we should have some invalid indentation so that there's a change in the two expression strings, otherwise we can't distinguish between it working and it doing nothing. So perhaps:
(is (reformats-to?
["{:key-first 1"
" :key2 3"
" :key3"
" (fn [a b c d e]"
" (+ a b c d e))}"]
["{:key-first 1"
" :key2 3"
" :key3"
" (fn [a b c d e]"
" (+ a b c d e))}"]
{:align-map-columns? true})))There was a problem hiding this comment.
Makes total sense, I've adjusted the test.
|
This all looks good! Can you squash down your commits and give them an appropriate commit message like: |
I noticed that the
:single-column-line?rule is not currently respected when the single-column element is the last one in a map. This PR fixes that.