https://github.com/clj-kondo/inspector
Turn Clojure specs into clj-kondo type annotations
https://github.com/clj-kondo/inspector
Last synced: 4 days ago
JSON representation
Turn Clojure specs into clj-kondo type annotations
- Host: GitHub
- URL: https://github.com/clj-kondo/inspector
- Owner: clj-kondo
- License: epl-1.0
- Created: 2020-09-09T19:37:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-10T11:02:08.000Z (over 4 years ago)
- Last Synced: 2024-11-12T14:25:44.447Z (6 months ago)
- Language: Clojure
- Size: 11.7 KB
- Stars: 31
- Watchers: 7
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- stars - clj-kondo/inspector - Turn Clojure specs into clj-kondo type annotations \[*Eclipse Public License 1.0*\] (⭐️31) (Clojure)
- stars - clj-kondo/inspector - Turn Clojure specs into clj-kondo type annotations \[*Eclipse Public License 1.0*\] (⭐️31) (Clojure)
README
# Clj-kondo inspector
Experimental tool using a REPL-assisted static analysis approach. It turns [clojure.spec.alpha](https://github.com/clojure/spec.alpha) specs into [clj-kondo](https://github.com/borkdude/clj-kondo/) [type annotations](https://github.com/borkdude/clj-kondo/blob/master/doc/types.md) for linting.
Very alpha, breaking changes will happen. Not ready for serious usage. Contributions welcome.
## Usage
``` clojure
(require '[clj-kondo.inspector :as i])
(require '[your.specs])
(i/emit-types)
```Add `"configs/inspector"` to your `:config-paths` in `/.clj-kondo/config.edn`. Requires clj-kondo 2020.09.09 or newer.
## Example
From `test/clj_kondo/inspector/test_specs.clj`:
``` clojure
(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.