Async formatting and linting utility for neovim 0.10+
.
nvimdev/guard.nvim
local ft = require('guard.filetype')
ft('c'):fmt('clang-format')
local ft = require('guard.filetype')
ft('lua'):lint('selene')
local ft = require('guard.filetype')
ft('haskell'):fmt('ormolu')
:lint('hlint')
local ft = require('guard.filetype')
ft('python'):fmt('isort')
:append('black')
:lint('mypy')
:append('mypyc')
:append('dmypy')
local ft = require('guard.filetype')
ft('typescript,javascript,typescriptreact'):fmt('prettier')
codespell
-- this does not work with formatters
ft('*'):lint('codespell')
-- always use 4 spaces for c files
ft('c'):fmt({
cmd = "clang-format",
args = { "--style={IndentWidth: 4}" },
stdin = true,
})
Some presets can be configured via vim.g.guard_config
-- defaults
vim.g.guard_config = {
-- format on write to buffer
fmt_on_save = true,
-- use lsp if no formatter was defined for this filetype
lsp_as_default_formatter = false,
-- whether or not to save the buffer after formatting
save_on_fmt = true,
-- automatic linting
auto_lint = true,
-- how frequently can linters be called
lint_interval = 500
}
Here are all the Guard
subcommands
Name | Desc |
---|---|
Guard fmt | Manually call format, also works with visual mode (best effort range formatting) |
Guard lint | Manually request for lint |
Guard enable-fmt | Turns auto formatting on for the current buffer |
Guard disable-fmt | Turns auto formatting off for the current buffer |
Guard enable-lint | Turns linting on for the current buffer |
Guard disable-lint | Turns linting off for the current buffer |
You can easily create your own configuration that's not in guard-collection
, see help guard.nvim-creating-new-configurations
.
For more niche use cases, help guard.nvim-advanced-tips
demonstrates how to:
fn
field.fn
field.CUSTOMIZE.md
ADVANCED.md