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

Warn when using namespace alias that isn't idiomatic according the Clojure Style Guide #1839

Closed
sheluchin opened this issue Oct 16, 2022 · 1 comment
Projects

Comments

@sheluchin
Copy link
Contributor

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

Is your feature request related to a problem? Please describe.
The Clojure Style Guide has a Use Idiomatic Namespace Aliases section which lists a set of namespace aliases. Adding a linter to clj-kondo to nudge developers towards adapting these community aliases in their own code would help increase the consistency of Clojure code bases.

Describe the solution you'd like
Add a linter that warns when using an unidiomatic namespace alias, where the idioms are defined in the Clojure Style Guide.

This can be implemented by adding a :community-guide flag to the :consistent-alias linter. Namespaces which have explicit configuration in the :consistent-alias linter should overwrite the :community-guide configuration, in case users prefer some aliases of their own, but generally want to adopt the community standards.

Describe alternatives you've considered
@borkdude suggested that alternatively there can be a new clj-kondo library created which would contain the community guide aliases so they could get merged to a project's clj-kondo config when imported. This option would require the minimal change to clj-kondo itself -- probably just documentation. On the down side, this approach may be difficult when installing clj-kondo as a binary instead of a project dependency.

Additional context
Currently, the Style Guide recommends clojure.spec.alpha -> spec which is likely a bug. There is an open PR which changes this item and some others. There should be some expectation of the alias list evolving over time.

@borkdude borkdude added this to Needs triage in clj-kondo via automation Oct 16, 2022
@borkdude borkdude moved this from Needs triage to Medium priority (new / enhance) in clj-kondo Oct 16, 2022
@sheluchin
Copy link
Contributor Author

@borkdude went ahead and put up the https://github.com/clj-kondo/configs repo which includes the recently updated set of community guide aliases.

You can opt in by putting this in your project dependencies:

io.github.clj-kondo/config-bbatsov-clojure-style-guide-aliases {:mvn/version "0.1.1"}

and then restarting clojure-lsp or running:

clj-kondo --lint $(clojure -Spath) --dependencies --skip-lint --copy-configs

Note that you can overwrite one more more of the entries by configuring your own :consistent-alias linter.

Marking this as resolved as it seems to cover all the bases. Thank you, @borkdude!

clj-kondo automation moved this from Medium priority (new / enhance) to Done Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
clj-kondo
  
Done
Development

No branches or pull requests

1 participant