Fork me on GitHub
#clj-kondo
<
2021-12-01
>
Noah Bogart00:12:20

I’m starting to work with #re-frame. The various event and subscription functions (`re-frame/reg-event-db`, etc) accept a function (usually an anonymous function) that take a regular set of inputs. Would it be possible to write a lint that requires certain function parameters to have specified names?

borkdude13:12:51

Can you give an example of this?

borkdude13:12:47

But yes, I think that is possible

Noah Bogart14:12:58

example from here: https://day8.github.io/re-frame/subscriptions/#reg-sub

(re-frame.core/reg-sub
  :id
  (fn [db query-v]
    (:something db)))
in the simplest usage, re-frame.core/reg-sub takes a keyword and a function (binding the function to the keyword in a hidden global state like s/def). the function must accept a hashmap and a vector. I’d like to specify that the hashmap always be named db.

Noah Bogart14:12:14

this will keep all of the reg-sub calls consistent and make writing the handling functions more clear (instead of potentially having one be db and another be app-db and a third be m)

borkdude22:12:01

@UEENNMX0T Yes, you can write a hook for this

chrisn19:12:43

Last issue I think - For the ffi system, I define the functions with datastructures and then use these to generate functions in the namespace:

chrisn19:12:10

In the above example, clj-kondo complains about memset not being defined.

chrisn19:12:36

I attempted a macro expansion of define-library-functions! but this could not use the data in the symbol - I had to use (resolve sym-name) in the macro in order to do this in Clojure and when sci is running the macro I can't resolve that variable like that.

chrisn19:12:21

One solution would be to collapse that all into one macro instead of a few macros. Then I could pass in the datastructure to the macro itself.

chrisn19:12:59

And hope users define it explicitly.

borkdude19:12:23

@chris441 what would you need in the hook, a helper function or more data?

chrisn19:12:45

I run through each function and define it with the appropriate args in the macro

borkdude19:12:51

I don't understand the issue

chrisn19:12:47

Ok, out of time - will explain further

👍 1
borkdude19:12:49

clj-kondo 2021.12.01  • Improve linting in `extend-protocol`, `extend-type`, `reify`, `specify!` https://github.com/clj-kondo/clj-kondo/issues/1333https://github.com/clj-kondo/clj-kondo/issues/1447 • Support `:context` in nodes in hooks for adding context to analysis https://github.com/clj-kondo/clj-kondo/issues/1211goog.object, `goog.string` etc must be required before use in newer releases of CLJS https://github.com/clj-kondo/clj-kondo/issues/1422 • Resume linting after invalid keyword https://github.com/clj-kondo/clj-kondo/issues/1451 • Fix install script for relative dir opts https://github.com/clj-kondo/clj-kondo/issues/1444 • Fix type mismatch error with auto-qualified keyword https://github.com/clj-kondo/clj-kondo/issues/1467 • String type hint causes false error report https://github.com/clj-kondo/clj-kondo/issues/1455 • Fix false positive with cljs/specify! https://github.com/clj-kondo/clj-kondo/issues/1450 • Improve analysis for ns-modifying destructuring key https://github.com/clj-kondo/clj-kondo/issues/1441 • CLJS `(exists? foo.bar/az)` complains about require https://github.com/clj-kondo/clj-kondo/issues/1472

🎉 6
clj-kondo 2