This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-02-29
Channels
- # announcements (6)
- # babashka (7)
- # beginners (24)
- # calva (2)
- # cider (21)
- # clj-kondo (49)
- # cljdoc (29)
- # clojure (56)
- # clojure-dev (2)
- # clojure-europe (15)
- # clojure-nl (6)
- # clojure-norway (27)
- # clojure-uk (3)
- # clojuredesign-podcast (6)
- # clojurescript (1)
- # conjure (1)
- # core-async (8)
- # cryogen (2)
- # cursive (6)
- # data-science (1)
- # datomic (12)
- # events (1)
- # fulcro (16)
- # graalvm (28)
- # hyperfiddle (2)
- # lambdaisland (4)
- # leiningen (20)
- # observability (1)
- # off-topic (24)
- # pathom (5)
- # pedestal (10)
- # portal (7)
- # practicalli (1)
- # reitit (5)
- # rewrite-clj (20)
- # shadow-cljs (18)
- # vim (8)
- # xtdb (9)
Could it be possible to add "current namespace" info to the context of hooks? i'd like to know if a given symbol's namespace is an alias or not
Oh interesting, let me see if that does what I need
coming back to this, api/resolve
will resolve the namespace, but it won't resolve the symbol.
given:
(ns example.foo
(:require [example.bar :as e.bar]))
(defn create-service
[this]
(with-meta this {`e.bar/real-function identity}))
if I write e.baa/real-function
, api/resolve
will return {:ns nil :name real-function}
. however, if i write e.bar/fake-function
, it will return {:ns example.bar :name fake-function}
.i realize this is outside of my original request
you can check api/ns-analysis
if the var exists or not, but if the analysis is there, depends on if the namespace has already been linted before
a little awkward but works great
thanks so much
Would you be interested in supporting making (load "some_file")
/ in-ns
work for analysis? i'm thinking about how there's no way to "go to definition" in clojure-lsp on certain core functions (`defrecord` is my current example) because clj-kondo doesn't provide analysis about it or at least it doesn't "merge" them together
well, i'm not going to write a PR if you wouldn't merge it lol
i'd prefer to check if you're like "no, not interested at all" vs "maybe if it's workable", you know?
I'm not sure if this pattern is common enough (and applicable across dialects) to make huge changes. Perhaps we can just make bespoke support for some of the namespaces in clojure that use this pattern, but I'm open to having it generally supported. Not sure how easy that is though
yeah, with parallel analysis, i don't think it's possible, so i'm not sure how it would work in that case.
parallel analysis doesn't lint stuff in parallel from the same jar file or directory
oh really? so passing --parallel
when linting my src
folder doesn't do anything?
okay, then maybe this is possible.
there's also this slightly related issue https://github.com/clj-kondo/clj-kondo/issues/2284

i missed that!
this is probably not an issue that can be tackled in a few hours though, but willing to think about it for the long term
topological sorting dependencies in the face of load-file is very chicken and the egg
To properly handle it, you’d have to sort of duplicate the evaluation logic of clojure, right? Take in a file, process each form one at a time, load files when encountering load/require/use etc
sure, meaning you would need to do analysis to determine dependencies (it is already the case you need to at least analyze the ns form) and you need dependencies in order to do some kind of topo sort, and you need some kind of topo sort to determine what is safe to analyze in parallel
Right
I implemented this in splint, it didn’t increase serial linting time noticeably (~100ms per 100 files), but it did remove the ability to lint files in parallel (which i do across all files (not just per directory like in clj-kondo))
have you seen the build system's a la carte paper? (https://www.microsoft.com/en-us/research/uploads/prod/2018/03/build-systems.pdf) it is very haskell, but it might give you some interesting ideas for structuring analysis where dependencies might be dynamically discoverable, and if I recall one of the concerns presented is wanting to parallelize builds
I’ve not, I’ll give that a read.
The code complexity increase was mild to moderate: instead of just linting each form recursively, i had to first check if a given form was one that loaded other files, and then actually update the ctx with the files to lint and files that have been linted. The code that processed loading was pretty easy tho it required a bit of work to fake a classpath awareness
I haven’t merged the code because it’s currently only a speed decrease for no gain (i don’t do any var/locals tracking), but it was good to see that it’s both possible and fairly easy
I could try doing this in clj-kondo if @U04V15CAJ is interested
yeah. I think identifying groups of dependencies that still can be linted in parallel might also be nice
this won't mean much without knowing splint's internals, but here's the PR i did showing "loading in dependency order": https://github.com/NoahTheDuke/splint/pull/9
I searched the issues and didn't see any requests, so checking before I open one: would you be interested in supporting linting a project (from a project file) instead of by directory/file?
Hello 👋. A project I'm working in has a custom macro defined for defining graphql resolvers, called defresolver
. The pattern used in this project with this macro is to name the symbols for field resolvers field/<field-name>
. For these symbols, clj-kondo reports syntax warnings like Function name must be simple symbol but got: field/account-name
. Is there a way to tell clj-kondo to stop reporting these warnings across the project without squelching all syntax warnings across the project?
try:
{:config-in-call {foobar/defresolver {:linters {:syntax {:level :off}}}}}
or soThanks. Will that disable syntax warnings for the whole defresolver
form? There's no way to be more fine-grained about what to disable, right?
Or rather, there's no way to tell clj-kondo "A /
in a symbol is ok in this foobar/defresolver
"? I assume not, but just checking.
you could however write a hook for it and transform the expression to something else
here's a hook i wrote which does this:
(ns hooks.noahtheduke.splint.rules
(:require
[clj-kondo.hooks-api :as api]))
(defn defrule
[{:keys [node]}]
(let [[defrule rule-name & body] (:children node)
new-node (api/list-node
(list* (with-meta (api/token-node 'def) (meta defrule))
(with-meta (api/token-node (symbol (name (api/sexpr rule-name))))
(meta rule-name))
body))]
{:node (with-meta new-node (meta node))}))
given (defrule style/eq-nil ...)
, it'll be treated as (def eq-nil ...)
this works for me because i have each defrule
in separate files. if you need them to be in the same file, you could transform in some other way