-
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 indentation for symbols in reader conditionals #348
Fix indentation for symbols in reader conditionals #348
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
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 have some comments/changes after a review.
cljfmt/src/cljfmt/core.cljc
Outdated
"Given a zipper pointing to a reader conditional form like | ||
|
||
#?(:clj potemkin.core/defprotocol+ :cljs defprotocol) | ||
|
||
Return the first symbol inside it e.g. | ||
|
||
potemkin.core/defprotocol+" |
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.
Can you remove this docstring? Since this is a private function, we don't need to give it public documentation. Instead, perhaps improve the function name. Something like: first-symbol-in-reader-conditional
.
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
cljfmt/src/cljfmt/core.cljc
Outdated
;; find the first keyword e.g. `:clj` | ||
(when-let [key-loc (z/find (-> zloc z/down z/right z/down) | ||
z/right | ||
#(n/keyword-node? (z/node %)))] |
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.
Maybe instead of the comment, we use a more descriptive function:
(when-key [key-zloc (-> zloc z/down z/right z/down find-next-keyword)]
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
cljfmt/src/cljfmt/core.cljc
Outdated
;; now move to the next non-whitespace/non-comment/non-metadata node after | ||
;; the keyword node e.g. `potemkin.core/defprotocol+`. |
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.
I don't think we need this comment, the code seems clear enough, and if it isn't, we should split it out into more functions. Ideally comments should explain "why" rather than "what".
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
ce787be
to
606380b
Compare
Things like
were not indenting correctly despite having indentation specs defined for both
potemkin.core/defprotocol+
anddefprotocol
.This PR reworks
form-symbol
a little bit to return the first symbol it finds when it encounters#?
forms -- in this case,potemkin.core/defprotocol+
(meaning the form above will be formatted using that spec). Does not currently work with#?@
reader conditionals, but I wasn't sure how that should realistically work anyway.