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

:used-underscore-binding reports false positives with clojure.core.match/match #2152

Closed
camsaul opened this issue Aug 3, 2023 · 2 comments
Closed
Labels
Projects

Comments

@camsaul
Copy link
Contributor

camsaul commented Aug 3, 2023

version

clj-kondo v2023.07.13

macro usage

Yes, clojure.core.match/match

platform

Native version installed via Homebrew on Linux

editor

N/A

problem

If you enable the :used-underscored-binding linter, a form like

(clojure.core.match/match [:name x y]
  [:name _ _]
  "Ok")

triggers a

Used binding is marked as unused: _

warning. This is a a false positive, since _ has a special meaning in clojure.core.match/match. It's not used in the macroexpansion either:

(let [ocr-149912 :name x x y y]
  (try
    (cond (= ocr-149912 :name) "Ok" :else (throw clojure.core.match/backtrack))
    (catch Exception e__46989__auto__
      (if (identical? e__46989__auto__ clojure.core.match/backtrack)
        (throw (java.lang.IllegalArgumentException. (str "No matching clause: " ocr-149912 " " x " " y)))
        (throw e__46989__auto__)))))

repro

(ns repro
  (:require [clojure.core.match :as match]))

(let [x 1 y 2]
  (match/match [:name x y]
    [:name _ _]
    "Ok"))

config

{:linters {:used-underscored-binding {:level :warning}}}

expected behavior

Since this is a part of Clojure core, it would be nice if it worked out of the box. If that's not possible, it would be nice if the :used-underscore-binding linter was configurable and could be disabled inside of specific forms clojure.core.match forms without needing a :clj-kondo/ignore every time you use it

@borkdude
Copy link
Member

borkdude commented Aug 3, 2023

Thanks, makes sense

@borkdude borkdude added this to Needs triage in clj-kondo via automation Aug 3, 2023
@borkdude borkdude moved this from Needs triage to High priority (next release) in clj-kondo Aug 3, 2023
@borkdude
Copy link
Member

borkdude commented Aug 3, 2023

$ clj -M:clj-kondo/dev --lint - --config '{:linters {:used-underscored-binding {:level :warning}}}' <<< "(require '[clojure.core.match]) (declare x y) (clojure.core.match/match [:name x y]
  [:name _ _]
  \"Ok\")"
<stdin>:2:10: warning: Used binding is marked as unused: _

clj-kondo automation moved this from High priority (next release) to Done Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
clj-kondo
  
Done
Development

No branches or pull requests

2 participants