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

Support linting JavaScript vars in clj-kondo #2319

Closed
1 task done
mjarus007 opened this issue Apr 25, 2024 · 1 comment
Closed
1 task done

Support linting JavaScript vars in clj-kondo #2319

mjarus007 opened this issue Apr 25, 2024 · 1 comment
Projects

Comments

@mjarus007
Copy link

  • I have read the Clojure etiquette and will respect it when communicating on this platform.

Is your feature request related to a problem? Please describe.
In our company, we want to create a wrapper around js/fetch that will add standard instrumentation to the request headers. So, we'd like to discourage the use of js/fetch directly but rather show a linting error, saying "instead of js/fetch use web.http/js-fetch". However, clj-kondo does not currently support linting JavaScript vars and so linters such as discouraged-var and custom hooks cannot solve this problem. For example,

:discouraged-var
{js/fetch {:message "Use web.http/js-fetch instead"}
web.http/js-fetch' {:message "Use web.http/js-fetch instead"}}

web.http/js-fetch' shows a linting error as expected, however, js/fetch does not.

Describe the solution you'd like
A clear and concise description of what you want to happen.

I would like to be able to show a linting error when js/fetch is used by using code like this,

:discouraged-var
{js/fetch {:message "Use web.http/js-fetch instead"}}

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

  • I tried the discouraged-var linter
  • I've tried custom hooks
  • I even tried using a regex with namespace groups
:ns-groups [{:pattern "js"
              :name js}]
@borkdude borkdude added this to Needs triage in clj-kondo via automation Apr 25, 2024
@borkdude borkdude moved this from Needs triage to High priority (next release) in clj-kondo Apr 25, 2024
@borkdude
Copy link
Member

This already works today if you add:

:linters {:unresolved-namespace {:exclude [js]}

to your config:

$ clj -M:clj-kondo/dev --lint - --lang cljs --config '{:linters {:unresolved-namespace {:exclude [js]} :discouraged-var {js/fetch {:message "Use web.http/js-fetch instead"}}}}' <<< 'js/fetch'
<stdin>:1:1: warning: Use web.http/js-fetch instead

I'll make it work without that config though.

clj-kondo automation moved this from High priority (next release) to Done May 22, 2024
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

2 participants