Skip to content

Commit

Permalink
Ensure cljfmt fix always outputs for STDOUT
Browse files Browse the repository at this point in the history
Fixes #305.
  • Loading branch information
weavejester committed May 29, 2023
1 parent e04ecfb commit e9b55e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions cljfmt/src/cljfmt/io.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

(defprotocol FileEntity
(read-file [f])
(write-file [f s])
(update-file [f s changed?])
(exists? [f])
(directory? [f])
(list-files [f])
Expand All @@ -12,7 +12,7 @@
(extend-protocol FileEntity
File
(read-file [f] (slurp f))
(write-file [f s] (spit f s))
(update-file [f s changed?] (when changed? (spit f s)))
(exists? [f] (.exists f))
(directory? [f] (.isDirectory f))
(list-files [f] (file-seq f))
Expand All @@ -24,7 +24,7 @@
(deftype StdIO [in out]
FileEntity
(read-file [_] (slurp in))
(write-file [_ s] (binding [*out* out] (print s)) (flush))
(update-file [_ s _] (binding [*out* out] (print s)) (flush))
(exists? [_] true)
(directory? [_] false)
(list-files [_] nil)
Expand Down
9 changes: 5 additions & 4 deletions cljfmt/src/cljfmt/tool.clj
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@
(trace "Processing file:" (project-path options file))
(let [original (io/read-file file)]
(try
(let [revised (reformat-string options original)]
(if (not= original revised)
(do (io/write-file file revised)
{:file file :reformatted true})
(let [revised (reformat-string options original)
changed? (not= original revised)]
(io/update-file file revised changed?)
(if changed?
{:file file :reformatted true}
{:file file}))
(catch Exception e
{:file file :exception e}))))
Expand Down

0 comments on commit e9b55e1

Please sign in to comment.