clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
2020-01-09T14:34:04.002900Z

hey everyone, is clojure.spec intented to be use as a linter ? I mean currently it only outputs errors but I see many opportunities it outputting warnings instead. However I dont see anything in spec to “capture” the error and print it as a warning instead :thinking_face: ps: not sure if this question belongs in this channel

seancorfield 2020-01-09T17:02:17.004Z

@carocad Linters check code statically, Spec checks data structures and functions at runtime -- can you elaborate on how you image Spec being used in the former scenario?

2020-01-09T17:07:27.004100Z

> Linters check code statically afaik, no such restriction exists. That is just the “standard” way > Spec checks data structures and functions at runtime maybe I am being naive but since you have access to the code on macro expansion it should be possible to pattern match the input code to issue warning/errors. Throwing would probably be bad but clojure introduced tap so I guess it should be possible to just send the warning/errors over there. Not sure yet how to make this work outside of a repl but so far this is just an idea 🙂

seancorfield 2020-01-09T17:09:56.004300Z

So you'd basically have to write a Spec for Clojure code and read in files and conform them to that Spec? 👀

2020-01-09T17:10:15.004500Z

yes

1
seancorfield 2020-01-09T17:11:56.004700Z

I'll be very interested in anything you produce in that vein. Sounds fascinating (but I'm seriously skeptical of the feasibility right now).

2020-01-09T17:13:51.005Z

> I’m seriously skeptical of the feasibility right now me too … that is why I posted it here hoping that people with way more experience on the inner workings of clojure would point out any “obvious” error 😅

2020-01-09T17:15:57.005200Z

> So you’d basically have to write a Spec for Clojure code and read in files and conform them to that Spec? that would be for cli usage. I was hoping to “just” instrument the macro symbol and lint while on repl

borkdude 2020-01-09T19:49:16.005400Z

if you want warnings instead of errors you could just catch the spec exceptions and handle them maybe?

borkdude 2020-01-09T19:50:00.005600Z

@carocad are you aiming on specs for clojure.core? that has been done here as well: https://github.com/borkdude/speculative

2020-01-09T21:02:32.006Z

@borkdude yeah I checked your work on speculative great work btw 🙂 . Unfortunately it seems to only include functions not macros so I came here looking for more info 🙂 > if you want warnings instead of errors you could just catch the spec exceptions and handle them maybe? I have not seen a way to do this since the error is thrown by the compiler. Not sure if the repl has a hook that I can use :thinking_face: