-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
filesystem.clj
37 lines (32 loc) · 1.13 KB
/
filesystem.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
(ns clj-holmes.filesystem
(:require [clojure.data.json :as json]
[clojure.string :as string]
[clojure.tools.reader.edn :as edn])
(:import (java.io File)))
(defn ^:private remove-dot-slash [filename]
(if (string/starts-with? filename "./")
(string/replace filename #"\./" "")
filename))
(defn ^:private clj-file? [file]
(and (.isFile file)
(-> file .toString (string/includes? "project.clj") not)
(-> file .toString (.endsWith ".clj"))))
(defn clj-files-from-directory! [directory]
(let [file-sanitize (comp remove-dot-slash str)]
(->> directory
File.
file-seq
(filter clj-file?)
(map file-sanitize))))
(defn load-rules! [directory]
(let [reader (comp edn/read-string slurp)]
(->> directory
File.
file-seq
(filter #(.isFile %))
(map reader))))
(defn save-sarif-report! [sarif-report directory]
(let [sarif-output-file (format "%s/report.sarif" directory)]
(when sarif-report
(->> sarif-report json/write-str (spit sarif-output-file))
(println "Sarif report can be find in" sarif-output-file))))