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

Alias usages not detected from keywords in quoted forms #981

Closed
milankinen opened this issue Aug 31, 2020 · 4 comments
Closed

Alias usages not detected from keywords in quoted forms #981

milankinen opened this issue Aug 31, 2020 · 4 comments

Comments

@milankinen
Copy link

milankinen commented Aug 31, 2020

Hi and thanks for this great tool! Here is a small issue we found while using it:

version

clj-kondo v2020.07.29

platform

Native version / OSX and Linux

problem

It seems that alias usages from quoted forms are not registered. If alias is used only in quoted form (real life example case: Datomic queries), clj-kondo gives warning: namespace <ns> is required but never used. However, if we remove the require, the code won't work anymore because reader can't recognize keyword without it.

We've solve this by so far by using fully qualified keywords but it's a bit annoying because some of the namespaces can be quite long.

repro

Here is a very basic code reproducing the issue (uses default configs):

(ns org.tsers.example
  (:require [datomic.api :as d]
            [org.tsers.user :as user]))

(defn find-users-by-country [db country]
  (d/q '[:find [?user-id ...]
         :in $ ?country 
         :where [?user ::user/country ?country]
                [?user ::user/id ?user-id]]
        db country))

expected behavior

I'd expect the code to be linted without warnings, instead I get

$ ./clj-kondo --lint example.clj 
example.clj:3:14: warning: namespace org.tsers.user is required but never used
linting took 10ms, errors: 0, warnings: 1
@milankinen milankinen changed the title Alias usages not detected from quoted forms Alias usages not detected from keywords in quoted forms Aug 31, 2020
@borkdude borkdude added this to Needs triage in clj-kondo via automation Aug 31, 2020
@borkdude borkdude moved this from Needs triage to High priority (next release) in clj-kondo Aug 31, 2020
@borkdude
Copy link
Member

A small workaround for now is to add a top-level keyword ::user/foo or use this config:

https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#exclude-required-but-unused-namespace-from-being-reported

@milankinen
Copy link
Author

Yes we've indeed considered those as well but decided not to use them because of the possibility to accidentally cause false negatives by forgetting the references/exclusions while doing code refactors. Having to write the fully qualified keyword name is a bit annoying but at least it's robust over time and easier to maintain.

@borkdude
Copy link
Member

borkdude commented Sep 1, 2020

Fixed on master.

@borkdude borkdude moved this from High priority (next release) to Next release in clj-kondo Sep 1, 2020
@milankinen
Copy link
Author

Wow that was fast! Thank you!

@borkdude borkdude closed this as completed Sep 9, 2020
clj-kondo automation moved this from Next release to Done Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
clj-kondo
  
Done
Development

No branches or pull requests

2 participants