Skip to content

Commit 0b1c320

Browse files
committed
First implementation of the linter
1 parent 8c4c387 commit 0b1c320

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/app/core.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
(println banner)
3838
(System/exit 1))
3939

40+
(defn info [opts msg]
41+
(println " [info] " msg))
42+
4043
; TODO extract part of this method to cli
4144
(defn -main
4245
"What I do"
@@ -51,7 +54,11 @@
5154
(when (:linter opts)
5255
(when (or (:interactive opts) (:query opts))
5356
(usageError banner opts "Linter, interactive and query mode are self exclusive"))
54-
(linter)
57+
(when (not (:dir opts))
58+
(info opts "Linter, no directory indicated. Using current directory")
59+
(linter ".")
60+
(System/exit 0))
61+
(linter (:dir opts))
5562
(System/exit 0))
5663
(when (:interactive opts)
5764
(do

src/app/linter.clj

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,33 @@
22
; Linter
33
; ============================================
44

5-
(defn linter []
6-
(println "Linter running"))
5+
; For a lint report we want to know:
6+
; * which element is affected
7+
; * have a message describing the warning/error
8+
; The element is always the first returned by the operation
9+
10+
(defrecord Check [operation params message])
11+
12+
(def checks
13+
[(Check. classesWithManyConstructorsOp {:threshold 4} "This class has too many constructors (#1#). Considers the Builder pattern")])
14+
15+
(defn replaceParamsInMessage [message result]
16+
(clojure.string/replace message "#1#" (toString (nth result 1))))
17+
18+
(defn printCheckResult [result message]
19+
(println (toString (nth result 0)) ":" (replaceParamsInMessage message result)))
20+
21+
(defn executeCheck [check cus]
22+
(let [operation (.operation check)
23+
params (.params check)
24+
threshold (:threshold params)
25+
results ((.query operation) {:cus cus :threshold threshold})
26+
message (.message check)]
27+
(doseq [r results]
28+
(printCheckResult r message))))
29+
30+
(defn linter [dir]
31+
(let [cus (cus dir)]
32+
(println "Loaded" (.size cus) "files")
33+
(doseq [c checks]
34+
(executeCheck c cus))))

0 commit comments

Comments
 (0)