redplanetlabs / specter

Clojure(Script)'s missing piece
Apache License 2.0
2.51k stars 102 forks source link

clj-kondo config #310

Closed IGJoshua closed 3 years ago

IGJoshua commented 3 years ago

Many people like to use the clj-kondo linter, which requires special handling for macros to lint correctly in order to preserve source information, like where in source a symbol comes from. At the moment much of specter is broken under clj-kondo because many of the navigators are defined in terms of custom macros.

Adding a configuration to fix this is fairly easy, all it requires is adding the following in a .clj-kondo/config.edn file:

{:lint-as {com.rpl.specter/defnav clojure.core/defn
           com.rpl.specter/defmacroalias clojure.core/defn}}

This can be done per-project, although it gets somewhat repetitive and it requires some knowledge of how specter is defined internally (although it's not hard to gain this knowledge).

A solution to this problem of duplication is to include this configuration as a default in specter, which can be done by placing a resource on the classpath at clj-kondo.exports/com.rpl/specter/config.edn with the above content. This may be considered a problem since it adds a small amount of extra content to the artifact that is not used at runtime. An alternate solution to this issue is simply to include the above snippet in a section in the project readme.

I would like to make a PR resolving this issue, but I would like your input on whether to update the readme, or to include it in the artifact.

IGJoshua commented 3 years ago

I've been looking through specter a bit more, and there's a couple more things that will need to be added to the config map that's listed above, I'll add a comment with a full config soon.

nathanmarz commented 3 years ago

It's best to add the snippet towards the end of the README.

IGJoshua commented 3 years ago

The configuration snippet that I proposed in the PR definitely doesn't do anything about trying to lint the specter source code itself, but it resolves lint problems in others' code when using specter.