fulcrologic / guardrails

Efficient, hassle-free function call validation with a concise inline syntax for clojure.spec and Malli
Eclipse Public License 2.0
240 stars 26 forks source link

Add clj-kondo config with improved hook for >defn #28

Closed MrEbbinghaus closed 2 years ago

MrEbbinghaus commented 2 years ago

Finally, the PR mentioned in https://github.com/fulcrologic/fulcro/pull/492.

I tested it in my project:

❯ clj-kondo --copy-configs --dependencies --lint "$(clojure -Spath)"
Imported config to .clj-kondo/com.fulcrologic/guardrails. To activate, add "com.fulcrologic/guardrails" to :config-paths in .clj-kondo/config.edn.

TODO: We can kick the guardrails parts from the fulcro clj-kondo config.


Original PR: fulcro

The current clj-kondo hook for >defn produces a false positive when using argument predicates ("such that").

This would fail because the current implementation counts everything before =>:

(>defn my-fn [x]
  [::x | #(pos? x) => any?] 
  x)

I took the chance and added some more checks to the gspec validation.

gspec reference: [arg-specs* (| arg-preds+)? => ret-spec (| fn-preds+)? (<- generator-fn)?]

What errors are caught?

@holyjak Maybe you want to review this as well?

awkay commented 2 years ago

cool