Only process when there is output to return (#116)

* fix: only process when there is output to return

scalafmt only returns stdout when there are errors, this could also help
in other cases where a formatter returns incorrectly.

Ideally, this would also be improved by basic error checking heuristics
to work out if we need to update the buffer.

* Update changelog

Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
This commit is contained in:
Ellis Kenyő 2022-08-21 23:21:21 +01:00 committed by GitHub
parent ebb62564a8
commit 04366a90df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View file

@ -12,6 +12,10 @@ The format is based on [Keep a Changelog].
fixes issues with formatters that behave differently when receiving
input on stdin versus being run on a tty ([#119]).
### Bugs fixed
* When a formatter has a bug and fails to return anything on stdout
(e.g. scalafmt), do not erase the buffer ([#116]).
### Formatters
* [bean-format](https://github.com/beancount/beancount) for Beancount
([#101]).
@ -21,6 +25,7 @@ The format is based on [Keep a Changelog].
[#105]: https://github.com/radian-software/apheleia/pull/105
[#109]: https://github.com/radian-software/apheleia/issues/109
[#110]: https://github.com/radian-software/apheleia/pull/110
[#116]: https://github.com/radian-software/apheleia/pull/116
[#119]: https://github.com/radian-software/apheleia/pull/119
## 3.0 (released 2022-06-01)

View file

@ -1034,13 +1034,14 @@ function: %s" command)))
buffer
remote
(lambda (stdout)
(if (cdr formatters)
;; Forward current stdout to remaining formatters, passing along
;; the current callback and using the current formatters output
;; as stdin.
(apheleia--run-formatters
(cdr formatters) buffer remote callback stdout)
(funcall callback stdout)))
(unless (string-empty-p (with-current-buffer stdout (buffer-string)))
(if (cdr formatters)
;; Forward current stdout to remaining formatters, passing along
;; the current callback and using the current formatters output
;; as stdin.
(apheleia--run-formatters
(cdr formatters) buffer remote callback stdout)
(funcall callback stdout))))
stdin
(car formatters))))