clj-kondo

https://github.com/clj-kondo/clj-kondo
wilkerlucio 2020-06-18T04:01:33.405100Z

hello, one curiosity, when you have many projects and would like to keep the lint configuration consistent between then, is there a nice way to keep a single file serving many projects?

borkdude 2020-06-18T06:53:11.407700Z

@wilkerlucio I recommend writing a babashka script to generate/update your project configs. Clj-kondo has an API function called merge-configs which can also be used for this and can be invoked as a pod function

dominicm 2020-06-18T07:28:05.409900Z

@borkdude with 468, it's about linting a single function, it's about linting the whole file. Eg implementing my own version of unused refers, or something like that. Generating an arbitrary message for anywhere in the file.

borkdude 2020-06-18T09:41:37.410900Z

I'm considering switching entirely to rewrite-clj node based transformations instead of converting them to sexprs and parse the transformed sexpr as rewrite-clj nodes again as it's quite difficult to preserve location metadata, for the "macroexpand" feature

borkdude 2020-06-18T09:43:08.411900Z

Still, the sexpr can be used for some validations, when people don't "macroexpand"

borkdude 2020-06-18T10:41:55.412500Z

it's a bit unfortunate since working with sexprs is more ergonomic than rewrite-clj nodes... but preserving location information is really important for clj-kondo

borkdude 2020-06-18T11:11:25.413700Z

I think he just affirmed my belief that it's good to not use sexprs but work directly with the source nodes in that response

Sean Poulter 2020-06-18T19:00:49.419400Z

Hey folks. Can I bounce a wild idea off someone? I’ve come over JavaScript in the last year and trying to find the Clojure-ish way to walk the AST to find where some of my function calls use third-party libraries. I heard about the analysis output from clj-kondo on Jacek Schae’s podcast, but it seem to have a way to connect the variable usage (call site) to the function that calls it. Does that sound right? I probably need to find something to work with the AST, eh?

Sean Poulter 2020-06-18T19:01:41.420400Z

Thanks in advance for thinking about it, and a huge thanks to Michiel for sharing all your tools. ❤️

borkdude 2020-06-18T19:02:45.421Z

@sean.poulter Using the analysis output you can see where a third party library is called: https://github.com/borkdude/clj-kondo/tree/master/analysis

👍 1
borkdude 2020-06-18T19:03:04.421500Z

see :var-usages

Sean Poulter 2020-06-18T19:03:10.421600Z

Yea, I’ve found the call sites that way which is awesome.

Sean Poulter 2020-06-18T19:03:55.422500Z

I don’t think we can find the enclosing function though. I’ve got to walk the call stack to figure out where that third-party code is called from our public APIs.

borkdude 2020-06-18T19:04:28.423200Z

you want to know the enclosing defining function? you can do that I think

borkdude 2020-06-18T19:05:27.424500Z

there are at least a few tools making visual representations of this using the analysis data, so it should be possible

borkdude 2020-06-18T19:05:32.424700Z

let me have a look

Sean Poulter 2020-06-18T19:06:35.425400Z

Here’s an entry from the var-usages:

{ filename: 'src/my/components/widgets/list/views.cljs', 
  row: 14, 
  col: 6, 
  from: 'my.components.widgets.list.views', 
  to: 'other.components', 
  name: 'Flow', 
  'from-var': 'widget' } 

Sean Poulter 2020-06-18T19:07:13.425700Z

Oh…. oh. 😐

borkdude 2020-06-18T19:07:14.425900Z

from-var

Sean Poulter 2020-06-18T19:07:26.426300Z

Yea… macros!

Sean Poulter 2020-06-18T19:07:43.426600Z

The macros have me all confused. Thanks!

borkdude 2020-06-18T19:08:10.427400Z

so with from-var + from (the ns) you know in which defn this happens

👍 1
borkdude 2020-06-18T19:08:38.428Z

I do notice that this isn't in the documentation

borkdude 2020-06-18T19:08:44.428300Z

so sorry for the confusion

Sean Poulter 2020-06-18T19:08:44.428400Z

Can I add from-var to https://github.com/borkdude/clj-kondo/tree/master/analysis for you?

Sean Poulter 2020-06-18T19:08:47.428600Z

All good.

borkdude 2020-06-18T19:08:49.428800Z

yes please

Sean Poulter 2020-06-18T19:09:04.429200Z

Cool. I’ll put something up in the next day or two after work. 🤓

borkdude 2020-06-18T19:09:42.429700Z

thanks a lot. there are a few cool tools built on top of this: https://github.com/borkdude/clj-kondo/issues/836

borkdude 2020-06-18T19:10:11.430300Z

these two: https://github.com/SevereOverfl0w/vizns https://github.com/benedekfazekas/morpheus visualize the analysis output in interesting ways

borkdude 2020-06-18T19:11:27.431900Z

@sean.poulter I'm also building something like this: https://twitter.com/borkdude/status/1273384546269040646/photo/1 so you can write a hook and make a custom linter once clj-kondo analyses the usage of a function. but it won't be released soon probably

Sean Poulter 2020-06-18T19:11:56.432400Z

Neat.

Sean Poulter 2020-06-18T19:12:28.433100Z

Wow, thanks. I can use Morpheus to solve my “where is this stuff used?” question too! 👏

borkdude 2020-06-18T19:12:55.433400Z

Also carve is interesting to cut out unused stuff

👍 1
Sean Poulter 2020-06-18T19:15:44.434200Z

Wow. That’s neat too! Thanks! 😀

Sean Poulter 2020-06-18T19:16:34.435200Z

This is one of those “I wish I could hang out and watch how (person) works” moments. That’s some really neat tooling we weren’t aware of.

borkdude 2020-06-18T21:46:14.435700Z

anyone want to add clj-kondo to this? https://github.com/github/super-linter https://github.com/github/super-linter/issues/111