fix single-column-line? to detect first element in collection#424
Conversation
weavejester
left a comment
There was a problem hiding this comment.
Thanks for the PR. Can you change the commit message so it adheres to the seven rules of a great Git commit message as per the contributing guidelines. I also have a suggestion regarding the use of some-> that I've added as a comment.
bc005ea to
161c125
Compare
Extend the left-side check to treat a nil left sibling as equivalent to a linebreak, so first-position nodes in a collection are correctly identified as single-column and excluded from the alignment anchor when :align-single-column-lines? is false.
161c125 to
5820b66
Compare
|
@weavejester Sorry, I forgot the commit and line width rules. They are updated. for the comment on the some-> form is not symantically the same. when z/right* or z/left* returns nil (nothing there, or first element), some-> returns nil which is falsy, but nil should be a passing condition. The form below works as well. This change copied the existing logic block, but either is fine with me. |
|
Ah, right. In which case, keep it the way it is. I think that's clearest. |
@weavejester I can't remember if you want an issue per PR, so I included the details here. I can make it an issue if you prefer.
LLM notice
I have reviewed all of what is being submitted. The PR description was partially generated with llm to show the current and expected. The test cases were partially generated with llm to cover all the permutations.
Problem
:align-single-column-lines? falsedoes not suppress anchor inflation when the wrapped form is the first binding in aletor the first entry in a map. The first-position element is always treated as an alignment anchor, producing the same excessive padding as:align-single-column-lines? true.The underlying cause is in
single-column-line?, which identifies whether a node is the sole element on its line. It checks for a linebreak to the left of the node, but the first element in a collection has no left sibling —z/left*returns nil,line-break?of nil returns false, and the element is never recognized as single-column regardless of what is on its right.Current behavior
Form columns
Config:
{:align-form-columns? true, :align-single-column-lines? false}Input:
Output — first-position wrapped binding used as anchor despite
false:Map columns
Config:
{:align-map-columns? true, :align-single-column-lines? false}Input:
{:very-long-map-key wrapped-value :host "localhost" :port 5432 :timeout 30}Output — first-position entry used as anchor despite
false:{:very-long-map-key wrapped-value :host "localhost" :port 5432 :timeout 30}Expected behavior
Form columns
Map columns
Fix
single-column-line?currently requires a linebreak to the left:A nil result (first element in collection) is treated as false. The fix treats nil
the same as a linebreak:
Tests cover all three positions (first, middle, last) for both
align-form-columns?and
align-map-columns?, with bothtrueandfalseflag values, added to theexisting
test-align-single-column-lines-optiondeftest.