Fork me on GitHub
#clj-kondo
<
2021-12-22
>
ingesol09:12:39

Hi! Would it make sense with a linter for orgs that want to wrap all fns in a threading form with parentheses? So this:

(-> x
    fn-a
    (fn-b arg1 arg2))
should be corrected to this:
(-> x
    (fn-a)
    (fn-b arg1 arg2))

borkdude09:12:29

Can you explain why?

ingesol09:12:06

My org simply prefers a consistency there, aesthetically I guess.

ingesol09:12:21

We all have our special ways 🙂

borkdude09:12:23

You can write a hook for it I think

ingesol09:12:07

I thought hooks were for parsing, will have a look

borkdude09:12:30

@U21QNFC5C you can use them for linting too. I got it working here: .clj-kondo/thread_hook.clj

(ns thread-hook
  (:require [clj-kondo.hooks-api :as api]))

(defn thread-hook [{:keys [node]}]
  (let [children (rest (:children node))]
    (run! (fn [node]
            (when-not (api/list-node? node)
              (api/reg-finding! (assoc (meta node)
                                       :message (str "Wrap in a list: " node)
                                       :type :org.acme/thread-list)))) children)))

borkdude09:12:38

.clj-kondo/config.edn

{:hooks {:analyze-call {clojure.core/-> thread-hook/thread-hook}}
 :linters {:org.acme/thread-list {:level :warning}}}

borkdude09:12:48

$ cat example.clj
(-> 1 2 3)

borkdude09:12:57

$ clj-kondo --lint example.clj
example.clj:1:5: warning: Wrap in a list: 1
example.clj:1:7: warning: Wrap in a list: 2
example.clj:1:7: error: a number is not a function
example.clj:1:9: warning: Wrap in a list: 3
example.clj:1:9: error: a number is not a function
linting took 74ms, errors: 2, warnings: 3

ingesol10:12:33

you are too fast, I did not have time to have a look 🙂

ingesol10:12:50

thanks for this, will try it out

alekszelark14:12:20

I wonder why it complains about parse-long? clojure-lsp version used: 2021.12.20-00.36.56 clj-kondo version used: 2021.12.19

borkdude14:12:01

@zelark parse-long is a new var in clojure 1.11 and clj-kondo has already been updated for that

borkdude14:12:22

however if you lint your deps, then it should pick up on your project's clojure version I think

alekszelark14:12:46

Hm, I linted via cli and it doesn’t complain about parse-long , maybe it’s a Calva specific issue, or I don’t know

alekszelark14:12:32

> if you lint your deps what does it mean? I have

{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.11.0-alpha3"}
...

alekszelark14:12:06

just figured out that I have clj-kondo extension installed in my vs code, after I deleted it, things look nice again, thanks

practicalli-johnny14:12:46

Is {:paths ["."]} a legitimate configuration for .clj-kondo/config.edn ? Background: I am using https://github.com/github/super-linter for markdown and it should do Clojure as well, but suspect its not finding the deps.edn file in the root of the project (practicalli/clojure-deps-edn). I think I just need to put in the config what I would otherwise specify on the command line with the --lint flag. Does that make sense?

borkdude15:12:13

@jr0cket clj-kondo config.edn doesn't know anything about :paths

practicalli-johnny15:12:35

Hmm, I'll take a look at the Super Linter PRs that added clj-kondo and see if I can work out why its not picking up the deps.edn file. I have a separate GitHub action that specificially checks the deps.edn file, using the lint deps.edn` command line arg, so not a big issue. Nice to have just one GitHub action though 🙂

borkdude15:12:24

clj-kondo doesn't pick up on deps.edn automatically

borkdude15:12:16

clj-kondo --lint $(clojure -Spath) --dependencies + clj-kondo --lint src:test is usually how you should lint your projects

practicalli-johnny15:12:10

In DeLaGuardo/setup-clj-kondo github action I use the following, which seems to work. This isnt for a Clojure project, its for a user level config project, so it only has a deps.edn file plus some markdown for docs, nothing else Clojure wise.

jobs:
  lint:
    runs-on: ubuntu-20.04
    steps:
      - uses: DeLaGuardo/setup-clj-kondo@master
        with:
          version: '2021.12.16'
      - uses: actions/checkout@v2
      - name: Run on Ubuntu
        run: clj-kondo --lint deps.edn

borkdude15:12:53

right, yes, you are linting the deps.edn file itself, that should work

practicalli-johnny15:12:30

I'll see if I can get Super Linter to do the same. But if not, its still covered. Thanks.

practicalli-johnny15:12:08

Super Linter is calling clj-kondo with the following command, so not sure what path would be used by default.

clj-kondo --config ${CLOJURE_LINTER_RULES} --lint
Would it be better to specify "." as the argument to --lint (assuming neither clojure or lein commands are available in the GitHub action image). Or do specific directories need to be added for src and test, etc.?

borkdude15:12:18

I have no idea how Super Linter works. I don't think specifying . is always a good default.

borkdude15:12:59

I'd say just use clj-kondo directly

borkdude15:12:08

unless you can find good examples of how other people use it. http://grep.app is a tool you can maybe use for this

practicalli-johnny15:12:39

Super Linter just runs the command above (and uses the latest clj-kondo it seems) I wonder if I do a PR to add a CLOJURE_LINTER_PATHS variable to the super linter then the paths can be specified in the github action yaml file that defined the jobs (maybe).

borkdude15:12:56

running --lint without any arguments doesn't do anything, so I would be surprised if that was all there is to it. Are you supposed to provide arguments to it yourself?

practicalli-johnny15:12:25

As --lint without arguments doesnt do anything, that would explain my results. Thanks. I'll try figure out how to add some paths to the command. 🙂

practicalli-johnny16:12:52

There are some options to set paths, but they arent being passed to the Clojure linter. It seems https://megalinter.github.io/latest/descriptors/clojure_clj_kondo/what I think super-linter should do for clj-kondo, so I'll switch to that. Thanks.

borkdude16:12:18

Oh I didn't even realize those were different things

practicalli-johnny16:12:53

Looking at the config options, they are very different: I'd consider super-linter broken for now until there is an env var to set the lint path (a PR adding the setup of mega-linter to super linter seems to be required - but then why not just use mega-linter 🙂 )