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

Global configuration as resource #8

Closed
vemv opened this issue Jun 30, 2022 · 7 comments · Fixed by #9
Closed

Global configuration as resource #8

vemv opened this issue Jun 30, 2022 · 7 comments · Fixed by #9

Comments

@vemv
Copy link
Contributor

vemv commented Jun 30, 2022

Hey there,

for a particular scenario I'd like to have a clj-kondo config released as a resource in a .jar and consumed from lein-clj-kondo.

The use case is definining org-wide preferences, etc.

I wonder if this is something that is possible OOTB already, or would it need some hacking?

The main feature/constraint is that the config should be a resource, not a file.

Maybe one could specify this as a Lein plugin option? {:config-resources ["mega/corp/clj_kondo_config.edn"]} which the plugin would convert into an io/resource call, slurp it, and pass that edn as https://github.com/clj-kondo/clj-kondo/blob/ab3172541dd07e52486962c762c6bd739ab25a09/src/clj_kondo/main.clj#L41-L42

WDYT?

@borkdude
Copy link
Member

@vemv You can do this by adding the config to a dependency in resources/clj-kondo.exports/your.org/your.lib/config.edn. When you then add this dependency to the classpath, and call lein clj-kondo --skip-lint --dependencies --copy-configs it should copy the configuration in your .clj-kondo dir and then clj-kondo should pick up on it.

Just make sure that library with exported config isn't used by anyone else, since exported configs should normally be just be about one specific library.

@vemv
Copy link
Contributor Author

vemv commented Jun 30, 2022

Nice!

Got it, thanks

@vemv vemv closed this as completed Jun 30, 2022
@vemv
Copy link
Contributor Author

vemv commented Jul 1, 2022

I kept thinking about my scenario and perhaps a .jar isn't the best solution to begin with.

We use a plugin similar to https://github.com/achin/lein-parent . So a kondo config could be defined in a parent project as Lein config.

Example:

;; project.clj
:clj-kondo {:config {:linters {:docstring-leading-trailing-whitespace {:level :warning}
                               :reduce-without-init                   {:level :warning}
                               :single-key-in                         {:level :warning}
                               :used-underscored-binding              {:level :warning}}}}

This would be similar to Eastwood config (which also is often expresed inline in project.clj or deps.edn) and overall a pretty vanilla feature that could serve various use cases.

PR OK?

@vemv vemv reopened this Jul 1, 2022
@borkdude
Copy link
Member

borkdude commented Jul 1, 2022

I'm fine with this, as long as it doesn't raise the expectation that "vanilla" clj-kondo supports reading configs from project.clj.

@borkdude
Copy link
Member

borkdude commented Jul 1, 2022

Maybe you're not aware of this, but if the shared config is part of a git mono-repo, say in $repo/shared-clj-kondo-config, you can refer to it from other projects in $repo/$project/.clj-kondo/config.edn with :config-paths ["../../shared-clj-kondo-config/config.edn"]

@vemv
Copy link
Contributor Author

vemv commented Jul 1, 2022

Yes, I had heard of monorepo niceties, however I'm using a polyrepo in this scenario

@borkdude
Copy link
Member

borkdude commented Jul 1, 2022

OK, even if you have polyrepos it works, as long as the directory structure matches. If the directory doesn't exist, then it won't crash, but it will just not include the config.

vemv added a commit to reducecombine/lein-clj-kondo that referenced this issue Jul 1, 2022
vemv added a commit to reducecombine/lein-clj-kondo that referenced this issue Jul 1, 2022
borkdude pushed a commit that referenced this issue Jul 1, 2022
* Bump clj-kondo

* Translate :clj-kondo config expressed in Leiningen project maps

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

Successfully merging a pull request may close this issue.

2 participants