fix(format): prettier: don't override prettier indent config

Apheleia's default config for prettier adds --use-tabs/--tab-width to
force prettier to match Emacs' indent settings, which is fine until a
prettier config file tries to overwrite it and is ignored. As a
compromise (and stopgap solution), I omit these flags if any prettier
settings are set in the current project.

Fix: #7998
This commit is contained in:
Henrik Lissner 2024-08-18 03:59:18 -04:00
parent e82dab3257
commit c0a1b9efc9
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -76,4 +76,30 @@ This is controlled by `+format-on-save-disabled-modes'."
;; `lsp-mode' or `eglot') that is capable of formatting. Without +lsp, users
;; must manually set `+format-with' to `lsp' to use it, or activate
;; `+format-with-lsp-mode' in the appropriate modes.
(add-to-list 'apheleia-formatters '(lsp . +format-lsp-buffer)))
(add-to-list 'apheleia-formatters '(lsp . +format-lsp-buffer))
;; Apheleia's default config for prettier passes an explicit --tab-width N to
;; all prettier formatters, respecting your indent settings in Emacs, but
;; overriding any indent settings in your prettier config files. This changes
;; it to omit indent switches if any configuration for prettier is present in
;; the current project.
(dolist (formatter '(prettier prettier-css prettier-html prettier-javascript
prettier-json prettier-scss prettier-svelte
prettier-typescript prettier-yaml))
(setf (alist-get formatter apheleia-formatters)
(append (delete '(apheleia-formatters-js-indent "--use-tabs" "--tab-width")
(alist-get formatter apheleia-formatters))
'(unless (or (cl-loop for file
in '(".prettierrc"
".prettierrc.json"
".prettierrc.yml"
".prettierrc.yaml"
".prettierrc.json5"
".prettierrc.js" "prettier.config.js"
".prettierrc.mjs" "prettier.config.mjs"
".prettierrc.cjs" "prettier.config.cjs"
".prettierrc.toml")
if (locate-dominating-file default-directory file)
return t)
(assq 'prettier (+javascript-npm-conf)))
(apheleia-formatters-indent "--use-tabs" "--tab-width"))))))