Fork me on GitHub
#clj-kondo
<
2019-06-13
>
Stefan06:06:35

@borkdude Just tried the (macOS) binary you posted above. I hope you forgive me for not going through all that has already been reported and I’ll just report my finding here:

(ns metrics-server.gitlab-fetcher
  (:require [clj-http.client :as client]
            [clojure.string :as str]
            [clojure.data.json :as json])
  (:import java.time.ZoneId
           java.time.format.DateTimeFormatter
           java.time.temporal.TemporalAdjusters
           java.time.LocalDate
           java.time.DayOfWeek))

(def zone-id (. ZoneId systemDefault))
(def formatter (. DateTimeFormatter ISO_OFFSET_DATE_TIME))
(defn date-to-string [date-time]
  (-> date-time
      (. atStartOfDay)
      (. atZone zone-id)
      (. format formatter)))
(def last-monday
  (-> (. LocalDate now)
      (. with (. TemporalAdjusters previousOrSame DayOfWeek/MONDAY))))
(def before-last-monday
  (-> last-monday
      (. with (. TemporalAdjusters previous DayOfWeek/MONDAY))))
(def before-before-last-monday
  (-> before-last-monday
      (. with (. TemporalAdjusters previous DayOfWeek/MONDAY))))
gives:
src/metrics_server/gitlab_fetcher.clj:11:17: error: unresolved symbol ZoneId
src/metrics_server/gitlab_fetcher.clj:11:24: error: unresolved symbol systemDefault
src/metrics_server/gitlab_fetcher.clj:12:19: error: unresolved symbol DateTimeFormatter
src/metrics_server/gitlab_fetcher.clj:12:37: error: unresolved symbol ISO_OFFSET_DATE_TIME
src/metrics_server/gitlab_fetcher.clj:15:10: error: unresolved symbol atStartOfDay
src/metrics_server/gitlab_fetcher.clj:16:10: error: unresolved symbol atZone
src/metrics_server/gitlab_fetcher.clj:19:10: error: unresolved symbol LocalDate
src/metrics_server/gitlab_fetcher.clj:19:20: error: unresolved symbol now
src/metrics_server/gitlab_fetcher.clj:20:10: error: unresolved symbol with
src/metrics_server/gitlab_fetcher.clj:20:18: error: unresolved symbol TemporalAdjusters
src/metrics_server/gitlab_fetcher.clj:20:36: error: unresolved symbol previousOrSame
src/metrics_server/gitlab_fetcher.clj:23:36: error: unresolved symbol previous

Stefan06:06:07

Also, this code:

(defn extract-relevant-fields [{:keys [key name]
                                [{:keys [value]}] :measures}]
  {:key key
   :name name
   :value value})
gives:
src/metrics_server/complexity.clj:7:11: error: unresolved symbol value
(Feedback on my code style is appreciated btw as I’m learning Clojure 😉)

Stefan06:06:49

Similarly:

(defn extract-relevant-fields [{{:keys [additions deletions]} :stats}]
  {:additions additions
   :deletions deletions})
gives:
src/metrics_server/churn.clj:4:15: error: unresolved symbol additions
src/metrics_server/churn.clj:5:15: error: unresolved symbol deletions

borkdude07:06:34

@stefan.van.den.oord Thanks for that. Some of those have already been solved, but there are some unknown ones, so I’ll go through them and let you know.

tatut09:06:19

In the CLI tool, I’m getting an “Unparsable namespace form” for:

(ns foo
  (:require [clojure.string :as str]
            #?(:cljs [cljs.reader :as reader])))

tatut09:06:42

in a .cljc file

tatut09:06:58

If I remove the reader conditional, it works

borkdude09:06:08

I can reproduce this if you lint the code as non-cljc, but as clj. but if you put this code in a .cljc file, it works

tatut09:06:31

ok, so it is probably my emacs config that’s broken

borkdude09:06:03

to make sure, please test from a shell: clj-kondo --lint /tmp/foo.cljc

borkdude09:06:42

clj-kondo could probably report a better error message like: reader conditional not supported in .clj file or something

tatut09:06:15

ok, I had the old custom define-flycheck-checker instead of using flycheck-clj-kondo package

borkdude09:06:15

if you’re using flycheck-clj-kondo, it should trigger this inside a .cljc file: https://github.com/borkdude/flycheck-clj-kondo/blob/master/flycheck-clj-kondo.el#L74

borkdude09:06:27

ok, makes sense

tatut10:06:06

is there (or should there be) a way to mark namespaces that are required for side effects in the source (not config)?

tatut10:06:35

because I think that would be good documentation to be present in the source where the require is placed and could be used for linting purposes

borkdude10:06:08

@tatut that’s what we’re trying to achieve in this discussion: https://github.com/borkdude/clj-kondo/issues/241 a convention that all tooling/linters could use

👍 4
borkdude10:06:44

the voting has already started, so please read the issue and bring out your vote 🙂

tatut10:06:48

voted

🙏 4
borkdude10:06:51

@tatut if there are many similar namespaces you want to capture in one go, you can also use a regex in the config

Stefan11:06:56

@borkdude Confirmed, well done! 🎉

tatut14:06:41

that would be enough from a tooling stand point imo, but I kind of like forcing myself to explicitly state it (for documentation purposes)

tatut14:06:53

now the documentation is left to the comments (if any)

tatut14:06:17

but maybe less is more in this case, no need to get everyone to agree on a proper metadata style… just omit :as and :refer and it is assumed to be for side effects

borkdude14:06:15

@tatut I usually use comments to document why it is required, it can be for various reasons and comments do give you the freedom to explain it how you want

borkdude14:06:38

I think I would still use comments even if there were a metadata standard

tatut14:06:40

should clj-kondo just go ahead and implement it as per your comment? with optional configuration to set it off (something like :assume-implicit-require flag)

tatut14:06:48

I’m all for it, now that I think about it

borkdude14:06:03

yeah, I don’t see why not, in the next version

borkdude14:06:22

I think it makes sense as the default behavior (underreporting is better than overreporting) and an option to turn it off

Stefan18:06:29

@borkdude regarding that #241 issue, probably a “stupid” question, but does it have to be namespaced? Can’t it be simply ^:implicitly_used without ns (for example)?

borkdude18:06:54

that has been discussed in the issue, some people think it should be namespaced

borkdude18:06:02

just read all the comments, hehe 😉

Stefan18:06:26

Right, I did but too quickly apparently, sorry 😉

borkdude18:06:40

why the underscore though?

borkdude18:06:24

we could also just go with ^:used maybe

Stefan18:06:40

Ah my bad, that’s me being too new to clojure

Stefan18:06:08

cool I like that a lot, ^:used. Very succinct and to the point.

Stefan18:06:52

having trouble keeping the underscores out of my code as well 🙂 Maybe a new linter rule? 🤪

Stefan18:06:09

(prefer-kebab-to-snakes or something)

borkdude18:06:25

neh, sometimes you have to use those keys, e.g. when writing to a database table

Stefan18:06:29

(even though I’m veggi so I don’t feel comfortable with either)

borkdude18:06:54

there is vegan kebab

😋 8
Stefan18:06:17

I do live close to the German border, but that’s still a bit too far away I guess.

borkdude18:06:24

feel free to propose ^:used in the issue

👍 4
Stefan18:06:40

Anyway, what was that about the database table, didn’t quite understand that?

borkdude18:06:48

because table column names don’t support hyphens basically

Stefan18:06:20

Ah right thanks.

borkdude22:06:55

Documentation for an upcoming new unresolved symbols linter: https://github.com/borkdude/clj-kondo/blob/unresolved-symbols/doc/config.md#exclude-unresolved-symbols-from-being-reported If you like to take it for a test run, let me know.