clj-kondo

https://github.com/clj-kondo/clj-kondo
snoe 2020-08-29T00:34:12.037600Z

I'd like to start a thread about the possibility of adding the ability to go from a cursor position to an analyzer entry. Continuing https://github.com/snoe/clojure-lsp/pull/176#issuecomment-683123972

borkdude 2020-08-29T08:43:18.039700Z

Maybe we can use the existing analysis hook or introduce new ones to be able to get other tooling to profit as well, in addition to the analysis info

snoe 2020-08-30T00:55:55.067200Z

I noticed that sometimes the (meta (:name %)) gives the position info, but not always... maybe we just need to make that more consistent.

borkdude 2020-08-30T15:01:43.006100Z

what is :name in this context?

snoe 2020-08-31T14:13:12.007100Z

@borkdude it's a mix of the analysis types, so var-usages seem to have meta on :name but on var-definitions and namespace-definitions and namespace-usages it is nil. I think if we always fill this in from rewrite-cljc I'd be able to use it for my purposes. Is it worth making an issue or do you foresee performance problems or difficulties with this approach?

snoe 2020-08-29T00:48:19.037800Z

I imagine the difficulty comes in with macros, and the reticence is because linting may not need it? I think carve shows the utility of the analyzer itself, so I wonder if we think about other tools it could be a useful exercise. Renaming, I think, is right up there beside dead code for utility. A cli tool that could correct any inconsistent aliases, or rename a fully qualified var without resorting to sed and careful diff checking. Is it fair to want the analyzer to grow beyond kondo with some examples like this?

snoe 2020-08-29T00:52:56.038200Z

My thinking is that kondo's analyzer feels like the closest thing we have to a tooling analyzer.

borkdude 2020-08-29T06:25:32.038600Z

Some exciting news! https://www.clojuriststogether.org/news/q3-2020-funding-announcement/

🎉 8
practicalli-john 2020-08-29T15:40:49.040400Z

Congratulations, very much deserved

borkdude 2020-08-29T15:41:15.040600Z

Same to you! :)

borkdude 2020-08-29T06:36:37.038800Z

I think I'm fine with this, with the following caveats: 1) Some things are easier to lint while analyzing, this is why clj-kondo intertwines linting with analysis sometimes. So splitting an analyzer into a library is hard because of this. 2) I don't like clj-kondo linting getting slower because of extra work it has to do for other projects. The in-editor experience should be as fast as possible. So if we can prevent that, that's cool. I think we can accomplish that just using some configuration options.

💯 1
borkdude 2020-08-29T06:39:05.039Z

Btw, carve uses clj-kondo analysis but then rewrites the code using rewrite-cljc, not using kondo. So it only uses the data output.

borkdude 2020-08-29T06:42:53.039400Z

There are some other issues that have to do with analysis here: https://github.com/borkdude/clj-kondo/issues?q=is%3Aissue+is%3Aopen+label%3Aanalysis

jaihindhreddy 2020-08-29T19:09:12.041600Z

Does clj-kondo compile with the following java -version?

openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03)
OpenJDK 64-Bit Server VM GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03, mixed mode, sharing)

borkdude 2020-08-29T19:09:40.042Z

it should yes

jaihindhreddy 2020-08-29T19:10:09.042600Z

I just tried it, and got this error:

Error: Already registered: java.util.zip.ZipFile$CleanableResource.get(ZipFile, File, int)
com.oracle.svm.core.util.UserError$UserException: Already registered: java.util.zip.ZipFile$CleanableResource.get(ZipFile, File, int)
...
...
...
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
	at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1558)
	at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1308)
	at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1269)
	at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1228)
	at com.oracle.svm.driver.NativeImage$JDK9Plus.main(NativeImage.java:1740)

borkdude 2020-08-29T19:10:15.042900Z

Ah 20.2, haven't tried it yet, currently using 20.1. But 20.2 should work

borkdude 2020-08-29T19:10:20.043100Z

Aaah

borkdude 2020-08-29T19:10:26.043400Z

I know what this is. Just use 20.1 for now

jaihindhreddy 2020-08-29T19:10:33.043700Z

Sure. Thanks!

borkdude 2020-08-29T19:10:34.043800Z

I'll upgrade soon

💯 1
borkdude 2020-08-29T19:11:19.044900Z

Or, if you feel like it, you can do it. The clojure reflector fix should be bumped to 20.2 in project.clj, but also other references in the CircleCI and Github config

👍 1
jaihindhreddy 2020-08-29T19:12:02.045100Z

this, I assume: https://github.com/borkdude/clj-reflector-graal-java11-fix

borkdude 2020-08-29T19:12:22.045400Z

yes

👍 1
jaihindhreddy 2020-08-29T19:30:39.046Z

Would you rather me make a PR directly, or make an issue first?

jaihindhreddy 2020-08-29T19:41:02.047100Z

Well, https://github.com/borkdude/clj-kondo/pull/979, but added diffs in resources/clj_kondo/impl/cache/built_in/clj/clojure.pprint.transit.json and resources/clj_kondo/impl/cache/built_in/clj/clojure.tools.reader.transit.json. Should I add these to .gitignore?

jaihindhreddy 2020-08-29T19:41:44.047700Z

also, wow native-image takes a lot of RAM (to compile)!

borkdude 2020-08-29T19:58:23.048400Z

Please don't add resources/* to .gitignore, it's essential to clj-kondo. Also, I wonder how did you end up with a diff in there, it's not relevant to the PR?

borkdude 2020-08-29T19:59:15.048700Z

So I would rather have you reset that file to the old one

borkdude 2020-08-29T20:03:16.049300Z

Yeah, GraalVM is quite heavy on the RAM, although for clj-kondo it doesn't go above 2 or 3GB I think?

jaihindhreddy 2020-08-29T20:13:10.051400Z

> So I would rather have you reset that file to the old one Done. > Please don't add resources/* to .gitignore, it's essential to clj-kondo. After reading docs/dev.md, I get this now. > Also, I wonder how did you end up with a diff in there, it's not relevant to the PR? Yeah, it's quite weird. I'm using clojure version 1.10.1.561. Not sure if that can make a difference. I'll see what the actual difference is.

borkdude 2020-08-29T20:17:27.051600Z

Thanks, merged!

🎉 1
jaihindhreddy 2020-08-29T20:50:06.056700Z

Courtesy of https://cljdoc.org/d/lambdaisland/deep-diff/0.0-47/doc/readme, I was able to find out the differences in the resources. clojure.pprint's cache had the following differences (Addition of :arities):

c-write-char {:col 1,
              :fixed-arities #{2},
              :name c-write-char,
              :ns clojure.pprint,
              :private true,
              :row 47,
              :top-ns clojure.pprint,
              +:arities {2 {:args (nil :nilable/int)}}},


p-write-char {:col 1,
              :fixed-arities #{2},
              :name p-write-char,
              :ns clojure.pprint,
              :private true,
              :row 360,
              :top-ns clojure.pprint,
              +:arities {2 {:args (nil :nilable/int)}}},
And clojure.tools.reader had the following:
read+string {:arities {0 {:ret :vector},
                       +1 {:ret :vector},
                       +2 {:ret :vector},
                       +3 {:ret :vector},
                       -:varargs {:min-arity 1, :ret :vector}}, ;; this got removed the the above 3 arities got added.
             :col 1,
             :fixed-arities #{0 +1 +2 +3},
             :name read+string,
             :ns clojure.tools.reader,
             :row 1008,
             :top-ns clojure.tools.reader,
             -:varargs-min-arity 1}, ;; this got removed as well.
Not sure why this is though. All three functions weren't changed in a long time.

borkdude 2020-08-29T20:52:43.057200Z

Have you ran any scripts locally that updated these files?

jaihindhreddy 2020-08-29T20:53:11.057800Z

I did run script/built-in. Should have mentioned this beforehand :man-facepalming:

borkdude 2020-08-29T20:53:48.058500Z

I haven't ran those in a while. It could be that some logic related to that changed.

👍 1
borkdude 2020-08-29T20:54:54.059500Z

if you think the changes are correct, then we could add those as well

jaihindhreddy 2020-08-29T20:55:14.059700Z

Yeah, https://github.com/clojure/tools.reader/blob/master/src/main/clojure/clojure/tools/reader.clj#L1009 never had a variadic arity. Seems like the new file is correctly identifying arities 0, 1, 2, 3.

borkdude 2020-08-29T20:55:36.060200Z

I have a script, script/dump_types that dumps type information in a diff-able manner

borkdude 2020-08-29T20:56:03.061Z

So when you run that on master and on your branch, it's easier to spot differences

borkdude 2020-08-29T20:56:44.061900Z

It could also be that one of the deps in clj-kondo got bumped, and the arities changed?

jaihindhreddy 2020-08-29T20:56:44.062Z

Got it. Although, apart from having to read with transit, I don't think it's un-diffable

jaihindhreddy 2020-08-29T20:57:36.062900Z

> It could also be that one of the deps in clj-kondo got bumped, and the arities changed? I git-blamed those three functions, and they didn't change in years. So this is unlikely.

borkdude 2020-08-29T20:57:57.063200Z

then clj-kondo must have had an error before

🙂 1
jaihindhreddy 2020-08-29T20:58:37.063400Z

:man-shrugging:

borkdude 2020-08-29T21:02:31.064100Z

@jaihindhreddy So I ran script/built-in and script/dump-types. Then made a branch: https://github.com/borkdude/clj-kondo/pull/980/files Now the diff is readable in Github, is what I mean

💯 1
jaihindhreddy 2020-08-29T21:04:06.064500Z

I get it now. Thanks for clarifying!

borkdude 2020-08-29T21:04:44.065Z

I'll just hook script/dump-types into script/built-ins, so we get it automatically

jaihindhreddy 2020-08-29T21:05:08.065200Z

good idea.

borkdude 2020-08-29T21:20:37.066Z

Merged. Also updated the script (since now babashka has had transit for a while).

1
borkdude 2020-08-29T21:22:25.066800Z

It's funny, you can also run that script using clojure script/dump_types.clj since all the deps are in deps.edn as well. But Clojure prints namespaced maps in script-mode it seems (https://clojuredocs.org/clojure.core/*print-namespace-maps*)

borkdude 2020-08-29T21:25:02.067100Z

This works: $ clojure -e "(set! *print-namespace-maps* false)" script/dump_types.clj