This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-22
Channels
- # announcements (9)
- # beginners (96)
- # calva (14)
- # cider (49)
- # clj-kondo (29)
- # cljsrn (5)
- # clojure (55)
- # clojure-dev (37)
- # clojure-europe (4)
- # clojure-italy (4)
- # clojure-nl (5)
- # clojure-spec (5)
- # clojure-switzerland (3)
- # clojure-uk (5)
- # clojurescript (172)
- # cursive (14)
- # datomic (3)
- # duct (1)
- # emacs (6)
- # fulcro (17)
- # jobs (1)
- # leiningen (6)
- # nrepl (11)
- # off-topic (26)
- # pedestal (2)
- # re-frame (20)
- # reagent (9)
- # remote-jobs (3)
- # shadow-cljs (67)
- # spacemacs (24)
- # specter (6)
- # test-check (3)
- # tools-deps (18)
I have a macro that introduces arbitrary new symbols within its scope. Is there a way to tell clj kondo to ignore any unused/bound symbols within its sexp?
specifically I’d like to support the matcha query macros here for construct, ask, select etc… https://github.com/Swirrl/matcha#construct
ahh is it :skip-args
I need?
hmmm looks like :skip-args
works but it then causes lint failures on vars that are used inside the macro (but outside its sexp) e.g.
(let [x 10 ;; x raises lint warning here
]
(matcha/construct ?s [[?s ?p x]])
Inspite the fact that it is used inside matcha/construct:skip-args
means the macros special ?s
?p
symbols aren’t flagged — but it then seems to cause the usage of x not to be detected.
I have the same issue with the meander
lib which uses such special symbols all over the place - would it make sense to have a global user-customizable regex for symbols which clj-kondo will ignore?
yeah that’s not good enough, there is no one special symbol… you can put unbound ?symbols
with names of your choosing anywhere in the macro definition.
the macro’s implement a query engine for matching patterns in graph data
is it fair to say clj-kondo assumes that all macros behave syntactically like other common macros?
@rickmoynihan can you give an example. I'm pretty sure you can ignore those symbols using a config.
sure…
(matcha/construct {:grafter.rdf/uri ?ds
?p ?o}
[[catalog-uri dcat:dataset ?ds]
[?ds ?p ?o]])
Is from actual code… catalog-uri
is bound outside the macro form in lexical scope, whilst all ?
symbols are arbitraryor another (real usage):
(matcha/construct {:grafter.rdf/uri ?nav-item ?nip ?nio}
[[nav-uri pmdui:hasNavItem ?nav-item]
[?nav-item ?nip ?nio]
(optional [[nav-uri pmdui:hasDisplayContext ?disp]])]
matcha-db)
here nav-uri
and pmdui:hasDisplayContext
and matcha-db
come from lexical or ns level scope… all other symbols represent unbound query variables. The optional
is nested macro syntax.(for which there is actually a defmacro definition, that just raises an error if it’s used outside of a query macro — but it provides a way to put a docstring on the optional
)
borkdude@MBA2015 ~/Dropbox/dev/clojure/jet (master) $ cat /tmp/foo.clj
(ns foo
(:require [matcha :as matcha]))
(matcha/construct {:grafter.rdf/uri ?ds
?p ?o}
[[catalog-uri dcat:dataset ?ds]
[?ds ?p ?o]])
borkdude@MBA2015 ~/Dropbox/dev/clojure/jet (master) $ clj-kondo --lint /tmp/foo.clj
/tmp/foo.clj:4:37: info: unresolved symbol ?ds
/tmp/foo.clj:5:20: info: unresolved symbol ?p
/tmp/foo.clj:5:23: info: unresolved symbol ?o
/tmp/foo.clj:6:21: info: unresolved symbol catalog-uri
/tmp/foo.clj:6:33: info: unresolved symbol dcat:dataset
linting took 17ms, errors: 0, warnings: 0
borkdude@MBA2015 ~/Dropbox/dev/clojure/jet (master) $ clj-kondo --lint /tmp/foo.clj --config '{:linters {:unresolved-symbol {:exclude [(matcha/construct)]}}}'
linting took 12ms, errors: 0, warnings: 0
borkdude@MBA2015 ~/Dropbox/dev/clojure/jet (master) $
ahh I misunderstood what that was doing thanks, I will give it a try… but first lunch! 🙂
Many thanks borkdude that seems to work great!
Hi @borkdude! Thanks for the new release, you’ve really created something awesome here! BTW, noticed README is still advising use of —cache in one spot: > So for lein the entire command would be: > $ clj-kondo --lint "$(lein classpath)" --cache
totally forgot to mention you in the latest release, you helped me a bunch testing the import-vars stuff: https://github.com/borkdude/clj-kondo/releases/tag/v2019.08.21-alpha