This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-24
Channels
- # announcements (8)
- # babashka (16)
- # beginners (18)
- # biff (4)
- # calva (18)
- # clj-kondo (20)
- # clojure (24)
- # clojure-brasil (1)
- # clojure-europe (13)
- # clojure-nl (1)
- # clojure-norway (35)
- # clojure-uk (3)
- # clojurescript (16)
- # core-async (50)
- # cursive (5)
- # data-science (5)
- # datalevin (5)
- # datomic (69)
- # dev-tooling (18)
- # fulcro (3)
- # gratitude (1)
- # honeysql (5)
- # hyperfiddle (4)
- # jackdaw (2)
- # jobs-discuss (24)
- # lambdaisland (7)
- # lsp (16)
- # malli (5)
- # off-topic (65)
- # overtone (16)
- # pathom (28)
- # portal (3)
- # re-frame (24)
- # releases (1)
- # shadow-cljs (101)
Hi Team, we want to discourage other Clojure Engineers in our company from using js/fetch
. We intend on implementing a js-fetch
function which will add some extra instrumentation to requests before they are sent. I am trying to use clj-kondo
for this, however, I am having difficulties with getting the discouraged-var
linter to work with js/fetch
. Custom hooks also suffer from the same fate. For example, this linter works as expected for web.http/js-fetch
but not for js/fetch
:discouraged-var {js/fetch {:message "Use web.http/js-fetch instead"}
web.http/js-fetch {:message "Use web.http/js-fetch instead"}}
Thanks for the prompt response, is it related to https://github.com/clojure/clojurescript/blob/6ed949278ba61dceeafb709583415578b6f7649b/src/main/clojure/cljs/analyzer.cljc#L798-L799?
Cool, I'll open an issue 👍:skin-tone-5:
What you could do as a workaround is redefine js/fetch in your runtime to make it throw when you use it
Okay, that's an idea. I'll try that out and see if it works for us. Thank you!
So our hope was to wrap ‘js/fetch’ in a new function. Would we still be able to access it if we deleted it?
yes,
(def ^:private fetch js/fetch)
(js-delete js/globalThis "fetch")
(defn foobar [x]
(fetch x))
Cool, this is a great idea. I’ll use it thanks you 👍:skin-tone-5:
Nice catch. Would I have to define a fetch
function in a js
namespace? :thinking_face:
js/...
just means the global context. it would be the same as writing: (set! js/globalThis.fetch ...)
Nice but that might be confusing for people who dint know we’ve redefined it. They might expect to have to translate EDN into JSON for example.
My instinct for instance when I see js
is to use some interop.
Awesome, thank you so much for the help! I've created an https://github.com/clj-kondo/clj-kondo/issues/2318 (EDIT: I deleted this one and created a new one using my work account)
Sorry, I made a bit of a blunder. I created the issue using my personal GitHub account. Here's thehttps://github.com/clj-kondo/clj-kondo/issues/2319