This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-11
Channels
- # announcements (3)
- # babashka (62)
- # beginners (58)
- # calva (40)
- # cider (3)
- # clj-kondo (75)
- # cljdoc (14)
- # clojars (8)
- # clojure (110)
- # clojure-australia (6)
- # clojure-europe (38)
- # clojure-hungary (1)
- # clojure-india (4)
- # clojure-italy (1)
- # clojure-nl (3)
- # clojure-spec (4)
- # clojure-uk (3)
- # clojurescript (45)
- # conjure (4)
- # cursive (35)
- # data-science (1)
- # datomic (11)
- # events (2)
- # exercism (4)
- # figwheel-main (4)
- # fulcro (103)
- # graphql (16)
- # helix (1)
- # holy-lambda (16)
- # honeysql (1)
- # introduce-yourself (3)
- # jobs (1)
- # keyboards (2)
- # lsp (4)
- # malli (11)
- # membrane-term (3)
- # mount (2)
- # nextjournal (2)
- # off-topic (53)
- # pathom (30)
- # pedestal (2)
- # portal (22)
- # rdf (1)
- # re-frame (7)
- # reagent (3)
- # reitit (5)
- # remote-jobs (6)
- # shadow-cljs (20)
- # sql (8)
- # tools-build (10)
- # vim (4)
- # xtdb (12)
hi everybody! is there a way to write custom per-project linters with clj-kondo? Would be a good way to try out new linters and to enforce specific styles
any pointers how to go about writing new linters in the clj-kondo codebase would be helpful too
@joost-diepenmaat yes, this is possible using hooks (or specific config for your project-specific functions). https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md
@joost-diepenmaat You can see several examples of this of libraries that export their custom hooks: https://github.com/clj-kondo/clj-kondo/issues/1383
thanks @borkdude. do hooks allow me to add additional linters to def*
forms? I would like to do additional checks on docstrings, similar to emacs’ checkdoc
function for elisp.
so I won’t be dealing with new macro’s, but actually adding checks to existing ones
yes, just write the hook for the core macro and then don't return a new node, just emit warnings using reg-finding!
I’ll give it a shot. thanks!
Can I ignore a specific expression on "Redundant expression"? My usecase is I'm using https://github.com/hyperfiddle/rcf and random :=
have meaning on the tests
expression.
@mynomoto You can ignore any warning by prepending the form with #_:clj-kondo/ignore
Yeah, the problem is that this would make the minimal syntax not so minimal or I would have no linting on the whole form. I think I will disable this linter on the namespace configuration.
I like my syntax really regular but after spending some time with this library I got to like this choice of syntax. And it wins hands down against comment
blocks that what this is replacing in the codebase.
Inside tests
would not report an error, inside a deftest
it would not be elided on prod.
If someone does another version of this lib using a more regular syntax I would go for it. 😉
I'm trying to write a hook for tech.v3.datatype.export-symbols
I've got a function that is being called by the hook and it is getting the right data (I think). I think I'm struggling to make the appropriate tokens for clj-kondo to understand.
(more in thread)
my hook looks like this:
(ns hooks.export-symbols
(:require [clj-kondo.hooks-api :as api]))
;; export-symbols takes a name space and then a bunch of funcitons in
;; that namespace to export
(defn export-symbols [{:keys [node]}]
(let [[es ns & fns] (:children node)]
(when-not (and es ns (seq fns))
(throw (ex-info "Missing namespace or functions." {})))
(into []
(map
(fn [f]
(prn "List Node: "
(api/list-node
(list* (api/token-node 'def)
f
(concat ns "/" f))))))
fns)
{:node
(into []
(map
(fn [f]
(api/list-node
(list* (api/token-node 'def)
f
(concat ns "/" f)))))
fns)}))
the code I'm checking looks like this:
(ns tech.v3.datatype.foo
(:require [tech.v3.datatype.datetime.base :as datetime-base]
[tech.v3.datatype.export-symbols :refer [export-symbols]]))
(export-symbols tech.v3.datatype.datetime.base
system-zone-id)
the macro-expand is doing this:
(do
(require 'tech.v3.datatype.datetime.base)
(let*
[varval__5802__auto__
(requiring-resolve
(symbol "tech.v3.datatype.datetime.base" "system-zone-id"))
var-meta__5803__auto__
(meta varval__5802__auto__)]
(if varval__5802__auto__
nil
(do
(throw
(ex-info
(format
"Failed to find symbol '%s' in namespace '%s'"
"system-zone-id"
"tech.v3.datatype.datetime.base")
{:symbol 'system-zone-id,
:src-ns 'tech.v3.datatype.datetime.base}))))
(if (:macro var-meta__5803__auto__)
(do
(throw
(ex-info
(format
"Cannot export macros as this breaks aot: %s"
'system-zone-id)
{:symbol 'system-zone-id}))))
(def system-zone-id (deref varval__5802__auto__))
(alter-meta!
#'system-zone-id
merge
(select-keys
var-meta__5803__auto__
[:file :line :column :doc :column :tag :arglists]))))
@U0525KG62 you can try the :macroexpand
hook as well, then you can re-use parts of the original macro
which is basically expanding
(export-symbols tech.v3.datatype.datetime.base
system-zone-id)
to
(def system-zone-id tech.v3.datatype.datetime.base/system-zone-id)
:macroexpand
looks good. I was hoping I'd be able to get something that pointed at the right lines in the source file
I've got a config.edn with the following:
{:hooks {:macroexpand {tech.v3.datatype.export-symbols/export-symbols
hooks.export-symbols/export-symbols}}}
and I just copy-pasta'd the export-symbols
macro from tech.v3.datatype.export-symbols
and things are good now
IIUC, putting this config in the .clj-kondo of the project where the macro is defined will mean that it works for all projects that use that macro (so I only need to define it once)
@U0525KG62 I'm back
> IIUC, putting this config in the .clj-kondo of the project where the macro is defined will mean that it works for all projects that use that macro
Nope this isn't true. It works only for the current project. If you want to share it with other projects, put it in clj-kondo.exports
The recommendation is to put it in resources/clj-kondo.exports/cnuernber/dtype-next/config.edn
I'm guessing read this: https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#exporting-and-importing-configuration
and also namespace the hooks code:
resources/clj-kondo.exports/cnuernber/dtype-next/tech/v3/datatype/export_symbols.clj
almost automagically. after linting dependencies, there will be a .clj-kondo/cnuerber/dtype-next
directory with your exported code/config
and you have to add this as :config-paths ["cnuerber/dtype-next"]
in your config.edn
the reason it's not automatically added is to prevent opting into config that you don't want or contains invalid code
but you can add this to your home dir as well. but projects have specific versions of deps and configuration can change over versions
You can see a list of other library exported config here: https://github.com/clj-kondo/clj-kondo/issues/1383
I was considering doing a workshop on clj-kondo hooks at re:clojure but I'm a bit late to the party I think
I am, but I ran out of brain and time tonight. I'll read up tomorrow and over the weekend and and do a write up so people in scicloj can use it.