aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-08-28 18:27:46 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-08-28 18:27:46 -0700
commitd508ae8f46b5b41e2806b412311719a941167c1a (patch)
treee4d9244fd20cbe0dcda9ce3a4e524fca5ba3d6fc /tests
parente09ef2a6a3d0f987963bfef771b5af060183f849 (diff)
refactor!: remove ability for formatter list to disable autoformat
I realized that there are so, so many possible features people would want when configuring the autoformatter, but it's better to just code it up yourself rather than try to create a config language that can describe all possible logic. Also adding new docs to provide examples of more advanced autoformat logic.
Diffstat (limited to 'tests')
-rw-r--r--tests/autoformat_doc.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/autoformat_doc.lua b/tests/autoformat_doc.lua
new file mode 100644
index 0000000..8c0761e
--- /dev/null
+++ b/tests/autoformat_doc.lua
@@ -0,0 +1,20 @@
+vim.api.nvim_create_autocmd("BufWritePre", {
+ pattern = "*",
+ callback = function(args)
+ -- Disable autoformat on certain filetypes
+ local ignore_filetypes = { "sql", "java" }
+ if vim.tbl_contains(ignore_filetypes, vim.bo[args.buf].filetype) then
+ return
+ end
+ -- Disable with a global or buffer-local variable
+ if vim.g.disable_autoformat or vim.b[args.buf].disable_autoformat then
+ return
+ end
+ -- Disable autoformat for files in a certain path
+ local bufname = vim.api.nvim_buf_get_name(args.buf)
+ if bufname:match("/node_modules/") then
+ return
+ end
+ require("conform").format({ timeout_ms = 500, lsp_fallback = true, buf = args.buf })
+ end,
+})