-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconform.lua
More file actions
66 lines (66 loc) · 1.78 KB
/
conform.lua
File metadata and controls
66 lines (66 loc) · 1.78 KB
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
return {
"stevearc/conform.nvim",
event = { "BufWritePre" },
cmd = { "ConformInfo" },
keys = {
{
-- Customize or remove this keymap to your liking
"<leader>fmt",
function()
require("conform").format({ async = true })
end,
mode = "",
desc = "Format buffer",
},
},
-- This will provide type hinting with LuaLS
---@module "conform"
opts = {
-- Define your formatters
formatters_by_ft = {
lua = { "stylua" },
python = { "isort", "black" },
rust = { "rustfmt", lsp_format = "fallback" },
javascript = { "eslint_d", "prettierd", "prettier", stop_after_first = true },
typescript = { "eslint_d", "prettier", stop_after_first = true },
javascriptreact = { "eslint_d", "prettier", stop_after_first = true },
typescriptreact = { "eslint_d", "prettier", stop_after_first = true },
svelte = { "prettier" },
css = { "prettier" },
html = { "prettier" },
json = { "prettier" },
yaml = { "prettier" },
markdown = { "prettier" },
graphql = { "prettier" },
go = { "goimports", "gofmt" },
ruby = { "rubocop" },
},
format_on_save = function(bufnr)
local ft = vim.bo[bufnr].filetype
if ft == "lua" then
return {} -- enable format on save with default options
end
return false -- disable for all other filetypes
end,
-- Set default options
default_format_opts = {
lsp_format = "fallback",
},
-- Set up format-on-save
-- format_on_save = { timeout_ms = 500 },
-- Customize formatters
formatters = {
shfmt = {
prepend_args = { "-i", "2" },
},
-- Use system rubocop (from mise) instead of Mason's version
rubocop = {
command = "rubocop",
},
},
},
init = function()
-- If you want the formatexpr, here is the place to set it
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
}