lint: add clippy
This commit is contained in:
parent
7c918ec18c
commit
35007c9331
1 changed files with 69 additions and 7 deletions
70
init.lua
70
init.lua
|
|
@ -118,7 +118,6 @@ local lsp = require 'lspconfig'
|
||||||
-- Use an on_attach function to only map the following keys
|
-- Use an on_attach function to only map the following keys
|
||||||
-- after the language server attaches to the current buffer
|
-- after the language server attaches to the current buffer
|
||||||
local on_lsp_attach = function(client, bufnr)
|
local on_lsp_attach = function(client, bufnr)
|
||||||
vim.pretty_print(bufnr)
|
|
||||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
-- 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.declaration()<CR>', opts)
|
||||||
vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<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
|
g.ale_go_golangci_lint_package = 1
|
||||||
---- nvim-lint ----
|
---- nvim-lint ----
|
||||||
local lint = require '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 = {
|
linters = {
|
||||||
bash = {'shellcheck'},
|
bash = {'shellcheck'},
|
||||||
go = {'golangcilint',},
|
go = {'golangcilint'},
|
||||||
python = {'flake8'},
|
python = {'flake8'},
|
||||||
|
rust = {'clippy'},
|
||||||
yaml = {'yamllint'},
|
yaml = {'yamllint'},
|
||||||
zsh = {'shellcheck'},
|
zsh = {'shellcheck'},
|
||||||
}
|
}
|
||||||
-- set linters --
|
-- set linters --
|
||||||
lint.linters_by_ft = linters
|
lint.linters_by_ft = linters
|
||||||
-- set autocommands --
|
-- set autocommands --
|
||||||
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
|
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()
|
callback = function()
|
||||||
lint.try_lint(nil, {ignore_errors=true})
|
lint.try_lint(nil, {ignore_errors=true})
|
||||||
end,
|
end,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---- completion-nvim
|
---- completion-nvim
|
||||||
local cmp = require'cmp'
|
local cmp = require'cmp'
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue