# HG changeset patch # User alys # Date 2018-09-26 23:56:14 # Node ID b40528ad18206966e43f889d7d63b51b89c757b4 # Parent f0a43226674ab90bee75ef5b19459e20808692b6 Various improvements and refactorings. diff --git a/project.clj b/project.clj --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject project-checkup "0.1.0-SNAPSHOT" +(defproject project-checkup "0.1.1-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" diff --git a/src/project_checkup/core.clj b/src/project_checkup/core.clj --- a/src/project_checkup/core.clj +++ b/src/project_checkup/core.clj @@ -9,17 +9,28 @@ (defn gather-project-info "Creates a dictionary of project information" [] - (let [files (set (map str (file-seq (clojure.java.io/file "."))))] + (let [all-files (set (map str (file-seq (clojure.java.io/file ".")))) + ; files (string/split (:out (shell/sh "hg" "st" "-m" "-a" "-r" "-d" "-c" "-n" )) #"\n") + files (map #(clojure.string/replace % #"./(.*)" "$1") all-files ) + + ] {:files files :extensions (frequencies (map get-extension files )) :path (:out (shell/sh "pwd")) - :untracked-files (string/split (:out (shell/sh "hg" "st" "-u" "-n")) #"\n") })) + :untracked-files (string/split (:out (shell/sh "hg" "st" "-u" "-n")) #"\n") + :readme (if-let [filename (some #{"README.md" "README.txt" "README.mkd"} files)] (slurp filename) "") + }) + + ) (defn color [color string] (let [color-sequence (case color :green "\u001B[32m" :yellow "\u001B[33m" :blue "\u001B[34m" + :red "\u001B[31m" + :cyan "\u001B[36m" + :magenta "\u001B[35m" ) reset "\u001B[m" ] (str color-sequence string reset)) ) @@ -27,19 +38,25 @@ (defn check-vcs [project] (let [{files :files } project] - (boolean (some #{"./.git" "./.hg"} files)) )) + (boolean (some #{".git" ".hg"} files)) )) (defn check-readme [project] (let [{files :files } project] - (boolean (some #{"./README.md" "./README.txt" "./README.mkd"} files)) )) + (boolean (some #{"README.md" "README.txt" "README.mkd"} files)) )) (defn check-untracked [project] (let [{untracked :untracked-files } project] (= (count untracked) 0)) ) (defn check-taskpaper [project] - (let [{extensions :extensions } project] - (>= (get ".taskpaper" extensions 0) 1) )) + (let [{extensions :extensions files :files } project] + (or (>= (get ".taskpaper" extensions 0) 1) + (some #{"TODO" "TODO.txt" } files)))) + +(defn check-readme-placeholders [project] + (= (count (re-find #"(FIXME|TODO)" (:readme project) )) 0) + ) + (def checks [{:name "Has VCS" :description "" @@ -64,7 +81,13 @@ :function check-readme :description "Readme exists" :level :suggestion - :follow-up "Add a README." } ]) + :follow-up "Add a README." } + {:name "README has no placeholders" + :function check-readme-placeholders + :description "No placeholders in README" + :level :error + :follow-up "Address placeholders or convert them to tasks." + } ]) (defn perform-check [check project] (let [{check-name :name function :function follow-up :follow-up @@ -83,8 +106,17 @@ (defn -main - "I don't do a whole lot ... yet." + "Run checks." [& args] +(try + (doseq [check checks] (println (:output (perform-check check (gather-project-info) )))) - (shutdown-agents) ) + + (catch Exception ex + (.printStackTrace ex) + (str "caught exception: " (.getMessage ex))) + (finally (shutdown-agents) ) + ) + + )