-
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 kondo api #102
Use kondo api #102
Conversation
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.
Great work!
I'd have exactly one PR for all things Kondo, fixing all rough edges at once.
- An essential feature is cache invalidation (changed code should invalidate cached kondo analyses)
- Should be part of the QA plan
- Another essential feature is selective choice of linters, depending on the type of consumer project
- This is hinted in
maybe it's ideal to enable arity checking only for a specific case: if at least 1 .cljs file is present in the project
(Use Kondo's new Clojure API + project cache #91) - Might need some careful thinking about the notion of
strategies
. Discuss first
- This is hinted in
- The most meaningful QA plan is ensuring that there are false positives in cljs (especially wrt arity) with f-s 1.0.1, and that they are gone with this PR
- Another usual suspect is our
test-runner
ns pattern. It always complains about unused requires
- Another usual suspect is our
Given we are changing things like strategies, protocols etc, it's likely that this PR is best left open for some time.
I would not merge #102 as-is because it would not add a tangible benefit (internals change, not without risk as Kondo itself may have changed)
project.clj
Outdated
@@ -1,7 +1,7 @@ | |||
;; Please don't bump the library version by hand - use ci.release-workflow instead. | |||
(defproject formatting-stack "1.0.1" | |||
;; Please keep the dependencies sorted a-z. | |||
:dependencies [[clj-kondo "2019.05.19-alpha"] | |||
:dependencies [[clj-kondo "2019.12.14"] |
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.
Make sure that all new linters added since the last version are excluded from JVM clojure, if they are redundant with Eastwood, or if they can possibly give false positives
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.
#{:datalog-syntax
:type-mismatch
:misplaced-docstring
:consistent-alias
:if
:use
:unused-referred-var
:not-empty?
:file
:refer-all
:unresolved-symbol
:cond-else
:missing-docstring
:unused-import
:deprecated-var
:unbound-destructuring-default
:syntax
:not-a-function
:duplicate-require
:unused-private-var
:unresolved-namespace
:unreachable-code
:redefined-var
:unused-binding}
These are the new linters since 2019.05.19-alpha
. The following are redundant i think;
:consistent-alias
: duped by how-to-ns:duplicate-require
: duped by clean-ns:unused-import
: duped by clean-ns:unused-namespace
: duped by clean-ns:unused-referred-var
: duped by clean-ns:deprecated-var
: duped by Eastwood:redefined-var
: duped by Eastwood:refer-all
: can't exclude clojure.test
But I'm not confident this is all. clj-kondo has less extensive documentation on linters and their behavior (compared to eastwood) so it's hard to determine the exact result.
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.
Alright, thanks for this one!
This is my initial judgement:
:cond-else ;; NOK (some of use prefer `true`)
:consistent-alias ;; f-s
:datalog-syntax ;; ?
:deprecated-var ;; eastwood
:duplicate-require ;; clean-ns
:file ;; ?
:if ;; ?
:misplaced-docstring ;; eastwood
:missing-docstring ;; NOK (docstrings at our discretion)
:not-a-function ;; ?
:not-empty? ;; ?
:redefined-var ;; Eastwood
:refer-all ;; OK (I'll be happy to improve our clojure.test usage. It's not cljs-friendly anyway)
:syntax ;; ?
:type-mismatch ;; speced.def
:unbound-destructuring-default ;; ?
:unreachable-code ;; OK
:unresolved-namespace ;; clean-ns
:unresolved-symbol ;; NOK (kondo works statically, cannot know every corner case)
:unused-binding ;; OK
:unused-import ;; clean-ns
:unused-private-var ;; NOK (kondo works statically, cannot know every corner case)
:unused-referred-var ;; clean-ns
:use ;; OK
The ?
s can be researched at some point. I don't know what they do and/or whether they're 100% reliable
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.
applied your suggestions, also gathered examples for the unknown linters
:datalog-syntax
;; reports faulty queries e.g. unknown vars; see https://git.io/Jejbj
:file
;; reports when file's can't be read or do not exist. different than broken syntax of a file (see :syntax)
;; https://github.com/borkdude/clj-kondo/blob/ca94d2b749447e7441f5d25961f765286413ba97/src/clj_kondo/impl/core.clj#L182-L200
:if
;; reports on missing else branch
;; https://github.com/borkdude/clj-kondo/blob/de4931f9f39d6eba92b15b3323d5b6a92437a78b/src/clj_kondo/impl/analyzer.clj#L967
:not-a-function
;; warns when type is a known type which isn't a ifn, e.g:
(defn t [] ("wat"))
:not-empty?
;; warns on (not (empty? ...)) in favor of (seq)
:syntax
;; triggers on reader errors, e.g:
(a
:unbound-destructuring-default
;; reports on 'extra' keys in :or. (`j` in this example)
(let [{:keys [:i] :or {i 2 j 3}} {}] i)
:type-mismatch
seems to do something different than speced.def; see https://github.com/borkdude/clj-kondo/blob/de4931f9f39d6eba92b15b3323d5b6a92437a78b/test/clj_kondo/types_test.clj. it warns on known-bad usage of clj.core usage.
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.
Some stuffs
Happy to have the current clj<->cljs dispatching thing as a POC, thanks for that one!
a60851f
to
59f11d9
Compare
59f11d9
to
5a8d431
Compare
b4059b1 prevents processing the classpath more than once; (let [processor (formatting-stack.processors.kondo/new)]
(time (formatting-stack.protocols.processor/process! processor
(strategies/all-files)))
(time (formatting-stack.protocols.processor/process! processor
(strategies/all-files))))
"Elapsed time: 21294.871522 msecs"
"Elapsed time: 396.488685 msecs" This enables us to enable processing in the normal stack.
Updated QA and found that the cache is recreated with each run. As long as changed files are provided to the processor, it'll be fine.
I'm not entirely sure how to test this, not really familiar with cljs. Got anything in mind? |
Not sure:
That might call for placing the state in the
I'll try to prepare a couple reprodudible scenarios |
Continued in #109 |
Brief
Removes vendorized clj-kondo source in favor of public api.
discuss compiler and disabled linter-options in kondo
QA plan
cache invalidation:
run this snippet:
notice folder creation:
$ ls -lah .clj-kondo/*/clj/formatting-stack.util.transit.json
Run the snippet again; notice new modified date.
Author checklist
Reviewer checklist