clj-kondo

https://github.com/clj-kondo/clj-kondo
cjsauer 2021-04-05T16:19:07.193800Z

When writing a custom hook, can I pass line/col metadata in the ex-data of an error?

cjsauer 2021-04-05T16:19:42.194300Z

I want to treat this problem as an error, not a warning, but still retain helpful line/col info

cjsauer 2021-04-05T16:20:05.194800Z

Right now when I throw, it “puts” the error onto the top-level form, but I have the exact line/col info of the real issue

cjsauer 2021-04-05T16:20:32.195100Z

(throw (ex-info "defmutation handlers must take 1 argument"
                          {:type :fulcro/defmutation
                           :row row
                           :col col}))

cjsauer 2021-04-05T16:20:35.195300Z

Something like this

borkdude 2021-04-05T16:20:47.195500Z

yes, that should work

borkdude 2021-04-05T16:21:21.196100Z

well, type isn't picked up from ex-data, but row and col are

borkdude 2021-04-05T16:22:03.196600Z

it probably should, but it isn't the case right now. but you can use reg-finding! to do what you want

cjsauer 2021-04-05T16:22:29.197100Z

Can reg-finding! be configured to be a fatal error?

borkdude 2021-04-05T16:22:44.197400Z

you have to set :level :error

cjsauer 2021-04-05T16:22:51.197600Z

Ahh duh, I see it now

cjsauer 2021-04-05T16:22:52.197800Z

Thank you

borkdude 2021-04-05T16:24:29.198400Z

note that the user will also have to configure :fulcro/defmutation in the linter config and set a level for it

borkdude 2021-04-05T16:24:46.198900Z

I think the :level isn't even relevant from where it's emitted, it's always the one from the config

cjsauer 2021-04-05T16:25:13.199300Z

Hm yea, must be, still can’t quite get it working

cjsauer 2021-04-05T16:28:33.200800Z

I think I’m doing something slightly weird is the problem. Basically, I’m transforming fulcro’s defmutation into something like this:

(defn my-mutation
  [params]
  (letfn [(action [env])
          (remote [env])]
    (action nil)
    (remote nil)))
It’s “close enough” to what I want the linting to do, but it’s giving me stray errors like “action is called with 1 arg instead of 0"…I’m trying to override those subsequent/general linters with my own very specific error messages, if that makes sense

borkdude 2021-04-05T16:35:10.201300Z

I don't know these macros to say with confidence if that makes sense.

borkdude 2021-04-05T16:36:03.201500Z

but in general I think it does

cjsauer 2021-04-05T19:30:48.202200Z

Inside of a reg-finding! map, how should I qualify :type keywords? I’m thinking something like this: :clj-kondo.fulcro.defmutation/handler-arity

cjsauer 2021-04-05T19:31:30.203100Z

Originally I had :com.fulcrologic.fulcro.mutations.defmutation/handler-arity, but that’s not a domain I own, so I shouldn’t be adding keys to it yea? Still figuring out how to namespace keywords generally…

borkdude 2021-04-05T19:36:34.203800Z

yeah, I think your proposal is reasonable

👍 1