diff options
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | apheleia-formatters.el | 28 | ||||
| -rwxr-xr-x | scripts/formatters/apheleia-npx | 7 |
3 files changed, 32 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 09e3bd4..3cda2e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog]. ### Bugs fixed * `shfmt` did not work with `apheleia-formatters-respect-indent-level` +* `apheleia-npx` did return an error when formatter was missing [#380]: https://github.com/radian-software/apheleia/pull/380 [#382]: https://github.com/radian-software/apheleia/pull/382 diff --git a/apheleia-formatters.el b/apheleia-formatters.el index 9bc39f8..53e7387 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -467,6 +467,23 @@ in the buffer." 'mhtml-submode) #'mhtml-mode)) +;; Expected exit code and stderr output for script when real +;; formatter is not available +(defvar apheleia-script--formatter-not-available + '(:exit-code 100 :stderr "formatter_not_available")) + +(defun apheleia-script--formatter-not-available-p (ctx stderr) + "Check if script reports that no formatter has been found. +CTX is a formatter process context. +STDERR is the stderr output of process." + (and (eq (apheleia-formatter--exit-status ctx) + (plist-get apheleia-script--formatter-not-available :exit-code)) + (string= stderr + (concat + (apheleia-formatter--arg1 ctx) ":" + (plist-get apheleia-script--formatter-not-available + :stderr))))) + ;;;###autoload (defcustom apheleia-mode-predicates '(apheleia-mhtml-mode-predicate) "List of predicates that check for sneaky major modes. @@ -747,9 +764,14 @@ its exit status is 0." proc-exit-status) (let ((exit-ok (and (not proc-interrupted) - (funcall - (or exit-status #'zerop) - (apheleia-formatter--exit-status ctx))))) + (or + (funcall + (or exit-status #'zerop) + (apheleia-formatter--exit-status ctx)) + (apheleia-script--formatter-not-available-p + ctx + (with-current-buffer stderr + (string-trim (buffer-string)))))))) ;; Append standard-error from current formatter ;; to log buffer when ;; `apheleia-log-only-errors' is nil or the diff --git a/scripts/formatters/apheleia-npx b/scripts/formatters/apheleia-npx index a540f9b..72cafb2 100755 --- a/scripts/formatters/apheleia-npx +++ b/scripts/formatters/apheleia-npx @@ -70,4 +70,9 @@ if [[ -d $dir ]]; then fi # Fall back to executing the command if it's installed and on the user's $PATH -exec "$@" +if command -v "$1" >/dev/null; then + exec "$@" +fi + +echo "apheleia-npx:formatter_not_available" >&2 +exit 100 |
