Fork me on GitHub
#clj-kondo
<
2020-02-19
>
nate20:02:46

Does anyone have an example of using a namespace local config to turn off a linter? I can't seem to get it to work.

nate20:02:50

Doesn't work:

(ns 
  {:clj-kondo/config {:linters {:unused-namespace {:level :off}}}}
  (:require
    [foo.bar :as bar]))

borkdude20:02:53

@nate The config has to be quoted, even if all the stuff in there is keywords

borkdude20:02:15

This is what clj-kondo expects

nate_clojurians20:02:16

(different Nate 😉 )

borkdude20:02:40

then why does Slack suggest the wrong Nate first... stupid app 😉

sogaiu22:02:01

on a related note, i wonder why when i press tab for completing nicks that i end up on completely different candidates than what was already highlighted...

nate20:02:37

So, like this?

(ns 
  {:clj-kondo/config '{:linters {:unused-namespace {:level :off}}}}
  (:require
    [foo.bar :as bar]))

nate20:02:21

ah, tried that and it didn't work

nate20:02:28

let me try a small repro

nate20:02:17

$ clj-kondo --lint test.clj
test.clj:4:6: warning: namespace foo.bar is required but never used
linting took 6ms, errors: 0, warnings: 1

nate21:02:30

hm, using an older version (v2020.01.10), maybe that's it

borkdude21:02:30

that example does work for me, also in the editor.

borkdude21:02:54

@nate Actually, that exact problem got solved in the last release: https://github.com/borkdude/clj-kondo/issues/430

nate21:02:10

aha! that definitely fixed it

nate21:02:15

many thanks

borkdude21:02:59

maybe a next nice tweak would be to let clj-kondo accept un unquoted config. I'll make an issue for that as well

nate21:02:34

I saw the note about quoting the config in the docs and tried that, but had a user error by not running the latest

borkdude21:02:07

yeah, so if there's anything not supported in the ns metadata it can probably be fixed without much trouble

nate21:02:08

on a related note, is there a way to configure linting by namespace or namespace regex? my use case is that I have a set of namespaces that all start with fiddle. that I use during development, and I would like them to have slightly different kondo config, like skipping the unused namespaces check. for now, I will just add the metadata like the above, but wondering if there was a way to do it more generally

borkdude21:02:44

unless that's supported on a linter basis

nate21:02:45

the issue is that I do use the namespaces in those files, but usually from comment blocks

borkdude21:02:48

not in general

borkdude21:02:11

but clj-kondo does lint comment blocks, unless you've turned that off

borkdude21:02:53

$ clj-kondo --lint - <<< "(ns  (:require [foo.bar :as bar])) (comment (bar/x))"
linting took 11ms, errors: 0, warnings: 0

nate21:02:10

ah, sorry, to be more specific, I usually use #_(...) style instead of (comment ...)

borkdude21:02:34

then use comment 😛

nate21:02:35

doesn't see the code in the #_ ones, unfortunately

nate21:02:05

I would like to, but I make extensive use of my editor's "run top level form" mapping, and comment blocks ruin that

borkdude21:02:58

you can also require those namespaces from the #_(...) blocks instead then

borkdude21:02:04

unless it's CLJS

nate21:02:14

interesting idea