Description:
Small style fixes.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -2,31 +2,30 | |||||
|
2 | (ns project-checkup.core |
|
2 | (ns project-checkup.core |
|
3 | (:gen-class) |
|
3 | (:gen-class) |
|
4 | (:require [clojure.java.shell :as shell] |
|
4 | (:require [clojure.java.shell :as shell] |
|
5 |
[clojure.string :as string])) |
|
5 | [clojure.string :as string])) |
|
6 |
|
6 | ||
|
7 |
(defn get-extension [path] |
|
7 | (defn get-extension [path] |
|
8 | "Extracts the extension of a path. |
|
8 | "Extracts the extension of a path. |
|
9 |
Returns the extension with the period, e.g., '.txt' because that's the format |
|
9 | Returns the extension with the period, e.g., '.txt' because that's the format |
|
10 | people are used to seeing extensions in." |
|
10 | people are used to seeing extensions in." |
|
11 | (re-find #"\.[a-zA-Z0-9]+$" path)) |
|
11 | (re-find #"\.[a-zA-Z0-9]+$" path)) |
|
12 |
|
12 | ||
|
13 |
(defn gather-untracked |
|
13 | (defn gather-untracked |
|
14 | [vcs-systems] |
|
14 | [vcs-systems] |
|
15 | "Gather untracked files in Git or Mercurial." |
|
15 | "Gather untracked files in Git or Mercurial." |
|
16 | (reduce into [ |
|
16 | (reduce into [ |
|
17 | (if (contains? vcs-systems ".hg") |
|
17 | (if (contains? vcs-systems ".hg") |
|
18 | (string/split (:out (shell/sh "chg" "st" "-u" "-n")) #"\n")) |
|
18 | (string/split (:out (shell/sh "chg" "st" "-u" "-n")) #"\n")) |
|
19 | (if (contains? vcs-systems ".git") |
|
19 | (if (contains? vcs-systems ".git") |
|
20 |
(string/split (:out (shell/sh "git" "ls-files" "--others" |
|
20 | (string/split (:out (shell/sh "git" "ls-files" "--others" |
|
21 | "--exclude-standard")) #"\n"))] |
|
21 | "--exclude-standard")) #"\n"))] |
|
22 |
|
|||
|
23 | ) |
|
22 | ) |
|
24 | ) |
|
23 | ) |
|
25 |
|
24 | ||
|
26 | (defn gather-project-info |
|
25 | (defn gather-project-info |
|
27 | "Creates a dictionary of project information." |
|
26 | "Creates a dictionary of project information." |
|
28 | [] |
|
27 | [] |
|
29 |
(let [all-files (map str (file-seq (clojure.java.io/file "."))) |
|
28 | (let [all-files (map str (file-seq (clojure.java.io/file "."))) |
|
30 | ; files (string/split (:out (shell/sh "hg" "st" "-m" "-a" "-r" "-d" "-c" "-n" )) #"\n") |
|
29 | ; files (string/split (:out (shell/sh "hg" "st" "-m" "-a" "-r" "-d" "-c" "-n" )) #"\n") |
|
31 |
|
30 | ||
|
32 | files (map #(clojure.string/replace % #"./(.*)" "$1") all-files ) |
|
31 | files (map #(clojure.string/replace % #"./(.*)" "$1") all-files ) |
@@ -34,11 +33,11 | |||||
|
34 | ;note that using some here means that if both are present, hg is |
|
33 | ;note that using some here means that if both are present, hg is |
|
35 | ;ignored: |
|
34 | ;ignored: |
|
36 | vcs-systems (set (vector (some #{".git" ".hg"} files))) ] |
|
35 | vcs-systems (set (vector (some #{".git" ".hg"} files))) ] |
|
37 |
{:files files |
|
36 | {:files files |
|
38 | :extensions (frequencies (map get-extension files )) |
|
37 | :extensions (frequencies (map get-extension files )) |
|
39 | :path (System/getProperty "user.dir") |
|
38 | :path (System/getProperty "user.dir") |
|
40 |
:untracked-files (gather-untracked vcs-systems) |
|
39 | :untracked-files (gather-untracked vcs-systems) |
|
41 |
:readme (if-let [filename (some #{"README.md" "README.txt" "README.mkd"} files)] (slurp filename) "") |
|
40 | :readme (if-let [filename (some #{"README.md" "README.txt" "README.mkd"} files)] (slurp filename) "") |
|
42 | }) ) |
|
41 | }) ) |
|
43 |
|
42 | ||
|
44 | (defn color [color string] |
|
43 | (defn color [color string] |
@@ -69,7 +68,7 | |||||
|
69 | (defn check-taskpaper [project] |
|
68 | (defn check-taskpaper [project] |
|
70 | (let [{extensions :extensions files :files } project] |
|
69 | (let [{extensions :extensions files :files } project] |
|
71 | (or (>= (get ".taskpaper" extensions 0) 1) |
|
70 | (or (>= (get ".taskpaper" extensions 0) 1) |
|
72 |
(some #{"TODO" "TODO.txt" } files)))) |
|
71 | (some #{"TODO" "TODO.txt" } files)))) |
|
73 |
|
72 | ||
|
74 | (defn check-readme-placeholders [project] |
|
73 | (defn check-readme-placeholders [project] |
|
75 | (= (count (re-find #"(FIXME|TODO)" (:readme project) )) 0)) |
|
74 | (= (count (re-find #"(FIXME|TODO)" (:readme project) )) 0)) |
@@ -78,7 +77,7 | |||||
|
78 | (def checks [{:name "Project is checked into revision control" |
|
77 | (def checks [{:name "Project is checked into revision control" |
|
79 | :description "" |
|
78 | :description "" |
|
80 | :function check-vcs |
|
79 | :function check-vcs |
|
81 |
:level :error |
|
80 | :level :error |
|
82 | :follow-up "Initialize a repository." } |
|
81 | :follow-up "Initialize a repository." } |
|
83 | {:name "Always True" |
|
82 | {:name "Always True" |
|
84 | :function #(or true %) |
|
83 | :function #(or true %) |
@@ -93,7 +92,7 | |||||
|
93 | :function check-taskpaper |
|
92 | :function check-taskpaper |
|
94 | :description "" |
|
93 | :description "" |
|
95 | :level :suggestion |
|
94 | :level :suggestion |
|
96 |
:follow-up "Add a todo file using Taskpaper." } |
|
95 | :follow-up "Add a todo file using Taskpaper." } |
|
97 | {:name "Has README" |
|
96 | {:name "Has README" |
|
98 | :function check-readme |
|
97 | :function check-readme |
|
99 | :description "Readme exists" |
|
98 | :description "Readme exists" |
@@ -114,33 +113,27 | |||||
|
114 | :suggestion :blue |
|
113 | :suggestion :blue |
|
115 | :warning :yellow |
|
114 | :warning :yellow |
|
116 | :error :red |
|
115 | :error :red |
|
117 |
:red) |
|
116 | :red) |
|
118 | prefix (case level |
|
117 | prefix (case level |
|
119 | :suggestion "Suggested follow-up" |
|
118 | :suggestion "Suggested follow-up" |
|
120 | :warning "Recommended follow-up" |
|
119 | :warning "Recommended follow-up" |
|
121 | :error "Required follow-up" |
|
120 | :error "Required follow-up" |
|
122 | "Follow-up" |
|
121 | "Follow-up" )] |
|
123 |
|
|||
|
124 | ) |
|
||
|
125 | ] |
|
||
|
126 | {:name check-name |
|
122 | {:name check-name |
|
127 | :result result |
|
123 | :result result |
|
128 |
:output (if result |
|
124 | :output (if result |
|
129 |
(color :green (str "✔" check-name "…passed!")) |
|
125 | (color :green (str "✔" check-name "…passed!")) |
|
130 | (str (color false-color (str "❌" check-name "…failed!")) "\n\t" prefix " Follow up: " follow-up) |
|
126 | (str (color false-color (str "❌" check-name "…failed!")) "\n\t" prefix " Follow up: " follow-up))})) |
|
131 | ; (str check-name (color false-color " failed! ") "\n\tFollow up: " follow-up) |
|
||
|
132 |
|
|||
|
133 | )})) |
|
||
|
134 |
|
127 | ||
|
135 |
|
128 | ||
|
136 | (defn -main |
|
129 | (defn -main |
|
137 | "Run checks." |
|
130 | "Run checks." |
|
138 | [& args] |
|
131 | [& args] |
|
139 |
(try |
|
132 | (try |
|
140 |
(let [project-info (gather-project-info)] |
|
133 | (let [project-info (gather-project-info)] |
|
141 | (doseq [check checks] |
|
134 | (doseq [check checks] |
|
142 | (println (:output (perform-check check project-info ))))) |
|
135 | (println (:output (perform-check check project-info ))))) |
|
143 |
(catch Exception ex |
|
136 | (catch Exception ex |
|
144 | (.printStackTrace ex) |
|
137 | (.printStackTrace ex) |
|
145 | (str "caught exception: " (.getMessage ex))) |
|
138 | (str "caught exception: " (.getMessage ex))) |
|
146 |
(finally (shutdown-agents) )) ) |
|
139 | (finally (shutdown-agents) )) ) |
You need to be logged in to leave comments.
Login now