Fork me on GitHub
#calva
<
2021-11-11
>
Felipe Cortez17:11:13

hey! we're using cljfmt through tools.deps, which means we use an indentation.edn file containing what would be inside :indents here: https://github.com/weavejester/cljfmt#configuration is there any way to make calva read this instead of the entire :cljfmt map?

ericdallo22:11:31

clojure-lsp has a standard of readding a .cljfmt.edn (https://clojure-lsp.io/settings/#all-settings), Since Calva uses clojure-lsp, it could do the same. c/c @U0ETXRFEW

Felipe Cortez23:11:56

hmm, isn't that for the lein-cljfmt style map instead of just the :indents?

ericdallo23:11:53

Hum, not sure I understood, for clojure-lsp you could configure any cljfmt config on that file, including :indents

Felipe Cortez23:11:14

yeah, but the tools.deps version uses command line arguments, like

clojure -Sdeps '{:deps {cljfmt {:mvn/version "0.8.0"}}}' \
  -m cljfmt.main check \
  --indents indentation.clj
where indentation.clj contains just the contents that would be inside :indents. I'll probably just use the .cljfmt.edn format and add a babashka task to convert the map to command line args

ericdallo00:11:22

BTW, any reason why not use clojure-lsp format instead of manually using cljfmt? (https://clojure-lsp.io/api/)

Felipe Cortez00:11:56

oh, this is much better

ericdallo00:11:05

We replaced at nubank every linter to use only clojure-lsp :)

ericdallo00:11:35

for linting (clj-kondo under the hood), formatting (cljfmt under the hood) and clean-ns (clojure-lsp itself)

ericdallo00:11:06

with that you could have a common library like codestyle and all services/libs of yours could use the same codestyle configuration

Felipe Cortez00:11:42

we run multiple jobs like

kondo-check:
  image: "cljkondo/clj-kondo"
  script:
    - clj-kondo --lint src $([ -d test ] && echo "test")

fmt-check:
  image: clojure:openjdk-11-tools-deps-buster
  script:
    - clojure -Sdeps '{:deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}}' -M -m cljfmt.main --indents indentation.edn check
but that does seem better 😄

ericdallo00:11:42

the issue when you run clj-kondo to lint only src and test is that it makes kondo doesn't know the whole classpath and know hooks and custom things for other macros, this issue is fixed with clojure-lsp since it scans the classpath with kondo already

Felipe Cortez00:11:42

wow, clj-kondo can look for dependencies' configs?

ericdallo00:11:41

we just have this on our common codestyle library at nubank:

{:config-paths ["nubank/stateflow" ...]}

ericdallo00:11:06

then clojure-lsp will already tell to kondo copy the hook and use it, understand this library macros that were configured on the library itself!

Felipe Cortez00:11:49

but never managed to commit it, I think

😅 1
Felipe Cortez00:11:15

this is awesome

ericdallo00:11:52

yeah, I can say after we introduced codestyle common library using all those configurations in one single place, we stopped having issues like missing lint config

ericdallo00:11:29

all services now just use this on .clj-kondo/config.edn:

{:config-paths ["nubank/codestyle"]}
which that lib has more kondo config-paths and custom kondo config for all services and libs :)

ericdallo00:11:38

LMK if you need more details

Felipe Cortez00:11:34

and nubank/codestyle is a lib? config-paths looks for stuff in the classpath?

ericdallo00:11:57

yes, is just a common lib that in resources has all clj-kondo exports + clojure-lsp exports

ericdallo00:11:00

yes, in classpath

ericdallo00:11:17

clojure-lsp has that same feature via :classpath-config-paths settings

ericdallo00:11:57

the kondo one, search not on classpath, it search on folders :config-paths , but it turns out that you can think on classpath since clojure-lsp will send that to be linted and clj-kondo will copy that config for your service folder

ericdallo00:11:17

when I created that on clojure-lsp I just added support for classpath only instead of all folder support like kondo has

Felipe Cortez00:11:09

very very nice

Felipe Cortez00:11:23

I'll definitely let you know when setting this up!

pez07:11:53

I’m not following about all the cool stuff here. Is there a blog write-up somewhere?

pez07:11:17

Calva doesn’t use clojure-lsp for formatting, anyway, so the question in TS still is relevant. And the answer is no, Calva only knows about one cljfmt config file. You could tell it to read indentation.edn, but then Calva wouldn’t know about your other cljfmt options. It should be quite simple to add this support though. An issue on the repo is welcome!

Felipe Cortez12:11:50

actually, it seems like defining all the cljfmt options in the leiningen format as it is today should be the way to go. I can then write a workaround or start using clojure-lsp to do my CI checks instead. what do you think?