-
Notifications
You must be signed in to change notification settings - Fork 119
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
Fix nested :inner specs #350
Conversation
* Cljfmt config part 2 * Part 3 WIP * Part 3 WIP * Part 3 WIP * Part 3 WIP * Part 3 WIP * Use fork with weavejester/cljfmt#348 and weavejester/cljfmt#350 * Backport updated config and linter fork from part 3 * Update formatting * Reformat * Fix bad indentation from #47064
What's the advantage of splitting up the indentation rules, compared to fixing the indentation ordering to prefer more 'outer' indentations? |
Originally I thought keeping them as one rule it would potentially break stuff in weird edge cases , e.g. if you have letfn [[:block 0] [:inner 1]]
my.namespace/letfn [[:block 0]] the stuff at depth one inside a I updated the PR so it keeps things as one rule and only updates the |
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.
Thanks for the PR. I only had one small suggestion around readability.
cljfmt/src/cljfmt/core.cljc
Outdated
(defn- indent-order [[key specs]] | ||
(let [max-depth (transduce | ||
(map (fn [[spec-type :as spec]] | ||
(case spec-type | ||
:inner (let [[_inner depth] spec] | ||
depth) | ||
0))) | ||
max | ||
0 | ||
specs) | ||
key-type* (cond | ||
(qualified-symbol? key) 0 | ||
(simple-symbol? key) 1 | ||
(pattern? key) 2)] | ||
[(- max-depth) key-type* (str key)])) |
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.
Perhaps instead:
(defn- indent-order [[key specs]]
(let [get-depth (fn [[type depth]] (if (= type :inner) depth 0))
max-depth (transduce (map get-depth) max 0 specs)
key-order (cond
(qualified-symbol? key) 0
(simple-symbol? key) 1
(pattern? key) 2)]
[(- max-depth) key-order (str key)]))
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.
done
Thanks for the update, and apologies for the delay in reviewing it. This past month has been rather busy for me. |
Fixes #349
After spending a few hours trying to figure out the best way to solve this problem without changing too much stuff I decided to changed the
indent
order code as follows:[[:block 1] [:inner 1]]
now get compiled to separate indenters for each part of the spec e.g. one for[:block 1]
and one for[:inner 1]
:inner
specs with depth greater than zero are sorted preferentially with deeper depths sorted first.Previously in #349 the
sorted-indents
herecljfmt/cljfmt/src/cljfmt/core.cljc
Line 384 in d84bd41
would have looked like
This PR changes them so they now look like
This ensures nested
:inner
indenters take precedence over general top-level indenters anddefprotocol
/extend-protocol
/etc. are applied in a sane way.