Fix apheleia--check-formatter-configured for unrelated formatters

This commit is contained in:
Adam Goldsmith 2024-05-31 14:03:33 -04:00
parent 1ea372e645
commit 3091331107

View File

@ -1094,18 +1094,18 @@
(defun apheleia--check-formatter-configured () (defun apheleia--check-formatter-configured ()
"Disable apheleia when a formatter's configuration does not exist" "Disable apheleia when a formatter's configuration does not exist"
(not (let ((formatters (apheleia--get-formatters))) (let ((formatters (apheleia--get-formatters)))
(cond (cond
((member 'ruff formatters) (apheleia--pyproject-contains-section "tool.ruff")) ((member 'ruff formatters) (not (apheleia--pyproject-contains-section "tool.ruff")))
((member 'black formatters) (apheleia--pyproject-contains-section "tool.black")) ((member 'black formatters) (not (apheleia--pyproject-contains-section "tool.black")))
((member 'djlint formatters) (apheleia--pyproject-contains-section "tool.djlint")) ((member 'djlint formatters) (not (apheleia--pyproject-contains-section "tool.djlint")))
((seq-some (lambda (f) (string-prefix-p "prettier" (symbol-name f))) formatters) ((seq-some (lambda (f) (string-prefix-p "prettier" (symbol-name f))) formatters)
(when (= 0 (call-process "prettier" nil nil nil "--find-config-path" (buffer-file-name))) (not (when (= 0 (call-process "prettier" nil nil nil "--find-config-path" (buffer-file-name)))
(let* ((config-file (shell-command-to-string (concat "prettier --find-config-path " (buffer-file-name)))) (let* ((config-file (shell-command-to-string (concat "prettier --find-config-path " (buffer-file-name))))
(default-directory (file-name-directory (expand-file-name config-file))) (default-directory (file-name-directory (expand-file-name config-file)))
(file-info (shell-command-to-string (concat "prettier --file-info " (buffer-file-name)))) (file-info (shell-command-to-string (concat "prettier --file-info " (buffer-file-name))))
(file-ignored (gethash "ignored" (json-parse-string file-info)))) (file-ignored (gethash "ignored" (json-parse-string file-info))))
(eq file-ignored :false)))))))) (eq file-ignored :false)))))))))
(add-to-list 'apheleia-inhibit-functions 'apheleia--check-formatter-configured) (add-to-list 'apheleia-inhibit-functions 'apheleia--check-formatter-configured)