1
0
Fork 0

lint: add clippy

This commit is contained in:
Felipe 2023-04-07 23:10:00 -04:00
parent 7c918ec18c
commit 35007c9331
Signed by: pitbuster
SSH key fingerprint: SHA256:HDYu2Pm4/TmSX8GBwV49UvFWr1Ljg8XlHxKeCpjJpOk

View file

@ -118,7 +118,6 @@ local lsp = require 'lspconfig'
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_lsp_attach = function(client, bufnr)
vim.pretty_print(bufnr)
-- See `:help vim.lsp.*` for documentation on any of the below functions
vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
@ -166,21 +165,84 @@ g.ale_go_golangci_lint_options = ''
g.ale_go_golangci_lint_package = 1
---- nvim-lint ----
local lint = require 'lint'
local clippy_format = '%E%f:%l:%c: %\\d%#:%\\d%# %.%\\{-}'
.. 'error:%.%\\{-} %m,%W%f:%l:%c: %\\d%#:%\\d%# %.%\\{-}'
.. 'warning:%.%\\{-} %m,%C%f:%l %m,%-G,%-G'
.. 'error: aborting %.%#,%-G'
.. 'error: Could not compile %.%#,%E'
.. 'error: %m,%Eerror[E%n]: %m,%-G'
.. 'warning: the option `Z` is unstable %.%#,%W'
.. 'warning: %m,%Inote: %m,%C %#--> %f:%l:%c'
lint.linters.clippy = {
cmd = 'cargo clippy',
stdin = false,
append_fname = true,
args = {},
stream = nil, -- ('stdout' | 'stderr' | 'both') configure the stream to which the linter outputs the linting result.
ignore_exitcode = false,
env = nil,
parser = require('lint.parser').from_errorformat(clippy_format)
}
linters = {
bash = {'shellcheck'},
go = {'golangcilint',},
go = {'golangcilint'},
python = {'flake8'},
rust = {'clippy'},
yaml = {'yamllint'},
zsh = {'shellcheck'},
}
-- set linters --
lint.linters_by_ft = linters
-- set autocommands --
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
callback = function()
lint.try_lint(nil, {ignore_errors=true})
end,
})
for ft, ft_linters in pairs(linters) do
local on_change = false
local on_write = false
for l in pairs(ft_linters) do
if lint.linters.l.stdin then
on_change = true
else
on_write = true
end
end
if on_change then
vim.api.nvim_create_autocmd(
{"FileType"},
{
pattern=ft,
callback = function()
vim.api.nvim_create_autocmd(
{"TextChanged" },
{
callback = function()
lint.try_lint(nil, {ignore_errors=true})
end,
}
)
end
}
)
end
if on_write then
vim.api.nvim_create_autocmd(
{"FileType"},
{
pattern=ft,
callback = function()
vim.api.nvim_create_autocmd(
{"BufWritePost" },
{
callback = function()
lint.try_lint(nil, {ignore_errors=true})
end,
}
)
end
}
)
end
end
---- completion-nvim
local cmp = require'cmp'