aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-09-15 17:43:14 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-09-15 17:44:03 -0700
commitcb5f939ab27b2c2ef2e1d4ac6fe16c5ba6332f39 (patch)
tree546ce64c755ad04b916f00c8ca398af8739d206c /doc
parentaa38b05575dab57b813ddcd14780f65ff20a6d49 (diff)
feat: utility function to extend the built-in formatter args (#50)
Diffstat (limited to 'doc')
-rw-r--r--doc/recipes.md28
1 files changed, 28 insertions, 0 deletions
diff --git a/doc/recipes.md b/doc/recipes.md
index 8dae5fc..c235475 100644
--- a/doc/recipes.md
+++ b/doc/recipes.md
@@ -7,6 +7,7 @@
- [Autoformat with extra features](#autoformat-with-extra-features)
- [Command to toggle format-on-save](#command-to-toggle-format-on-save)
- [Automatically run slow formatters async](#automatically-run-slow-formatters-async)
+- [Add extra arguments to a formatter command](#add-extra-arguments-to-a-formatter-command)
<!-- /TOC -->
@@ -164,3 +165,30 @@ require("conform").setup({
end,
})
```
+
+## Add extra arguments to a formatter command
+
+The official recommended way to change the arguments of a formatter is to just copy the default
+values and mutate them however you like. For example:
+
+```lua
+require("conform.formatters.shfmt").args = { "-i", "4", "-filename", "$FILENAME" }
+```
+
+But if you really want to _add_ arguments instead of replacing them, there is a utility function to
+make this easier:
+
+```lua
+local util = require("conform.util")
+local prettier = require("conform.formatters.prettier")
+require("conform").formatters.prettier = vim.tbl_deep_extend("force", prettier, {
+ args = util.extend_args(prettier.args, { "--tab", "--indent", "2" }),
+ range_args = util.extend_args(prettier.range_args, { "--tab", "--indent", "2" }),
+})
+
+-- Pass append=true to append the extra arguments to the end
+local deno_fmt = require("conform.formatters.deno_fmt")
+require("conform").formatters.deno_fmt = vim.tbl_deep_extend('force', deno_fmt, {
+ args = util.extend_args(deno_fmt.args, { "--use-tabs" }, { append = true })
+})
+```