-
Notifications
You must be signed in to change notification settings - Fork 2
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
Use refactor-nrepl 3.3.2 #202
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,32 +64,45 @@ | |
(make-cleaner how-to-ns-opts refactor-nrepl-opts namespaces-that-should-never-cleaned libspec-whitelist filename) | ||
how-to-ns-opts))) | ||
|
||
(defmacro with-memoized-libspec-allowlist | ||
"Uses refactor-nrepl's 'memoized libspec' facility for best performance, | ||
while respecting formatting-stack's need of lazily requiring refactor-nrepl." | ||
{:style/indent 0} | ||
[& body] | ||
`(do | ||
(require 'refactor-nrepl.ns.libspec-allowlist) | ||
((resolve 'refactor-nrepl.ns.libspec-allowlist/with-memoized-libspec-allowlist*) | ||
(fn [] | ||
~@body)))) | ||
|
||
(defn format! | ||
[this files] | ||
(->> files | ||
(process-in-parallel! (fn [filename] | ||
(when-let [ns-replacement (replaceable-ns-form this filename)] | ||
(println "Cleaning unused imports:" filename) | ||
(write-ns-replacement! filename ns-replacement))))) | ||
(with-memoized-libspec-allowlist | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This macro invocation could be a Could be revisited later when f-s' new API becomes an actual thing |
||
(->> files | ||
(process-in-parallel! (bound-fn [filename] | ||
(when-let [ns-replacement (replaceable-ns-form this filename)] | ||
(println "Cleaning unused imports:" filename) | ||
(write-ns-replacement! filename ns-replacement)))))) | ||
nil) | ||
|
||
(defn lint! [this files] | ||
(->> files | ||
(process-in-parallel! (fn [filename] | ||
(when-let [{:keys [final-ns-form-str | ||
original-ns-form-str]} (replaceable-ns-form this filename)] | ||
(let [diff (diff/unified-diff filename original-ns-form-str final-ns-form-str)] | ||
(->> (diff->line-numbers diff) | ||
(mapv (fn [{:keys [start]}] | ||
{:filename filename | ||
:diff diff | ||
:level :warning | ||
:column 0 | ||
:line start | ||
:msg "ns can be cleaned" | ||
:source :formatting-stack/clean-ns}))))))) | ||
(filter some?) | ||
(mapcat ensure-sequential))) | ||
(with-memoized-libspec-allowlist | ||
(->> files | ||
(process-in-parallel! (bound-fn [filename] | ||
(when-let [{:keys [final-ns-form-str | ||
original-ns-form-str]} (replaceable-ns-form this filename)] | ||
(let [diff (diff/unified-diff filename original-ns-form-str final-ns-form-str)] | ||
(->> (diff->line-numbers diff) | ||
(mapv (fn [{:keys [start]}] | ||
{:filename filename | ||
:diff diff | ||
:level :warning | ||
:column 0 | ||
:line start | ||
:msg "ns can be cleaned" | ||
:source :formatting-stack/clean-ns}))))))) | ||
(filter some?) | ||
(mapcat ensure-sequential)))) | ||
|
||
(defn new [{:keys [refactor-nrepl-opts libspec-whitelist how-to-ns-opts namespaces-that-should-never-cleaned] | ||
:or {namespaces-that-should-never-cleaned default-namespaces-that-should-never-cleaned | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(ns unit.formatting-stack.formatters.clean-ns | ||
(:require | ||
[clojure.test :refer [deftest is testing]] | ||
[formatting-stack.formatters.clean-ns :as sut] | ||
[formatting-stack.strategies :as strategies])) | ||
|
||
(when (strategies/refactor-nrepl-available?) | ||
(deftest with-memoized-libspec-allowlist | ||
(testing "Binds `*libspec-allowlist*`, which means that memoization will be effectively used" | ||
(let [bound? (fn [] | ||
@(resolve 'refactor-nrepl.ns.libspec-allowlist/*libspec-allowlist*))] | ||
(assert (not (bound?))) | ||
(is (sut/with-memoized-libspec-allowlist | ||
(bound?))))))) |
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.
What about requiring-resolve?
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.
It's not available in every clojure version, so I tend not to use it in tooling projs
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.
F-s ships with clojure 1.10.3, so I think you're safe 😁
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! Also bumped r-n again for https://github.com/clojure-emacs/refactor-nrepl/blob/6529ec03c854eddcd0b62f359378d066e9d88d3d/CHANGELOG.md#332