Skip to content
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

Merged

Conversation

camsaul
Copy link
Contributor

@camsaul camsaul commented Aug 20, 2024

Things like

(#?(:clj potemkin.core/defprotocol+ :cljs defprotocol) MyProtocol
  ...)

were not indenting correctly despite having indentation specs defined for both potemkin.core/defprotocol+ and defprotocol.

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.

camsaul added a commit to metabase/metabase that referenced this pull request Aug 21, 2024
camsaul added a commit to metabase/metabase that referenced this pull request Aug 21, 2024
* 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
Copy link
Owner

@weavejester weavejester left a 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.

Comment on lines 252 to 258
"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+"
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 261 to 264
;; 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 %)))]
Copy link
Owner

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)]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 265 to 266
;; now move to the next non-whitespace/non-comment/non-metadata node after
;; the keyword node e.g. `potemkin.core/defprotocol+`.
Copy link
Owner

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@camsaul camsaul force-pushed the fix-reader-conditional-symbols branch from ce787be to 606380b Compare August 22, 2024 17:16
@weavejester weavejester merged commit d750bc1 into weavejester:master Aug 25, 2024
1 check passed
@camsaul camsaul deleted the fix-reader-conditional-symbols branch August 28, 2024 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants