Skip to content

clj-kondo/inspector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clj-kondo inspector

Experimental tool using a REPL-assisted static analysis approach. It turns clojure.spec.alpha specs into clj-kondo type annotations for linting.

Very alpha, breaking changes will happen. Not ready for serious usage. Contributions welcome.

Usage

(require '[clj-kondo.inspector :as i])
(require '[your.specs])
(i/emit-types)

Add "configs/inspector" to your :config-paths in <project>/.clj-kondo/config.edn. Requires clj-kondo 2020.09.09 or newer.

Example

From test/clj_kondo/inspector/test_specs.clj:

(ns clj-kondo.inspector.test-specs
  (:require [clj-kondo.inspector :as i]
            [clojure.spec.alpha :as s]))

(defn foo [x y]
  (+ x y))

(s/def ::x string?)
(s/def ::y ::x)

(s/fdef foo :args (s/cat :x int? :y ::y))

(comment (foo 1 :foo)) ;; Expected string, received keyword

(defn bar [m]
  m)

(s/def ::z string?)

(s/fdef bar :args (s/cat :m (s/keys :req-un [::x ::y]
                                    :opt-un [::z])))

(comment (bar {:x "foo"}) ;; Missing required key :y
         (bar {:x 1 :y "foo"}) ;; Expected string, received positive integer
         (bar {:x "foo" :y "foo" :z 1}) ;; Expected string, received positive integer
         )

License

Copyright © 2020 Michiel Borkent

Distributed under the EPL License, same as Clojure. See LICENSE.

About

Turn Clojure specs into clj-kondo type annotations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published