Skip to content

Commit

Permalink
Fix #2274: support new clojure 1.12 type hint notations (#2275)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Feb 12, 2024
1 parent 7da0b13 commit c004abe
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ For a list of breaking changes, check [here](#breaking-changes).

## Unreleased

- [#2274](https://github.com/clj-kondo/clj-kondo/issues/2274): Support clojure 1.12 new type hint notations
- [#1917](https://github.com/clj-kondo/clj-kondo/issues/1917): detect string being called as function
- [#1923](https://github.com/clj-kondo/clj-kondo/issues/1923): Lint invalid fn name
- [#2256](https://github.com/clj-kondo/clj-kondo/issues/2256): enable `assert` in hooks
- [#2253](https://github.com/clj-kondo/clj-kondo/issues/2253): add support for `datomic-type-extensions` to datalog syntax checking
- [#2255](https://github.com/clj-kondo/clj-kondo/issues/2255): support `:exclude-files` in combination with linting from stdin + provided `--filename` argument
- [#2246](https://github.com/clj-kondo/clj-kondo/issues/2246): preserve metadata on symbol when going through `:macroexpand` hook
- [#1923](https://github.com/clj-kondo/clj-kondo/issues/1923): Lint invalid fn name
- [#2254](https://github.com/clj-kondo/clj-kondo/issues/2254): lint files in absence of config dir
- [#2256](https://github.com/clj-kondo/clj-kondo/issues/2256): enable `assert` in hooks
- [#2251](https://github.com/clj-kondo/clj-kondo/issues/2251): support suppressing `:unused-value` using `:config-in-call`
- [#2266](https://github.com/clj-kondo/clj-kondo/issues/2266): suppress `:not-a-function` linter in reader tag
- [#2259](https://github.com/clj-kondo/clj-kondo/issues/2259): `ns-map` unmaps var defined prior in namespace
- [#2272](https://github.com/clj-kondo/clj-kondo/issues/2272): Report var usage in `if`/`when` condition as always truthy
- [#2272](https://github.com/clj-kondo/clj-kondo/issues/2272): Report var usage in `if`/`when` condition as always truthy, e.g. `(when #'some-var 1)`

## 2023.12.15

Expand Down
4 changes: 3 additions & 1 deletion src/clj_kondo/impl/analyzer/usages.clj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@
symbol-val)
expr-meta (meta expr)]
(if-let [b (when (and simple? (not syntax-quote?))
(get (:bindings ctx) symbol-val))]
(or (get (:bindings ctx) symbol-val)
(get (:bindings ctx)
(str/replace (str symbol-val) #"\**$" ""))))]
(namespace/reg-used-binding! ctx
(-> ns :name)
b
Expand Down
4 changes: 3 additions & 1 deletion src/clj_kondo/impl/metadata.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
boolean boolean
byte bytes
char chars
objects]
objects
_]
(repeat {})))

(defn lift-meta-content2
Expand All @@ -42,6 +43,7 @@
meta-ctx
(-> ctx
(update :callstack conj [nil :metadata])
(assoc :in-meta true)
(utils/ctx-with-bindings
(cond->
type-hint-bindings
Expand Down
13 changes: 8 additions & 5 deletions src/clj_kondo/impl/namespace.clj
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,14 @@
(do (java/reg-class-usage! ctx (str name-sym) nil (meta expr))
(when call? (findings/warn-reflection ctx expr))
{:interop? true})
{:ns (or referred-all-ns :clj-kondo/unknown-namespace)
:name name-sym
:unresolved? true
:allow-forward-reference? (:in-comment ctx)
:clojure-excluded? clojure-excluded?})))))))))))
(let [name-str (str name-sym)]
(if (and (:in-meta ctx) (str/ends-with? name-str "*"))
(recur ctx call? ns-name (symbol (subs name-str (dec (count name-str)))) expr)
{:ns (or referred-all-ns :clj-kondo/unknown-namespace)
:name name-sym
:unresolved? true
:allow-forward-reference? (:in-comment ctx)
:clojure-excluded? clojure-excluded?})))))))))))))

;;;; Scratch

Expand Down
8 changes: 7 additions & 1 deletion test/clj_kondo/unresolved_symbol_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,19 @@
(is (empty? (lint! "(ns foo) (comment (map square [1 2 3])) (defn square [x] (* x x))"
{:linters {:unresolved-symbol {:level :error}}}))))

(deftest primitive-type-hints-test
(deftest type-hints-test
(is (empty? (lint! "(ns my-app
(:refer-clojure :exclude [double int]))
(defn scalb
[x exp]
(Math/scalb ^double x ^int exp))"
{:linters {:unresolved-symbol {:level :error}}})))
(is (empty? (lint! "
(^[_] java.net.URI/new \"http://localhost\")
(^[long*] java.net.URI/new \"http://localhost\")
(^[short*] java.net.URI/new \"http://localhost\")
(^[String*] java.net.URI/new \"http://localhost\")"
{:linters {:unresolved-symbol {:level :error}}}))))

(deftest exclude-patterns-test
Expand Down

0 comments on commit c004abe

Please sign in to comment.