Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core.match support #496

Closed
tatut opened this issue Oct 3, 2019 · 9 comments
Closed

core.match support #496

tatut opened this issue Oct 3, 2019 · 9 comments
Labels
enhancement New feature or request
Projects

Comments

@tatut
Copy link

tatut commented Oct 3, 2019

In the example below clj-kondo warns "unresolved symbol a".

(let [v [1 2 3]]
  (m/match v
           [a _ _] (println "first number is " a)
           :else (println "got something other than vector of three")))
@borkdude borkdude added the enhancement New feature or request label Oct 4, 2019
@hjhamala
Copy link

hjhamala commented Oct 4, 2019

This should also support core matches or-syntax which currently causes arity error for keyword ->

(let [x 4 y 6 z 9]
(match [x y z]
[(:or 1 2 3) _ _] :a0
[4 (:or 5 6 7) _] :a1
:else nil))

@tatut
Copy link
Author

tatut commented Oct 4, 2019

My current plan is to just not lint the pattern part which is its own mini-language.
Only extract bindings from it so that they can be resolved in the consequence part.

@borkdude borkdude added this to In progress in clj-kondo Oct 15, 2019
@borkdude borkdude moved this from In progress to Medium priority (new / enhance) in clj-kondo Nov 18, 2019
@filipesilva
Copy link
Contributor

Note: you can follow https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#exclude-unresolved-symbols-from-being-reported to prevent those symbols from being reported for now.

@mikkosuonio
Copy link

Is there something I could do now to prevent an error from the or-keyword?

I get

match-test.cljs:6:14: error: keyword :or is called with 3 args but expects 1 or 2
match-test.cljs:6:26: error: unresolved symbol _
match-test.cljs:7:16: error: keyword :or is called with 3 args but expects 1 or 2

from

(ns match-test
  (:require [cljs.core.match] :as match))

(let [x 4 y 6 z 9]
     (match/match [x y z]
            [(:or 1 2 3) _ _] :a0
            [4 (:or 5 6 7) _] :a1
            :else nil))

using

{:linters {:unresolved-symbol   {:exclude [(clojure.core.match/match)
                                           (cljs.core.match/match)]}}}

@borkdude
Copy link
Member

borkdude commented May 6, 2020

@mikkosuonio Yes, there is a typo in your require spec:

(ns match-test
  {:clj-kondo/config '{:linters {:unresolved-symbol {:exclude [(cljs.core.match/match)]}
                                 :invalid-arity {:skip-args [cljs.core.match/match]}}}}
  (:require [cljs.core.match :as match]))

(let [x 4 y 6 z 9]
  (match/match [x y z]
               [(:or 1 2 3) _ ] :a0
               [4 (:or 5 6 7) _] :a1
               :else nil))

@mikkosuonio
Copy link

Thanks for pointing that out!

Config for invalid-arity with skip-args seems to work fine!

@borkdude borkdude moved this from Medium priority (new / enhance) to High priority (next release) in clj-kondo Jun 20, 2020
@borkdude borkdude moved this from High priority (next release) to Medium priority (new / enhance) in clj-kondo Jun 21, 2020
@borkdude borkdude moved this from Medium priority (new / enhance) to High priority (next release) in clj-kondo Jan 23, 2021
@borkdude borkdude moved this from High priority (next release) to In progress in clj-kondo Jan 26, 2021
@borkdude
Copy link
Member

Work in progress in the core-match branch:

Screenshot 2021-01-26 at 23 30 16

borkdude added a commit that referenced this issue Jan 29, 2021
@borkdude
Copy link
Member

Merged part 1 to master now. Awaiting your feedback.

You can grab a binary from CircleCI / appveyor or use the JVM version.

borkdude added a commit that referenced this issue Feb 10, 2021
borkdude added a commit that referenced this issue Feb 10, 2021
@borkdude
Copy link
Member

And now the final part, part 2 is merged too!

@borkdude borkdude moved this from In progress to Next release in clj-kondo Feb 10, 2021
clj-kondo automation moved this from Next release to Done Feb 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
clj-kondo
  
Done
Development

No branches or pull requests

5 participants