27 lines
695 B
Lua
27 lines
695 B
Lua
local prettier = function()
|
|
return {
|
|
exe = Get_project_node_modules_path() .. "/.bin/prettier",
|
|
args = {"--stdin-filepath", vim.api.nvim_buf_get_name(0), '--single-quote'},
|
|
stdin = true
|
|
}
|
|
end
|
|
|
|
require('formatter').setup({
|
|
filetype = {
|
|
javascript = { prettier },
|
|
typescript = { prettier },
|
|
typescriptreact = { prettier },
|
|
}
|
|
})
|
|
|
|
-- TODO: use vim.api.nvim_create_augroup()
|
|
vim.api.nvim_exec2([[
|
|
augroup FormatAutogroup
|
|
autocmd!
|
|
autocmd BufWritePost *.js,*.ts,*.tsx silent FormatWrite
|
|
augroup END
|
|
]], { output = true })
|
|
|
|
local bufnr = vim.fn.bufnr("%")
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>F', '<Cmd>silent Format<CR>', { noremap=true, silent=true })
|