Skip to content

Commit

Permalink
First implementation of the linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Aug 2, 2014
1 parent 8c4c387 commit 0b1c320
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/app/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
(println banner)
(System/exit 1))

(defn info [opts msg]
(println " [info] " msg))

; TODO extract part of this method to cli
(defn -main
"What I do"
Expand All @@ -51,7 +54,11 @@
(when (:linter opts)
(when (or (:interactive opts) (:query opts))
(usageError banner opts "Linter, interactive and query mode are self exclusive"))
(linter)
(when (not (:dir opts))
(info opts "Linter, no directory indicated. Using current directory")
(linter ".")
(System/exit 0))
(linter (:dir opts))
(System/exit 0))
(when (:interactive opts)
(do
Expand Down
32 changes: 30 additions & 2 deletions src/app/linter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,33 @@
; Linter
; ============================================

(defn linter []
(println "Linter running"))
; For a lint report we want to know:
; * which element is affected
; * have a message describing the warning/error
; The element is always the first returned by the operation

(defrecord Check [operation params message])

(def checks
[(Check. classesWithManyConstructorsOp {:threshold 4} "This class has too many constructors (#1#). Considers the Builder pattern")])

(defn replaceParamsInMessage [message result]
(clojure.string/replace message "#1#" (toString (nth result 1))))

(defn printCheckResult [result message]
(println (toString (nth result 0)) ":" (replaceParamsInMessage message result)))

(defn executeCheck [check cus]
(let [operation (.operation check)
params (.params check)
threshold (:threshold params)
results ((.query operation) {:cus cus :threshold threshold})
message (.message check)]
(doseq [r results]
(printCheckResult r message))))

(defn linter [dir]
(let [cus (cus dir)]
(println "Loaded" (.size cus) "files")
(doseq [c checks]
(executeCheck c cus))))

0 comments on commit 0b1c320

Please sign in to comment.