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

clj-kondo #247

Open
awb99 opened this issue Oct 24, 2023 · 2 comments
Open

clj-kondo #247

awb99 opened this issue Oct 24, 2023 · 2 comments

Comments

@awb99
Copy link

awb99 commented Oct 24, 2023

This is not a bug of meander.
I use meander and clj-kondo.
The meander-templates trigger lots of :unresolved-symbol warnings in clj-kondo.
I am looking for a way to ignore this warnigns by way of clj-kondo config.
Any ideas?

@bnert
Copy link

bnert commented Nov 16, 2023

Adding a #_:clj-kondo/ignore around a form causes clj-kondo to ignore the inner form.

Usages given readme example:

(require '[meander.epsilon :as m])

(defn favorite-food-info [foods-by-name user]
  #_:clj-kondo/ignore
  (m/match {:user user
            :foods-by-name foods-by-name}
    {:user
     {:name ?name
      :favorite-food {:name ?food}}
     :foods-by-name {?food {:popularity ?popularity
                            :calories ?calories}}}
    {:name ?name
     :favorite {:food ?food
                :popularity ?popularity
                :calories ?calories}}))

And if you want to get really granular:

(require '[meander.epsilon :as m])

(defn favorite-food-info [foods-by-name user]
  (m/match {:user user
            :foods-by-name foods-by-name}
    #_:clj-kondo/ignore
    {:user
     {:name ?name
      :favorite-food {:name ?food}}
     :foods-by-name {?food {:popularity ?popularity
                            :calories ?calories}}}
    #_:clj-kondo/ignore
    {:name ?name
     :favorite {:food ?food
                :popularity ?popularity
                :calories ?calories}}))

There is also the option of adding an extension, though I am not really familiar w/ doing that and haven't invested enough time to understand that process, so will leave it as merely a mention.

@bsless
Copy link
Collaborator

bsless commented Nov 20, 2023

Rough starting point, but courtesy of @borkdude

;; .clj-kondo/meander/epsilon.clj:
(ns meander.epsilon
  (:require [clojure.string :as str]
            [clojure.walk :as walk]))

(defn collect-vars [expr]
  (let [vars (volatile! [])]
    (walk/postwalk (fn [x]
                     (when (and (symbol? x)
                                (str/starts-with? (str x) "?"))
                       (vswap! vars conj x))
                     x)
                   expr)
    @vars))

(defmacro rewrite [expr & exprs]
  (let [ret `(do ~expr
                 ~@(map (fn [[lhs rhs]]
                          `(fn ~(collect-vars lhs)
                             ~rhs))
                        (partition 2 exprs)))]
    ;; (prn ret)
    ret))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants