|
115 | 115 | (and file diff) (assoc-in [:incorrect path] diff)
|
116 | 116 | (and file exception) (assoc-in [:error path] exception))))
|
117 | 117 |
|
118 |
| -(defmulti check-report-file (fn [& args] (first args))) |
119 |
| -(defmulti check-report-final (fn [& args] (first args))) |
| 118 | +(defmulti report-cli (fn [event & _] event)) |
| 119 | +(defmulti report-lib (fn [event & _] event)) |
120 | 120 |
|
121 |
| -(defmethod check-report-file :cli |
122 |
| - [_ options status] |
123 |
| - (print-file-status options status) |
124 |
| - (:counts status)) |
| 121 | +(defmethod report-cli :check/initial |
| 122 | + [_ _ _] |
| 123 | + nil) |
125 | 124 |
|
126 |
| -(defmethod check-report-final :cli |
127 |
| - [_ results] |
128 |
| - (let [counts (reduce merge-counts results)] |
| 125 | +(defmethod report-cli :check/file |
| 126 | + [_ context data] |
| 127 | + (print-file-status context data) |
| 128 | + (:counts data)) |
| 129 | + |
| 130 | +(defmethod report-cli :check/summary |
| 131 | + [_ summary _] |
| 132 | + (let [counts (reduce merge-counts summary)] |
129 | 133 | (print-final-count counts)
|
130 | 134 | (exit counts)))
|
131 | 135 |
|
132 |
| -(defmethod check-report-file :lib |
133 |
| - [_ _ status] |
134 |
| - status) |
| 136 | +(defmethod report-lib :check/initial |
| 137 | + [_ _ _] |
| 138 | + nil) |
| 139 | + |
| 140 | +(defmethod report-lib :check/file |
| 141 | + [_ _ data] |
| 142 | + data) |
135 | 143 |
|
136 |
| -(defmethod check-report-final :lib |
137 |
| - [_ results] |
138 |
| - (reduce merge-statuses {} results)) |
| 144 | +(defmethod report-lib :check/summary |
| 145 | + [_ context _] |
| 146 | + (reduce merge-statuses {} context)) |
139 | 147 |
|
140 | 148 | (defn check-no-config
|
141 | 149 | "The same as `check`, but ignores dotfile configuration."
|
142 |
| - [{:keys [parallel? paths report/file report/final] :as options}] |
143 |
| - (let [map* (if parallel? pmap map) |
144 |
| - report-file (partial file options) |
145 |
| - results (->> paths |
146 |
| - (mapcat (partial find-files options)) |
147 |
| - (map* (partial check-one options)) |
148 |
| - (map report-file))] |
149 |
| - (final results))) |
| 150 | + [{:keys [parallel? paths report] :as options}] |
| 151 | + (report :check/initial options nil) |
| 152 | + (let [map* (if parallel? pmap map) |
| 153 | + summary (->> paths |
| 154 | + (mapcat (partial find-files options)) |
| 155 | + (map* (partial check-one options)) |
| 156 | + (reduce #(report :check/file %1 %2) options))] |
| 157 | + (report :check/summary summary nil))) |
150 | 158 |
|
151 | 159 | (defn check
|
152 | 160 | "Checks that the Clojure paths specified by the :paths option are
|
153 | 161 | correctly formatted."
|
154 | 162 | [options]
|
155 |
| - (let [opts (merge {:report/file #(check-report-file :cli %1 %2) |
156 |
| - :report/final #(check-report-final :cli %)} |
| 163 | + (let [opts (merge {:report report-cli} |
157 | 164 | (config/load-config) options)]
|
158 | 165 | (check-no-config opts)))
|
159 | 166 |
|
160 | 167 | (defn check-paths
|
161 | 168 | "Runs a check on the provided paths and returns a map detailing the results."
|
162 | 169 | [paths & [options]]
|
163 |
| - (let [opts (merge {:report/file #(check-report-file :lib %1 %2) |
164 |
| - :report/final #(check-report-final :lib %)} |
| 170 | + (let [opts (merge {:report report-lib} |
165 | 171 | (config/load-config) options
|
166 | 172 | {:paths paths})]
|
167 | 173 | (check-no-config opts)))
|
|
182 | 188 | (defn- recursively-find-files [{:keys [paths] :as options}]
|
183 | 189 | (mapcat #(find-files options %) (set paths)))
|
184 | 190 |
|
185 |
| -(defmulti fix-report (fn [& args] (first args))) |
| 191 | +(defmethod report-cli :fix/initial |
| 192 | + [_ _ _] |
| 193 | + nil) |
| 194 | + |
| 195 | +(defmethod report-cli :fix/file |
| 196 | + [_ context data] |
| 197 | + (print-file-status context data)) |
| 198 | + |
| 199 | +(defmethod report-cli :fix/summary |
| 200 | + [_ _ _] |
| 201 | + nil) |
| 202 | + |
| 203 | +(defmethod report-lib :fix/initial |
| 204 | + [_ _ _] |
| 205 | + nil) |
186 | 206 |
|
187 |
| -(defmethod fix-report :cli |
188 |
| - [_ options status] |
189 |
| - (print-file-status options status)) |
| 207 | +(defmethod report-lib :fix/file |
| 208 | + [_ _ data] |
| 209 | + data) |
190 | 210 |
|
191 |
| -(defmethod fix-report :lib |
192 |
| - [_ _ status] |
193 |
| - status) |
| 211 | +(defmethod report-lib :fix/summary |
| 212 | + [_ summary _] |
| 213 | + summary) |
194 | 214 |
|
195 | 215 | (defn fix-no-config
|
196 | 216 | "The same as `fix`, but ignores dotfile configuration."
|
197 |
| - [{:keys [parallel? report/fix] :as options}] |
198 |
| - (let [files (recursively-find-files options) |
199 |
| - map* (if parallel? pmap map) |
200 |
| - fix-report (partial fix options)] |
201 |
| - (->> files |
202 |
| - (map* (partial fix-one options)) |
203 |
| - (map fix-report) |
204 |
| - dorun))) |
| 217 | + [{:keys [parallel? report] :as options}] |
| 218 | + (report :fix/initial options nil) |
| 219 | + (let [files (recursively-find-files options) |
| 220 | + map* (if parallel? pmap map) |
| 221 | + summary (->> files |
| 222 | + (map* (partial fix-one options)) |
| 223 | + (reduce #(report :fix/file %1 %2) options))] |
| 224 | + (report :fix/summary summary nil))) |
205 | 225 |
|
206 | 226 | (defn fix
|
207 | 227 | "Fixes the formatting for all files specified by the :paths option."
|
208 | 228 | [options]
|
209 |
| - (let [opts (merge {:report/fix #(fix-report :cli %1 %2)} |
| 229 | + (let [opts (merge {:report report-cli} |
210 | 230 | (config/load-config) options)]
|
211 | 231 | (fix-no-config opts)))
|
212 | 232 |
|
213 | 233 | (defn fix-paths
|
214 | 234 | "Fixes code in the provided paths."
|
215 | 235 | [paths & [options]]
|
216 |
| - (let [opts (merge {:report/fix #(fix-report :lib %1 %2)} |
| 236 | + (let [opts (merge {:report report-lib} |
217 | 237 | (config/load-config) options
|
218 | 238 | {:paths paths})]
|
219 | 239 | (fix-no-config opts)))
|
0 commit comments