Fork me on GitHub
#clj-kondo
<
2020-06-18
>
wilkerlucio04:06:33

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?

borkdude06:06:11

@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

dominicm07:06:05

@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.

borkdude09:06:37

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

borkdude09:06:08

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

borkdude10:06:55

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

borkdude11:06:25

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 Poulter19:06:49

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 Poulter19:06:41

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

borkdude19:06:45

@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

👍 3
borkdude19:06:04

see :var-usages

Sean Poulter19:06:10

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

Sean Poulter19:06:55

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.

borkdude19:06:28

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

borkdude19:06:27

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

borkdude19:06:32

let me have a look

Sean Poulter19:06:35

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 Poulter19:06:13

Oh…. oh. 😐

Sean Poulter19:06:26

Yea… macros!

Sean Poulter19:06:43

The macros have me all confused. Thanks!

borkdude19:06:10

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

👍 3
borkdude19:06:38

I do notice that this isn't in the documentation

borkdude19:06:44

so sorry for the confusion

Sean Poulter19:06:04

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

borkdude19:06:42

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

borkdude19:06:27

@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 Poulter19:06:28

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

borkdude19:06:55

Also carve is interesting to cut out unused stuff

👍 3
Sean Poulter19:06:44

Wow. That’s neat too! Thanks! 😀

Sean Poulter19:06:34

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.