tolitius / mount

managing Clojure and ClojureScript app state since (reset)
Eclipse Public License 1.0
1.22k stars 88 forks source link

Update defstate clj-kondo hook to return a var #133

Closed NoahTheDuke closed 5 days ago

NoahTheDuke commented 1 month ago

Follow-up to #130, addresses the issue mentioned in https://github.com/tolitius/mount/pull/130#issuecomment-1980554084.

Problem statement

The clj-kondo hook for defstate doesn't register the state's symbol as a var, which marks all subsequent usages as unresolved symbols. This is because for (defstate conf :start (load-config)), it produces the node (fn* [conf] conf :start (load-config)).

Proposed solution

Change the produced node to (def conf (do :start (load-config))).

I also added a .clj-kondo/config.edn which references the config in resources/, to make it easier to use in this project. And I moved the hook folder into the mount/mount folder, which helps clj-kondo find it easier and prevents merge-conflicts if a user calls --copy-configs and multiple projects have defined resources/clj-kondo.exports/hooks folders.

pmonks commented 1 month ago

Just tried this out on one of my projects that uses mount and confirmed that it works better than the existing hook.

ieugen commented 1 month ago

Thank you @NoahTheDuke I can confirm. Using the commit with a Calva project setup I no longer see the linting errors

        mount/mount {:git/url "https://github.com/tolitius/mount.git"
        :git/sha "4065f5df368893dcb4546fd80f573ee9f9226f85"}

image

ieugen commented 2 weeks ago

@tolitius : Can you please take a look at this PR and consider merging it? Thanks.

tolitius commented 5 days ago

@ieugen merged is in [0.1.19]

let me know whether it works

ieugen commented 5 days ago

it works, thanks ! I removed .clj-kondo directory to force re-download of the clj-kondo imports.