clj-kondo

https://github.com/clj-kondo/clj-kondo
borkdude 2020-06-19T08:40:01.436400Z

maybe @delaguardo ^?

2020-06-19T08:42:22.437400Z

I already reserve few hours this weekend for that)

borkdude 2020-06-19T08:42:54.437600Z

๐Ÿ˜„ โค๏ธ

borkdude 2020-06-19T10:05:27.438200Z

This is an example of rewriting a slingshot/try+ call to something clj-kondo understands using the new "hooks" functionality: https://github.com/borkdude/clj-kondo/blob/macros-sci/corpus/.clj-kondo/macroexpand/try_plus.clj

borkdude 2020-06-19T10:05:38.438600Z

(cc @martinklepsch)

borkdude 2020-06-19T10:08:47.439600Z

it's not the easiest macro example, but it shows that it's possible to do it. this is an easier one which is syntactically isomorphic to the jdbc with-transaction macro: https://github.com/borkdude/clj-kondo/blob/macros-sci/corpus/.clj-kondo/macroexpand/weird_macro.clj

borkdude 2020-06-19T14:38:21.440400Z

@martinklepsch so this is a newer version of a hook that can teach clj-kondo about rum defc: https://github.com/borkdude/clj-kondo/blob/81e3e8a66beaf07c011546ff89b7d7358cd00644/corpus/macroexpand.clj#L74-L111

borkdude 2020-06-19T14:38:47.441Z

Note, the string in the config is only for demo, it may also be a filepath relative to the .clj-kondo directory

borkdude 2020-06-19T14:50:49.442900Z

I might still rename the naming of {:hooks {rum/defc ...}} since this gets invoked during analysis of a call only. so maybe {:hooks {:analyze-call {rum/defc ...}}} might be better for future extension

borkdude 2020-06-19T14:51:19.443300Z

and then we could potentially add more and more hooks

borkdude 2020-06-19T14:53:22.443600Z

but that's a minor detail.

martinklepsch 2020-06-19T15:05:04.443800Z

downloaded this binary and added the config to the ns form of a file but it seems to behave as before

martinklepsch 2020-06-19T15:05:17.444Z

Iโ€™m pretty sure the right clj-kondo binary is used

martinklepsch 2020-06-19T15:06:28.444200Z

clj-kondo v2020.06.13-SNAPSHOT

borkdude 2020-06-19T15:10:36.444500Z

can you give me that same file?

borkdude 2020-06-19T15:12:45.444700Z

borkdude 2020-06-19T15:12:48.445100Z

works for me

borkdude 2020-06-19T15:13:04.445300Z

can you try running clj-kondo --lint rum.clj?

borkdude 2020-06-19T15:13:31.445500Z

it should output:

$ clj-kondo --lint /tmp/rum.clj
/tmp/rum.clj:35:1: error: quux/with-mixin is called with 4 args but expects 1
/tmp/rum.clj:35:13: error: unresolved symbol a
/tmp/rum.clj:37:1: warning: redefined var #'quux/with-mixin

martinklepsch 2020-06-19T15:28:27.445700Z

figured it out by trying to trim down my file

martinklepsch 2020-06-19T15:28:49.445900Z

the :hooks key should use the fully qualified macro name

{:clj-kondo/config '{:hooks {rum.core/defc "

martinklepsch 2020-06-19T15:29:11.446200Z

before the key was just rum/defc

martinklepsch 2020-06-19T15:29:47.446400Z

but these macros live in rum.core

borkdude 2020-06-19T15:30:10.446600Z

yeah sorry, that was just for my own tests ๐Ÿ™‚ I actually don't use rum so I didn't bother to look what the real ns name was ๐Ÿ™‚

martinklepsch 2020-06-19T15:31:08.446900Z

very very cool though, seems to work great!

borkdude 2020-06-19T15:40:12.447100Z

thanks for testing

martinklepsch 2020-06-19T15:40:53.447300Z

my pleasure, very excited to get this into our CI ๐Ÿ™‚

borkdude 2020-06-19T15:43:00.447500Z

so how many variations of this defc macro are there, only one?

borkdude 2020-06-19T15:44:09.447700Z

rum/defcs I see, is that syntactically the same as defc?

borkdude 2020-06-19T15:47:20.447900Z

if so, then adding a lint-as rule for this should work (it doesn't right now, but it can be made so)

martinklepsch 2020-06-19T17:33:40.448500Z

thereโ€™s also defcc but I think itโ€™s also the same

martinklepsch 2020-06-19T17:33:49.448700Z

they basically add extra arguments to the function

martinklepsch 2020-06-19T17:34:02.448900Z

so as long as the argvec is parsed correctly this should be fine

borkdude 2020-06-19T17:50:50.449100Z

ok then lint-as can also be used for that one, nice

borkdude 2020-06-19T20:09:35.449600Z

@delaguardo Seems someone worked on including clj-kondo into super-linter: https://github.com/github/super-linter/pull/197

2020-06-19T20:27:40.449900Z

That's even better) now I have free two hours on weekend)

2020-06-19T20:27:49.450100Z

:hugging_face: