File tree Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 37
37
(println banner)
38
38
(System/exit 1 ))
39
39
40
+ (defn info [opts msg]
41
+ (println " [info] " msg))
42
+
40
43
; TODO extract part of this method to cli
41
44
(defn -main
42
45
" What I do"
51
54
(when (:linter opts)
52
55
(when (or (:interactive opts) (:query opts))
53
56
(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))
55
62
(System/exit 0 ))
56
63
(when (:interactive opts)
57
64
(do
Original file line number Diff line number Diff line change 2
2
; Linter
3
3
; ============================================
4
4
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))))
You can’t perform that action at this time.
0 commit comments