-
Notifications
You must be signed in to change notification settings - Fork 7
/
api.clj
45 lines (35 loc) · 1.75 KB
/
api.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(ns clj-depend.api
(:require [clj-depend.internal-api :as internal-api])
(:import [java.io File]))
(defn analyze
"Analyze namespaces dependencies.
Takes a map with:
- `:project-root` required, a java.io.File representing the project root.
- `:config` optional, a configuration map. Otherwise, it will try to resolve the configuration using `.clj-depend/config.edn` in `:project-root` directory.
- `:files` optional, a set of files or directories (java.io.File) representing files to be analyzed. If empty, all files in source paths declared in config will be considered.
- `:namespaces` optional, a set of symbols representing namespaces to be analyzed. If empty, all project namespaces will be considered.
Returns a map with:
- `:result-code` required, an integer:
- 0: no violations were found
- 1: one or more violations were found
- 2: error during analysis
- `:message` required, a string with message.
- `:violations` a set of maps with `:namespace` and `:violation`.
**Example**
```clojure
(clj-depend.api/analyze {:project-root (io/file \".\")
:config {:source-paths #{\"src\"
:layers {:foo {:defined-by \"foo\\..*\" :accessed-by-layers #{}}
:bar {:defined-by \"bar\\..*\" :accessed-by-layers #{:foo}}}}}
:namespaces #{foo.x bar.y}})
```"
[{:keys [project-root config files namespaces] :as options}]
{:pre [(and (instance? File project-root)
(.exists ^File project-root))
(or (nil? config)
(map? config))
(or (nil? files)
(set? files))
(or (nil? namespaces)
(set? namespaces))]}
(internal-api/analyze options))