This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-25
Channels
- # babashka (65)
- # beginners (34)
- # biff (18)
- # calva (8)
- # clara (22)
- # clj-kondo (32)
- # clojure (24)
- # clojure-bay-area (4)
- # clojure-europe (135)
- # clojure-nl (3)
- # clojure-norway (9)
- # clojure-uk (1)
- # clojurescript (11)
- # clojutre (1)
- # core-async (8)
- # cursive (3)
- # datomic (31)
- # emacs (5)
- # fulcro (6)
- # graalvm (5)
- # graphql (3)
- # honeysql (1)
- # introduce-yourself (9)
- # kaocha (1)
- # lsp (65)
- # meander (5)
- # nbb (7)
- # nrepl (2)
- # off-topic (44)
- # rum (3)
- # shadow-cljs (23)
- # specter (1)
- # tools-deps (6)
- # vim (3)
- # xtdb (30)
Is there a recommended way to share .cljfmt.edn
between Calva and clojure-lsp?
Specifically, I'm asking about :indents
that use regular expressions, like :indents {#"^for-" [[:inner 0]]}
. That format works for Calva because it uses tools.reader/read-string, which sees #"..."
as a regular expression. But clojure-lsp reads with clojure.edn/read-string, which doesn't understand regular expressions. To get around this, clojure-lsp expects you to use a reader function: :indents {#re "^for-" [[:inner 0]]}
. Unfortunately, tools.reader/read-string complains about that. So, depending on which format I choose, my .cljfmt.edn file works in Calva or with clojure-lsp, but not both.
To partially answer my own question, it appears that cljfmt is https://github.com/weavejester/cljfmt/pull/274 being able to read .cljfmt.edn
itself. I've https://github.com/weavejester/cljfmt/pull/274#issuecomment-1289896356 that it also try .cljfmt.clj
. If that change is incorporated, it looks like it will support the #"..."
style in the .clj
file. I've also requested that it support #re "..."
in the .edn
file. @U0ETXRFEW and @UKFSJSM38 I think it'd be nice if both Calva and clojure-lsp use cljfmt's own tools for reading those files, whenever they're ready. Do you think we could move in that direction? The one blocker will be that Calva currently parses .edn
files as if they were .clj
files—that is, it uses tools.reader/read-string. That means it currently happily consumes #"..."
in an .edn
file, though with the new toolset, it would start throwing errors. Perhaps when the cljfmt PR is finished, we can think about a migration path?
Interesting. I actually didn't know that regular expressions were not part of EDN. That explains a lot! 😃
The recommended way to share cljfmt configs between Calva and clojure-lsp is to tell Calva to use clojure-lsp for reading the config https://calva.io/formatting/#configuration. But testing it now, I see that it still croaks on the `#re" reader tag.
That'd be great @U07M2C8TT, both using the same upstream function
Clojure-lsp in my VSCode with Calva is very much in love with my memory.. Any way to feed it something else? 🙂
We could make a private chat with @UKFSJSM38 @U07M2C8TT and @U0BUV7XSA
sure, it wasnt always like this. i feel its since a cpl of weeks. i'm in the middle of upgrading dependencies and moving to java 11 from java 8
I've seen a memory leak with clj-kondo once, which I could repro by linting the same file in a loop 100000x times but this could be anywhere of course.
the memory leak was introduced by memoize
which holds on to objects in memory forever. could be similar problem in lsp, but remains to be seen of course
could also be because of the lsp4clj change, but now I'm just guessing. It's best to share your setup / config etc with the people I just mentioned.
@U02CX2V8PJN yes, do it
A valid info: clojure-lsp usually to take more memory/cpu during startup, especially without cache (.lsp/.cache), but then it should not increase during the time, since it uses really low cpu and memory after that
Is there a way to not run specific linters on some buffer types? I use NVIM with Conjure and when it prints the loaded namespaces into its log buffer it always highlights the namespaces as unused like this:
Or maybe not run linter on a buffer type completely? But I would like the customization better.
If we'd want to omit the buffer from linting then this question may be better suited for #vim
@UKFSJSM38 It seems the docs weren't updated for that :filename-pattern
maybe
{:ns-groups [{:filename-pattern ".*integration.*" :name integration}]
:config-in-ns {integration {:linters {:unused-private-var {:level :off}}}
This is not a proper namespace, it doesn't have a declaration. I'll try the filename pattern.
I use ALE for linting with kondo in vim, and have this in my vimrc:
let g:ale_pattern_options = {'conjure-log.*.cljc': {'ale_enabled': 0}}
I tried this file:
{:ns-groups [{:filename-pattern "conjure-log-.*\.cljc" :name conjure-log}]
:config-in-ns {conjure-log {:linters {:unresolved-symbol {:level :off}}}
I added it to my .clj-kondo/config.edn
in the project directory and into ~/.config/clojure-lsp/config.edn
.
I think it didn't work. Did I do something wrong?
I also tried .*
for the regex> clj-kondo --version
clj-kondo v2022.10.14
can you give the full path? after you mentioned the lsp config I have doubts if you intended to add the config to kondo's home config, which is not ~/.clj-kondo
but ~/.config/clj-kondo
I used this to find clojure-lsp
config:
https://github.com/clojure-lsp/clojure-lsp/blob/01500c34e00efa2b4affc627bdc80e89af18f55d/lib/src/clojure_lsp/config.clj#L32
It points into ~/.config/clojure-lsp/config.edn
so I created that file and added the config map there.
Also my XDG_CONFIG_HOME
variable is not set.
And for clj-kondo
I used the project itself. I'll try the ~/.config/clj-kondo
.
I tried ~/.config/clj-kondo/config.edn
(notice the tilda at the front) and it also doesn't silence the linter.
Maybe my rules are bad, I don't know anymore.
If I add a file in ~/.config/clj-kondo/config.edn
then with this config I can silence the linter globally:
{:linters {:unresolved-symbol {:level :off}
:unresolved-namespace {:level :off}}}
But this config doesn't pick up the file conjure-log-1151426.cljc
(it has random integer in the name):
{:ns-groups [{:filename-pattern ".*conjure.*" :name conjure-log}]
:config-in-ns {conjure-log {:linters {:unresolved-symbol {:level :off}
:unresolved-namespace {:level :off}
}}}}
Is there something that I'm doing wrong?
What I expect is to silence these linters in that specific file pattern.It's best to debug this from the command line and perhaps with a local checkout of clj-kondo with some debugging statements inserted
First thing I found is that I can't put \.
into the regex pattern. But it's not enough.
I have this input file (don't mind the error texts here, it's system-out buffer):
; Sponsored by @___________ ❤
; --------------------------------------------------------------------------------
; localhost:34189 (connected): .nrepl-port
; --------------------------------------------------------------------------------
; Assumed session: Bullmastiff (Clojure)
; --------------------------------------------------------------------------------
; eval (buf): /home/martin/_____________________________________________.clj
nil
; (err) Syntax error compiling at (src/_______________.clj:25:1).
; (err) Unable to resolve symbol: a in this context
#'my.ns/hi
nil
#'my.ns/api-config
#'my.ns/start
nil
#'my.ns/-main
hi
Then I have this config:
{:ns-groups [{:filename-pattern "clj_file" :name conjure-log}]
:config-in-ns {conjure-log {:linters {:unresolved-symbol {:level :off}
:unresolved-namespace {:level :off}}}}}
Command:
cat clj_file | clj-kondo --filename clj_file --lint -
This is the output:
cat clj_file | clj-kondo --filename clj_file --lint -
clj_file:11:3: warning: Unresolved namespace my.ns. Are you missing a require?
clj_file:18:1: error: Unresolved symbol: hi
linting took 11ms, errors: 1, warnings: 1
Version: clj-kondo v2022.11.02
Is it correct?How can I evaluate it from command line without compiling?
I have this in my ~/.clojure/deps.edn
:
:clj-kondo/dev {:paths []
:deps {clj-kondo/clj-kondo {:local/root "/Users/borkdude/dev/clj-kondo"}}
:main-opts ["-m" "clj-kondo.main"]}
I tried to run it using lein repl
but it hangs the REPL if I try to run the main
function 😕 (not the -main
which does system exit)
> I have this in my ~/.clojure/deps.edn
:
Is it in the top-level?
I tried this expression that I found in the bottom and I deleted one --lint
clause to point to only my file:
;;;; Scratch
(comment
(into #{}
(comp
(map :filename)
(distinct))
(:findings (read-string (with-out-str
(main "--lint" "/home/martin/ttttttttttttttttttttttttt/clj_file"
"--config" "{:output {:format :edn}}"
"--config" "{:linters {:invalid-arity {:level :warning}}}"))))))
I used lein repl
to connect to REPL and I have nREPL middleware tooI added a print statement in config.clj
, in function
(println {:str-filename (string? filename-pattern)
:sym-name (symbol? name)
:pattern-matches (and filename-pattern
(re-matches (re-pattern filename-pattern) filename))
:filename-pattern filename-pattern
:filename filename
:matches (or (and (string? pattern) (symbol? name)
(re-matches (re-pattern pattern) (str ns-name)))
(and (string? filename-pattern) (symbol? name)
(re-matches (re-pattern filename-pattern) filename)))})
Outputs (first when file matches, second when it doesn't match):
$ cat clj_file | clojure -M:clj-kondo/dev --filename heeey --lint -
{:str-filename true, :sym-name true, :pattern-matches heeey, :filename-pattern heeey, :filename heeey, :matches heeey}
heeey:11:3: warning: Unresolved namespace my.ns. Are you missing a require?
heeey:18:1: error: Unresolved symbol: hi
linting took 70ms, errors: 1, warnings: 1
$ cat clj_file | clojure -M:clj-kondo/dev --filename heeeyAAAAA --lint -
{:str-filename true, :sym-name true, :pattern-matches nil, :filename-pattern heeey, :filename heeeyAAAAA, :matches nil}
{:str-filename false, :sym-name true, :pattern-matches nil, :filename-pattern nil, :filename heeeyAAAAA, :matches false}
heeeyAAAAA:11:3: warning: Unresolved namespace my.ns. Are you missing a require?
heeeyAAAAA:18:1: error: Unresolved symbol: hi
linting took 67ms, errors: 1, warnings: 1
It matched the linter's config but the output didn't change 🤷
Config:
{:ns-groups [{:filename-pattern "heeey" :name conjure-log}]
:config-in-ns {conjure-log {:linters {:unresolved-symbol {:level :off}
:unresolved-namespace {:level :off}}}}}
OK, I think the relevant bit might be in linters.clj
where the unresolved symbols are processed. It might not take the ns-group into account
If I add a file in ~/.config/clj-kondo/config.edn
then with this config I can silence the linter globally:
{:linters {:unresolved-symbol {:level :off}
:unresolved-namespace {:level :off}}}
But this config doesn't pick up the file conjure-log-1151426.cljc
(it has random integer in the name):
{:ns-groups [{:filename-pattern ".*conjure.*" :name conjure-log}]
:config-in-ns {conjure-log {:linters {:unresolved-symbol {:level :off}
:unresolved-namespace {:level :off}
}}}}
Is there something that I'm doing wrong?
What I expect is to silence these linters in that specific file pattern.