Fork me on GitHub
#clj-kondo
<
2022-02-15
>
lread02:02:30

I like failing my builds on lint warnings too. Keeps things nice and tidy, yeah?

Sam Ritchie16:02:09

I am getting pretty fancy over here with api/reg-finding! to throw specific linter warnings for my pattern-matching DSL

Sam Ritchie16:02:00

there are some confusing rules for (pattern (+ (? x odd?) ?y ?z)), and the linter can sort of… teach the user what to do as they type. “x must be a non-namespaced symbol”, etc, so awesome.

Sam Ritchie16:02:53

kind of makes me want to revive https://github.com/nathanmarz/cascalog… I have had thoughts over the years of writing it up as a literate program, would be fun to have a linter for the datalog syntax too

borkdude16:02:50

@sritchie09 clj-kondo already has linting built-in for datalog as well, via the datalog-parser library

Sam Ritchie16:02:54

@borkdude any chance I can beg for unquote? and friends to be exposed in the hooks API?

borkdude16:02:42

sure, but you can probably already do this by doing (:tag node) right?

Sam Ritchie16:02:45

whoops, yes 🙂

Sam Ritchie17:02:29

@borkdude should I rely on the fact that hook namespaces can require each other, or is that an accidental feature?

Stefan T19:02:53

I have to say, figuring out how to configure hooks has really filled in the gaps and eliminated most of the remaining false positives I used to have, great stuff! I was wondering, let’s say I have a couple dozen or so variations of a very similar macro that I would like to use the same hook for, is there any way I can avoid listing out every one of those in :analyze-call? Is it possible to configure :analyze-call with a function instead of a map?

borkdude21:02:59

@stefan.toubia currently not possible

borkdude21:02:27

you could of course just programmatically generate that map once :)

Stefan T21:02:33

Gotcha, thanks. In my case I have a handful of common macros generally used for testing, each project defines their own version but they all follow the same naming convention. It would be great to be able to just match the macro name, and avoid having to update the config when new macros are added. Will have to explore options for generating the config. Thanks for the advice!

borkdude21:02:27

@stefan.toubia This might also come in handy if you want to update the config programmatically: https://github.com/borkdude/rewrite-edn

Stefan T21:02:22

Thanks! I will give it a try!

Stefan T16:03:55

Hey @borkdude are there any options for maintaining/enforcing alphabetical ordering in a map when using rewrite-edn?

borkdude16:03:08

there's not a thing for it right now

Stefan T16:03:48

Ah darn, thanks.

Sam Ritchie21:02:36

@borkdude is it possible to use a :clj-kondo/ignore to ignore the custom errors registered by my library? This does not seem to be working, for reference:

#_{:clj-kondo/ignore [:sicmutils.rule/ruleset-args]}
(ruleset (+ (? x) (? y)) (fn [m] (- ('?x m) ('?y m))))

Sam Ritchie21:02:02

meaning, linting still gives that error:

[sritchie@wintermute ~/code/clj/sicmutils (sritchie/kondo)]$ clj-kondo --lint src
src/pattern/rule.cljc:570:2: error: ruleset requires bindings in groups of 3. Received 2 bindings.

Sam Ritchie21:02:26

I have it enabled in my exported config like this:

{:linters
 {:sicmutils.pattern/ruleset-args {:level :error}}}

Sam Ritchie21:02:00

I also can’t seem to override it in the :linters key of my project-local config.edn; and if I erase the entry from my exported config, I can’t enable it by adding

:sicmutils.pattern/ruleset-args {:level :error}
to my local config.edn

borkdude22:02:40

Normally this should work. Not sure why it doesn't in this case. If you could make a small repro, then I'll investigate.

borkdude22:02:51

Or, I guess simcutils is already the repro.

borkdude22:02:08

Post an issue with some details then please.

Sam Ritchie22:02:34

@borkdude is a repro in a sicmutils branch okay?

borkdude22:02:57

yeah, as long as I can reproduce it locally. the less deep I have to dig, the better it is of course

Sam Ritchie22:02:04

@borkdude hopefully this is an easy repro; I expect there is nothing sicmutils specific about this, but setting up a repro project is still fiddly. So hopefully this will work. let me know if it’s annoying and I can get a smaller one together

borkdude22:02:46

thanks, I'll look later this week

Sam Ritchie22:02:28

sg, thanks again

Sam Ritchie21:02:11

phew, this hook got a bit turbo. Might be fun reading for anyone interested: https://github.com/sicmutils/sicmutils/blob/961b5bce04a03f1b41e5a39ab427d3a649a710b0/resources/clj-kondo.exports/sicmutils/sicmutils/hooks/pattern/rule.clj pretty cool given that this basically lints a different programming language embedded in clj

🐢 3