-
Notifications
You must be signed in to change notification settings - Fork 0
/
conform.lua
78 lines (73 loc) · 2.76 KB
/
conform.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- https://github.com/stevearc/conform.nvim
-- https://github.com/Allaman/nvim/blob/main/lua/config/defaults/conform.lua
-- alternative https://github.com/nvimtools/none-ls.nvim -- wraps linters and formatters and creates LSP out of them
return {
"stevearc/conform.nvim",
event = { "BufReadPre", "BufNewFile", "InsertLeave" },
config = function()
local conform = require("conform")
conform.setup({
-- Use `:ConformInfo` to see the location of the log file.
-- log_level = vim.log.levels.TRACE,
format_on_save = {
-- These options will be passed to conform.format()
lsp_format = "fallback",
async = false,
timeout_ms = 1000,
},
formatters_by_ft = {
javascript = { "prettier" },
typescript = { "prettier" },
javascriptreact = { "prettier" },
typescriptreact = { "prettier" },
svelte = { "prettier" },
css = { "prettier" },
html = { "prettier" },
json = { "prettier" },
lua = { "stylua" },
python = { "black", "ruff_organize_imports" },
go = { "gofumpt" },
sh = { "shfmt" },
terraform = { "terraform_fmt" },
---- flattens array of arrays https://github.com/google/yamlfmt/issues/167
-- yaml = { "yamlfmt" },
----
---- markdownfmt tested
---- For some reason replaces spaces with tabs
---- also splitting list items and list identifier with 4 spaces or tab
---- I.e list item `- item` becomes `- item`
---- .editorconfig had influence on this, tab becomes 2 or 4 spaces
---- but .editorconfig is was not able to make markdownfmt to use spaces instead of tabs
----
---- prettier works better and also uses .editorconfig in addition to .prettierrc and similar
markdown = { "prettier" },
},
formatters = {
-- prettier = {
-- prepend_args = { "--use-tabs", "false" },
-- },
shfmt = {
prepend_args = { "-i", "2" }, -- 2 spaces instead of tab
},
stylua = {
prepend_args = { "--indent-type", "Spaces", "--indent-width", "2" }, -- 2 spaces instead of tab
},
---- Yamlfmt is buggy
---- flattens array of arrays https://github.com/google/yamlfmt/issues/167
-- yamlfmt = {
-- prepend_args = {
-- "-formatter",
-- "indent=2,indentless_arrays=true,include_document_start=false,retain_line_breaks_single=true,eof_newline=true",
-- },
-- },
},
})
vim.keymap.set({ "n", "v" }, "<leader>mp", function()
conform.format({
lsp_format = "fallback",
async = false,
timeout_ms = 1000,
})
end, { desc = "Format file or range (in visual mode)" })
end,
}