-
-
Notifications
You must be signed in to change notification settings - Fork 292
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
unresolved symbol #174
Comments
@mynomoto Since you were the first to ask for this feature, would you be willing to give an early version of this a try? A binary can be downloaded by going to CircleCI https://circleci.com/gh/borkdude/clj-kondo/tree/unresolved-symbols, select the newest Or try out the I'm inclined to set the default level for this linter to |
I'm trying to get the binary but cannot find it on https://circleci.com/gh/borkdude/clj-kondo/3529 (the latest buildlinux). There is a step |
@mynomoto Aw, it seems the assets view isn't public on CircleCI. Here's the link to the latest: |
Some false positives:
I'm not sure about how to proceed on the last one because it happens a lot and may require lots of configuration. Joker solves it by allowing to define equivalent macros that joker understand. |
@mynomoto Could you give a code example the first one? E.g.:
seems to work? |
The one that I found is a destructuring on defmethod arguments. |
@mynomoto: For the third option, there is already the option to lint a macro as if it is a built-in macro. If you could provide a code example of such a macro, I could look if that's possible and else figure out something else, possibly looking at how joker solves it. |
We have many macros, most of def-something type, which is simple to deal with in the way you are describing. But we have a macro to generate standalone functions for all protocol defined functions (to spec the functions), which is too specific for clj-kondo to be concerned with. And we use a library https://github.com/nubank/matcher-combinators that introduces a symbol |
@mynomoto In the latter case, were you able to solve it with joker and if so, how? Could you give a code snippet example? |
@mynomoto I'm considering this new feature: a namespace local config. This only works regarding unresolved symbols for now: That should make it easier to exclude unresolved symbols from being warned about on a per-namespace basis? |
I'm not sure about what joker is doing because I have no configuration for that and it doesn't complain. It may treat macros differently.
I probably wouldn't use that because naming is uniform on the application I'm working so global would work better for this use case. I also don't like to have to change things in two places, I think that is more error prone than I'm confortable with. |
@mynomoto so can you give me an example of a code fragment where joker doesn't complain (without config) and clj-kondo does? |
Sure:
clj-kondo complains about |
@mynomoto Thank you for being so helpful with your feedback, I really appreciate it. This is because joker doesn't report unresolved symbols in I guess clj-kondo can take the same approach: don't report unresolved symbols in a configurable list of macros. Would that be better than making a list of excluded symbols? |
Actually joker is being too broad in this case. It can be configured to whitelist symbols inside macros, which would be more appropriate in this case. In this case, I'm not sure about the mechanism because putting |
@mynomoto We already have a
That's effectively the same as joker's Also we could let people specify symbols that are introduced by a macro, something like:
|
I think this may be expected but there is a perf hit on this branch. Before it just returned and now is taking 18 seconds for my project. |
I think that is a good place to start, 👍 |
Wow. Not acceptable. That's not what I'm seeing on CircleCI though (https://3563-176829714-gh.circle-artifacts.com/0/release/performance.txt): linting took 7476ms, errors: 3785, warnings: 1106 ==== Lint a single file (emulate in-editor usage) real 0m0.038s These times are comparable to the master branch. Are you using a config file? Can you post it here, so I might be able to reproduce? Is your linted code public, so I can test? This is the latest linux binary: |
Other problem is macros that define arbitrary vars, in this case hugsql that creates vars based on statements defined on |
This can usually be solved by using |
Nice, thanks for that! |
The code is not public, and to be clear for any file the result is instantaneous, linting the whole project for cache purposes is the command that is taking 18 seconds. The whole project has 796 clojure files with 107233 lines of code excluding blanks and comments. The following is the config file for the project (minus other excluded namespaces)
|
False positive: using a namespace to define a
False positive on tag literals
I think both of those are regressions, they were not reported before. |
False positive on if-some
|
@mynomoto Regarding the performance issue, can you try a couple of older versions of clj-kondo and see how they were doing? You can get them at: https://github.com/borkdude/clj-kondo/releases |
@borkdude call me crazy, cannot reproduce. Lastest 6 versions take about the same time. Sorry about the noise. |
@mynomoto No problem at all, it's good to keep an eye on performance. What I can imagine that happened is that you only linted |
@mynomoto The reported false positives should be fixed in https://3579-176829714-gh.circle-artifacts.com/0/release/clj-kondo-2019.06.08-alpha-SNAPSHOT-linux-amd64.zip |
More false positives (ns cljkondo
(:import
(clojure.lang ExceptionInfo)))
(defn ex-info?
[x]
(instance? ExceptionInfo x)) ; error: unresolved symbol ExceptionInfo
(defmacro foo
[s1 s2]
`(def ~s1
~@(let [v (resolve s2)] ; error: unresolved symbol v
(when (.hasRoot v)
(list (.getRawRoot v))))))
Object ; error: unresolved symbol Object
BigDecimal ; error: unresolved symbol BigDecimal
(defprotocol IFoo
"Foo"
(-foo [this]))
(identity IFoo) ; error: unresolved symbol IFoo |
@mynomoto Some false positives from the above code have been fixed in https://3597-176829714-gh.circle-artifacts.com/0/release/clj-kondo-2019.06.08-alpha-SNAPSHOT-linux-amd64.zip Also it supports some form of config which is documented here: https://github.com/borkdude/clj-kondo/blob/unresolved-symbols/doc/config.md#exclude-an-unresolved-symbol-from-being-reported One remaining issue is resolving all public classes from the |
@mynomoto This version supports java imports: TODO: add a list of java.lang classes that are imported by default. |
@mynomoto This version completes the TODO of the previous comment: all default imported classes are now recognized (like Also the docs descript all options how to prevent false positives: https://github.com/borkdude/clj-kondo/blob/unresolved-symbols/doc/config.md#exclude-unresolved-symbols-from-being-reported For now I turned down the level to |
Excluded a few false positives. Latest linux: https://3671-176829714-gh.circle-artifacts.com/0/release/clj-kondo-2019.06.08-alpha-SNAPSHOT-linux-amd64.zip |
False positive
|
Has something changed on how the command works? Ale seems not able use clj-kondo anymore. |
@mynomoto I've lowered the level of this linter from If ale doesn't support it, we could make the level to |
That was it, thanks! |
@mynomoto defrecord false positive fixed in: |
Fixed with 3dce371 |
One more false positive: (definterface Foo (foo []))
(identity Foo) ; warning: unresolved symbol Foo |
Another one: (ns cljkondo
(:require
[schema.core :as sc]))
(sc/defn bar :- #(last %) ; warning: unresolved symbol %
[x]
x) |
And my largest project is fully linted again! Thanks for all this work! |
@mynomoto Thank you. The last two false positives should be fixed with: |
Report unresolved vars
@mynomoto in the #clj-kondo slack channel:
declare
anddef
.getMessage
, anything starting with a dot probablycatch
andfinally
(only intry
)-hash
,*print-err-fn*
,js*
,*eval-fn*
,-write
,-flush
java.lang
(we can leverage our ExtractJava stuff for this, might be good to check against joker's list here(:import (clojure.lang ExceptionInfo))
(let [{{:keys [:a]} :stats} {:stats {:a 1}}] a)
clojure.lang.BigInt
The text was updated successfully, but these errors were encountered: