-
-
Notifications
You must be signed in to change notification settings - Fork 290
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
Offer a Clojure API #226
Comments
Hi @vemv, You can already use clj-kondo from Clojure like this:
You'll have to pass in strings as arguments, but the command line API can be considered stable. So out of the box, clj-kondo on the JVM should already do what you want, except for having a Clojure-y API instead of passing strings. Do I understand this correctly? Note that when running in a JVM with a newer tools.reader version than rewrite-clj uses: |
Hi @borkdude , thanks for the reply!
Builing argument vectors and
Saw that one, ace! (I had done the adaptation work a few days before that)
Arrgh, unfortunate one. Too bad rewrite-clj is currently on a hiatus. Personally I can live with it atm (nothing at work needs the latest tools.reader), and maybe by the time I need to upgrade, rewrite-clj will be fixed as well (or in any case: hacking seems possible) As a last observation, the current API does not leverage |
Summary of Slack discussion with @vemv: I will document the output format which can then be filtered (#230). |
Just for the sake of persistence, other interesting points that popped up were:
As a last observation, I think the current Would address both my perceived needs, and those expressed in https://twitter.com/simon_brooke/status/1130382052996669441 , while keeping Kondo's codebase DRY (i.e. I'm not particularly asking for adding more code, but for splitting/refactoring certain code). |
Hi, I'm sort-of working (that is to say, writing experimental conceptual code) on a unified wrapper for existing Clojure code quality tools. It's really not ready for other folk to look at yet, but for the purposes of this discussion I've put it up here. The important document is probably this one. Regardless of whether my tool ever becomes useful or not, it does seem to me that it would be valuable for tools which generate commentary on Clojure code to output a common, standardised, easily parseable notation, in order that that notation can be consumed by other tools. |
Reviewed! Idea and format seem sound to me. I have a linter-wrapping tool with ~6 months of (occasional) progress. I don't think it competes with your idea/goals and one project could benefit from the other. Will ping you as I open-source it (this/next week) |
@simon-brooke To answer your question about accepting a PR: to save you time, it's probably better if I add the EDN output, since I'm refactoring the main namespace quite a bit. Would you like to have this printed to stdout or returned as values? |
@vemv I've got a first version here: #231
@simon-brooke With this in place, it's trival to output EDN. I may rename the |
That looks fine to me. In conjunction to the pull request I've just submitted, I think we have something. I'd leave |
( |
@vemv The API now looks like this: (require '[clj-kondo.core :as clj-kondo])
(def findings
(:findings
(clj-kondo/run!
{;; seq of string or file
:files ["corpus" (io/file "test")]
:config {:linters {:invalid-arity {:level :off}}}
;; :cache takes a string, file or boolean
:cache (io/file "/tmp/clj-kondo-cache")
;; only relevant when linting stdin
:lang :clj})))
(first findings)
(clj-kondo/print-findings! res) |
That looks good: I can work with that. This is the |
@simon-brooke confirmed! I'll add some tests to it. if you have feedback on the API (naming, etc.) now is the time for change. 🙂 |
I absolutely don't mind what keys you have, provided they're consistent and distinct. Rewriting keys in a map is trivial and not very expensive. What I mind is all the data is available, which in your proposed structure if seems to be. |
small change: |
Fixed with bb80290 |
commit e394cb5 Author: Michiel Borkent <michielborkent@gmail.com> Date: Sat Jun 8 15:01:46 2019 +0200 replace instead of merge config commit 179fdcf Author: Michiel Borkent <michielborkent@gmail.com> Date: Fri Jun 7 10:41:00 2019 +0200 bump versions commit cfaf526 Author: Michiel Borkent <michielborkent@gmail.com> Date: Fri Jun 7 10:19:49 2019 +0200 v2019.06.07-alpha commit 44d9ba1 Author: Michiel Borkent <michielborkent@gmail.com> Date: Thu Jun 6 21:40:16 2019 +0200 fix false positive with associative destructuring commit 627a22c Author: Michiel Borkent <michielborkent@gmail.com> Date: Thu Jun 6 12:29:34 2019 +0200 clojure API: files -> lint commit bb80290 Author: Michiel Borkent <michielborkent@gmail.com> Date: Thu Jun 6 10:33:56 2019 +0200 Clojure/JVM API Implements feature request in #226
Is your feature request related to a problem?
I like to run formatters/linters in the following way:
Where
user/format!
invokes cljfmt et al (via their Clojure APIs), and since very recently, clj-kondo too.I used main for that, however that ns is not an API, as you reflect in the README, so I had to hack things a little.
Describe the solution you'd like
An
api
ns (orapi.alpha
, if you will) which would expose a function similar tomain
but with the following improvements:TODO: move global state to local context
)Describe alternatives you've considered
There's the alternative of disregarding the Reloaded integration, but it's a formula that has worked well for me for quite long now, with ~10 formatters/linters integrated. Git integration and multithreading speed things up.
So I'm happy with the vanilla JVM and with avoiding Graal as long as possible, which would represent another yet moving piece in the stack.
Btw, as expected Kondo is really fast! Certainly fast enough to not get in my way in Reloaded.
WDYT?
Cheers - V
The text was updated successfully, but these errors were encountered: