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

Project clj-kondo config file not being considered #1026

Closed
lread opened this issue Feb 9, 2021 · 20 comments
Closed

Project clj-kondo config file not being considered #1026

lread opened this issue Feb 9, 2021 · 20 comments
Labels

Comments

@lread
Copy link

lread commented Feb 9, 2021

Symptom
When I run clj-kondo from the command line I get no errors and no warnings.
In Calva, clj-kondo issues are reported.

Enviromnent

  • Calva v2.0.170
  • clj-kondo v2021.01.20
  • macOS 10.15.7
  • clojure v1.10.2.77

Reproduction

  1. Clone my project's v1 branch (I'll refine this to something smaller if its too much)

    $ git clone --branch v1 https://github.com/clj-commons/rewrite-clj.git rewrite-clj-repro

    If you want to match the exact commit I tested against:

    $ cd rewrite-clj-repro
    $ git reset --hard 377bb5d7f86a4751350b0d347856b60a25528bc4
    $ git clean -f -d
  2. Run clj-kondo on the command line and witness no errors/warnings:

    $ cd rewrite-clj-repro
    $ clj-kondo --lint src test script
    linting took 1287ms, errors: 0, warnings: 0
  3. Open the cloned repo in Calva and navigate to test/rewrite_clj/zip_test.cljc

Expected Behaviour
I would expect to see no clj-kondo errors, matching the command line invoked clj-kondo results.

Actual Behaviour
I see unresolved-var clj-kondo warnings, for example:
image

Extra Info

  1. On Slack I was talking about clj-kondo hooks, you should ignore that.
  2. I am new to Calva, maybe I missed something obvious?
  3. I already just fixed one typo in my .clj-kondo/config.edn maybe there's something else amiss in there that clj-kondo handles just fine but affects Calva.
  4. If I delete the :lint-as config for import-varsand rerun clj-kondo from the command line, as expected, tons of unresolved symbol errors are reported from clj-kondo command-line.
@bpringe
Copy link
Member

bpringe commented Feb 9, 2021

Thanks for the detailed report. @ericdallo, since Calva's really just the middleman here, I think this would be more something with clojure-lsp itself. Calva doesn't affect what clojure-lsp uses as the clj-kondo config or how files are linted.

@bpringe bpringe added the lsp label Feb 9, 2021
@ericdallo
Copy link
Contributor

I will test it locally soon with only clojure-lsp + emacs

@ericdallo
Copy link
Contributor

ericdallo commented Feb 9, 2021

@lread I found the issue, it is a clj-kondo issue that happens with libs that use potemkim like rewrite-clj, so clj-kondo does not return analysis for those symbols 😔 It's actually the same issue we run using clojure-lsp on its own project 😅 , that's why we have these config
c/c @borkdude

@borkdude
Copy link

borkdude commented Feb 9, 2021

The question remains why clj-kondo itself gives no warnings for @lread's project but clojure-lsp does?

@lread has these hooks:

 :hooks {:analyze-call {rewrite-clj.potemkin.clojure/import-vars-with-mods
                        hooks.rewrite-clj.potemkin.import-vars-with-mods/import-vars-with-mods

                        rewrite-clj.potemkin.cljs/import-vars-with-mods
                        hooks.rewrite-clj.potemkin.import-vars-with-mods/import-vars-with-mods}}

which are used to "teach" clj-kondo how to interpret their custom import-vars macros. It seems this isn't recognized by the clj-kondo invocation of clojure-lsp.

@borkdude
Copy link

borkdude commented Feb 9, 2021

I checked the referenced issue and that turned out to be a non-issue.

@ericdallo
Copy link
Contributor

Got it, didn't notice that, I will double-check clojure-lsp so

@ericdallo
Copy link
Contributor

Testing local I confirmed clojure-lsp is not considering the project clj-kondo config file for some reason, I'll take a look, created this issue to track: clojure-lsp/clojure-lsp#308

@ericdallo
Copy link
Contributor

Fixed on latest clojure-lsp release, it seems it was a bug introduced during the kondo integration, I'll think in some kind of integration test to catch bugs like that.

@lread after Calva updates clojure-lsp version, you should get no warnings in your project again :)

@bpringe bpringe changed the title Command line clj-kondo reporting differs from Calva clj-kondo? Project clj-kondo config file not being considered Feb 10, 2021
@bpringe
Copy link
Member

bpringe commented Feb 10, 2021

@lread Please try out the latest version and see if the issue is resolved. (2.0.171)

@lread
Copy link
Author

lread commented Feb 10, 2021

Much thanks for the fix, I am no longer getting unresolved-var errors in Calva v2.0.171 for my import-vared variables.

But... something else seems amiss now. If you look up at my original example screenshot code snippit from this issue:

(deftest of-string-simple-sexpr
  (let [sexpr "(+ 1 2)"]
   (is (= sexpr (-> sexpr z/of-string z/root-string)))))

It's good, no unresolved-var errors. But.. if I add in something obviously invalid:

(deftest of-string-simple-sexpr
  (let [sexpr "(+ 1 2)"]
   (is (= sexpr (-> sexpr z/of-string z/invalid z/root-string)))))

I would expect an unresolved-var error for z/invalid but am not seeing it reported in Calva.

If I run clj-kondo from the command line, I get the expected warning:

$ clj-kondo --lint src test script
test/rewrite_clj/zip_test.cljc:10:39: warning: Unresolved var: z/invalid
linting took 1395ms, errors: 0, warnings: 1 

If I temporarily add in something contrived like:

(string/notgood)

Calva correctly reports the clj-kondo unresolved-var warning.

Do you see this as unexpected behaviour? If so, do you want me to raise a separate issue?

@bpringe
Copy link
Member

bpringe commented Feb 10, 2021

Hmm @ericdallo ^?

@ericdallo
Copy link
Contributor

ericdallo commented Feb 10, 2021

Yeah, I confirmed this is happening in clojure-lsp with lsp-mode too.
But with my tests, clj-kondo is not returning the unresolved-var too 🤔 when adding a z/unknown-function:

$ cat ./rewrite-clj-repro/test/rewrite_clj/zip_test.cljc | clj-kondo --config '{:cache false}' --lint -
=> linting took 201ms, errors: 0, warnings: 0

Am I missing something @borkdude ?

@borkdude
Copy link

borkdude commented Feb 10, 2021

@ericdallo Clj-kondo will only complain about unresolved vars when you lint both namespaces at the same time, or one the required namespaces comes from the cache.

@lread
Copy link
Author

lread commented Feb 10, 2021

There's probably a good reason Calva/lsp is not using clj-kondo cache?

@ericdallo
Copy link
Contributor

ericdallo commented Feb 10, 2021

oh, got it, I changed clojure-lsp to not use the cache when linting a single file, so that is not fixed correctly, I could not make it work without not using the cache though, I'll need to understand why adding the cache make clj-kondo ignore the config

@borkdude
Copy link

Yeah, that's not so beneficial since clj-kondo won't get updated information while the user is typing.

@ericdallo
Copy link
Contributor

@borkdude do you see any config that does not makes sense here, besides the cache false?

@borkdude
Copy link

@ericdallo nope, makes sense

@ericdallo
Copy link
Contributor

So as discussed here this is a corner case bug on clj-kondo, I'll fix clojure-lsp side to always use the cache thought, but we still need a fix on clj-kondo @lread

@lread
Copy link
Author

lread commented Feb 10, 2021

Coolio, thanks for update! Nice troubleshooting!

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

No branches or pull requests

4 participants