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

Fully qualified symbol in def referring to current namespace #1326

Closed
jimka2001 opened this issue Jul 24, 2021 · 3 comments
Closed

Fully qualified symbol in def referring to current namespace #1326

jimka2001 opened this issue Jul 24, 2021 · 3 comments
Projects

Comments

@jimka2001
Copy link
Contributor

version

I am using the clojure-lsp plugin + lisp-mode for emacs.

platform
MacOS

editor

emacs

problem

I see several wrong errors and warnings.
When I use alias to make an alias to the current package, and thereafter
prefix symbols with that alias, the analyser doesn't seem to recognize the names.

Screenshot 2021-07-24 at 13 47 22
repro

(ns jimka-test)
(alias 'jt 'jimka-test)
(def jt/xyz (fn [x] x))
(defn foo [x]
  (jt/xyz x))
(defn bar [x]
  (xyz x))

expected behavior

I expect that jt/xyz be treated like xyz if jt is aliased to the current namespace.

@jimka2001
Copy link
Contributor Author

As I understand Michiel Borkent already has a workaround for this issue.

@borkdude
Copy link
Member

A workaround using hooks:

def_hook.clj:

(ns def-hook
  (:require [clj-kondo.hooks-api :as api]))

(defn transform-def [{:keys [:node]}]
  (let [[name-node & arg-nodes] (rest (:children node))
        name-sym (api/sexpr name-node)]
    (when-not (simple-symbol? name-sym)
      (let [new-node (with-meta
                       (api/list-node
                        (list*
                         (api/token-node 'def)
                         (api/token-node (symbol (name name-sym)))
                         arg-nodes))
                       (meta node))]
        {:node new-node}))))
{:hooks {:analyze-call {clojure.core/def def-hook/transform-def}}}

@borkdude borkdude added this to Needs triage in clj-kondo via automation Jul 24, 2021
@borkdude borkdude moved this from Needs triage to Medium priority (new / enhance) in clj-kondo Jul 24, 2021
@borkdude borkdude changed the title clj-kondo does not understand alias Fully qualified symbol in def referring to current namespace Jul 24, 2021
@borkdude
Copy link
Member

@jimka2001 I decided to start supporting this one so we can get this out of the way while iterating on the macroexpand stuff.

clj-kondo automation moved this from Medium priority (new / enhance) to Done Jul 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
clj-kondo
  
Done
Development

No branches or pull requests

2 participants