This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-31
Channels
- # announcements (20)
- # asami (14)
- # aws (6)
- # babashka (15)
- # beginners (83)
- # biff (6)
- # calva (93)
- # cider (3)
- # clj-kondo (21)
- # cljdoc (106)
- # cljs-dev (32)
- # clojure (165)
- # clojure-dev (78)
- # clojure-europe (54)
- # clojure-italy (9)
- # clojure-nl (9)
- # clojure-norway (24)
- # clojure-uk (4)
- # clojurescript (6)
- # community-development (2)
- # conjure (2)
- # core-typed (14)
- # datahike (4)
- # datomic (2)
- # emacs (40)
- # events (1)
- # fulcro (11)
- # graalvm-mobile (29)
- # graphql (8)
- # honeysql (19)
- # java (1)
- # jobs (1)
- # lsp (232)
- # malli (5)
- # membrane (112)
- # nextjournal (11)
- # off-topic (63)
- # portal (12)
- # re-frame (6)
- # reagent (3)
- # reitit (4)
- # rewrite-clj (2)
- # shadow-cljs (25)
- # tools-deps (6)
Is it possible to use kondo for side effect linting / analysis? For example require a function should be pure then get a lint error if this assumption is violated, or query a function if it has side effects?
I'm curious; how would/could you detect if a function has side-effects? By manually adding some explicit metadata or something like that to "color" the functions?
Initially, yes. I think if you default to "all interop is impure unless explicitly stated" and propagate this upwards you'll be 95% there
ah, ok. I think this is one of those questions where that last 5% contains all sorts of nasty edge-cases. A silly function like (defn foo [*a] (swap! *a inc)
sure looks quite side-effecting in isolation, but perhaps it's (sometimes) invoked from (defn bar [val] (let [*a (atom val)] (foo *a) @*a))
etc 🙂 or in case of printing your function might be wrapped in with-out-str
@UK0810AQ2 Could work to a certain degree, but what kind of input/output would you expect? Need more specific examples.
I think that "all interop is impure" would be pretty troublesome in a lot of codebases considering you'd have to, for one, manually examine most of clojure core for this since so much of it delegates to clojure.lang.RT, and then a lot of very common data structure libraries like sorted maps etc. would then have to get custom linting as well considering their authors are unlikely to package clj-kondo configs. Not saying it's impossible by any stretch to start from there, but it definitely feels like it would require a lot of community effort.
@U04V15CAJ I think there are linters you can build on top of this analysis. Few ideas: Maximum recommended depth for side effects Maximum number of side effects in function call Assertions - specify a certain function must remain pure, then down the line trip that linter if something violated this assumption
Should there be a warning for something like this?
(defn foo
([x & {:keys [y]
:or {y false}}]
(foo x y))
([x y]
[x y]))
Looks like clj-kondo has no problem with it, but Clojure gives:
Syntax error compiling fn* ...
Can't have fixed arity function with more params than variadic function
yes, clj-kondo should lint this. there might be an issue but if not, feel free to create it
I just muddled through how to configure clj-kondo to ignore an assert expr brought in by https://github.com/nubank/matcher-combinators.
In the end it was an easy :unresolved-symbol {:exclude [(clojure.test/is [match?])]}
in my clj-kondo config.
Might be worth me adding a tip under https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md#unresolved-symbol docs?
{:linters
{:unresolved-symbol
{:exclude [(riemann.streams/streams [where])]}}}
is a similar example?