mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-03 09:35:26 +02:00
[Feature] add linter support (#982)
This commit is contained in:
parent
fe48ed9ef9
commit
836286798e
15 changed files with 107 additions and 84 deletions
33
lua/core/linter.lua
Normal file
33
lua/core/linter.lua
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.setup = function()
|
||||||
|
if O.lint_on_save then
|
||||||
|
require("lv-utils").define_augroups {
|
||||||
|
autolint = {
|
||||||
|
{
|
||||||
|
"BufWritePost",
|
||||||
|
"<buffer>",
|
||||||
|
":silent lua require('lint').try_lint()",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"BufEnter",
|
||||||
|
"<buffer>",
|
||||||
|
":silent lua require('lint').try_lint()",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local status_ok, linter = pcall(require, "lint")
|
||||||
|
if not status_ok then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not O.lint_on_save then
|
||||||
|
vim.cmd [[if exists('#autolint#BufWritePost')
|
||||||
|
:autocmd! autolint
|
||||||
|
endif]]
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
|
@ -127,9 +127,10 @@ M.config = function()
|
||||||
"<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>",
|
"<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>",
|
||||||
"Prev Diagnostic",
|
"Prev Diagnostic",
|
||||||
},
|
},
|
||||||
|
l = { "<cmd>silent lua require('lint').try_lint()<cr>", "Lint" },
|
||||||
q = { "<cmd>Telescope quickfix<cr>", "Quickfix" },
|
q = { "<cmd>Telescope quickfix<cr>", "Quickfix" },
|
||||||
r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
|
r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
|
||||||
s = { "<cmd> Telescope lsp_document_symbols<cr>", "Document Symbols" },
|
s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
|
||||||
S = {
|
S = {
|
||||||
"<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
|
"<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
|
||||||
"Workspace Symbols",
|
"Workspace Symbols",
|
||||||
|
|
|
@ -10,6 +10,7 @@ O = {
|
||||||
line_wrap_cursor_movement = true,
|
line_wrap_cursor_movement = true,
|
||||||
transparent_window = false,
|
transparent_window = false,
|
||||||
format_on_save = true,
|
format_on_save = true,
|
||||||
|
lint_on_save = true,
|
||||||
vsnip_dir = vim.fn.stdpath "config" .. "/snippets",
|
vsnip_dir = vim.fn.stdpath "config" .. "/snippets",
|
||||||
|
|
||||||
default_options = {
|
default_options = {
|
||||||
|
|
|
@ -14,6 +14,10 @@ M.config = function()
|
||||||
exe = "clang-format",
|
exe = "clang-format",
|
||||||
args = {},
|
args = {},
|
||||||
},
|
},
|
||||||
|
linters = {
|
||||||
|
"cppcheck",
|
||||||
|
"clangtidy",
|
||||||
|
},
|
||||||
debug = {
|
debug = {
|
||||||
adapter = {
|
adapter = {
|
||||||
command = "/usr/bin/lldb-vscode",
|
command = "/usr/bin/lldb-vscode",
|
||||||
|
@ -45,8 +49,10 @@ M.format = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lint = function()
|
M.lint = function()
|
||||||
-- TODO: implement linters (if applicable)
|
require("lint").linters_by_ft = {
|
||||||
return "No linters configured!"
|
c = O.lang.clang.linters,
|
||||||
|
cpp = O.lang.clang.linters,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lsp = function()
|
M.lsp = function()
|
||||||
|
|
|
@ -6,6 +6,10 @@ M.config = function()
|
||||||
exe = "gofmt",
|
exe = "gofmt",
|
||||||
args = {},
|
args = {},
|
||||||
},
|
},
|
||||||
|
linters = {
|
||||||
|
"golangcilint",
|
||||||
|
"revive",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -27,8 +31,9 @@ M.format = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lint = function()
|
M.lint = function()
|
||||||
-- TODO: implement linters (if applicable)
|
require("lint").linters_by_ft = {
|
||||||
return "No linters configured!"
|
go = O.lang.go.linters,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lsp = function()
|
M.lsp = function()
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.config = function()
|
M.config = function()
|
||||||
O.lang.html = {}
|
O.lang.html = {
|
||||||
|
linters = {
|
||||||
|
"tidy",
|
||||||
|
-- https://docs.errata.ai/vale/scoping#html
|
||||||
|
"vale",
|
||||||
|
},
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.format = function()
|
M.format = function()
|
||||||
|
@ -10,8 +16,9 @@ M.format = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lint = function()
|
M.lint = function()
|
||||||
-- TODO: implement linters (if applicable)
|
require("lint").linters_by_ft = {
|
||||||
return "No linters configured!"
|
html = O.lang.html.linters,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lsp = function()
|
M.lsp = function()
|
||||||
|
|
|
@ -12,6 +12,7 @@ M.config = function()
|
||||||
args = {},
|
args = {},
|
||||||
stdin = false,
|
stdin = false,
|
||||||
},
|
},
|
||||||
|
linters = { "luacheck" },
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,8 +35,9 @@ M.format = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lint = function()
|
M.lint = function()
|
||||||
-- TODO: implement linters (if applicable)
|
require("lint").linters_by_ft = {
|
||||||
return "No linters configured!"
|
lua = O.lang.lua.linters,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lsp = function()
|
M.lsp = function()
|
||||||
|
|
|
@ -19,6 +19,11 @@ M.config = function()
|
||||||
exe = "yapf",
|
exe = "yapf",
|
||||||
args = {},
|
args = {},
|
||||||
},
|
},
|
||||||
|
linters = {
|
||||||
|
"flake8",
|
||||||
|
"pylint",
|
||||||
|
"mypy",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,41 +45,9 @@ M.format = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lint = function()
|
M.lint = function()
|
||||||
if require("lv-utils").check_lsp_client_active "efm" then
|
require("lint").linters_by_ft = {
|
||||||
return
|
python = O.lang.python.linters,
|
||||||
end
|
|
||||||
local python_arguments = {}
|
|
||||||
|
|
||||||
local flake8 = {
|
|
||||||
LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -",
|
|
||||||
lintStdin = true,
|
|
||||||
lintFormats = { "%f:%l:%c: %m" },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local isort = { formatCommand = "isort --quiet -", formatStdin = true }
|
|
||||||
|
|
||||||
if O.lang.python.linter == "flake8" then
|
|
||||||
table.insert(python_arguments, flake8)
|
|
||||||
end
|
|
||||||
|
|
||||||
if O.lang.python.isort then
|
|
||||||
table.insert(python_arguments, isort)
|
|
||||||
end
|
|
||||||
|
|
||||||
if not require("lv-utils").check_lsp_client_active "efm" then
|
|
||||||
require("lspconfig").efm.setup {
|
|
||||||
cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
|
|
||||||
init_options = { documentFormatting = true, codeAction = false },
|
|
||||||
root_dir = require("lspconfig").util.root_pattern(".git/", "requirements.txt"),
|
|
||||||
filetypes = { "python" },
|
|
||||||
settings = {
|
|
||||||
rootMarkers = { ".git/", "requirements.txt" },
|
|
||||||
languages = {
|
|
||||||
python = python_arguments,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lsp = function()
|
M.lsp = function()
|
||||||
|
|
|
@ -12,6 +12,7 @@ M.config = function()
|
||||||
exe = "rufo",
|
exe = "rufo",
|
||||||
args = { "-x" },
|
args = { "-x" },
|
||||||
},
|
},
|
||||||
|
linters = { "ruby" },
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,8 +34,9 @@ M.format = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lint = function()
|
M.lint = function()
|
||||||
-- TODO: implement linters (if applicable)
|
require("lint").linters_by_ft = {
|
||||||
return "No linters configured!"
|
ruby = O.lang.ruby.linters,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lsp = function()
|
M.lsp = function()
|
||||||
|
|
|
@ -15,6 +15,7 @@ M.config = function()
|
||||||
args = { "-w" },
|
args = { "-w" },
|
||||||
stdin = false,
|
stdin = false,
|
||||||
},
|
},
|
||||||
|
linters = { "shellcheck" },
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,36 +38,9 @@ M.format = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lint = function()
|
M.lint = function()
|
||||||
-- sh
|
require("lint").linters_by_ft = {
|
||||||
local sh_arguments = {}
|
sh = O.lang.sh.linters,
|
||||||
|
|
||||||
local shfmt = { formatCommand = "shfmt -ci -s -bn", formatStdin = true }
|
|
||||||
|
|
||||||
local shellcheck = {
|
|
||||||
LintCommand = "shellcheck -f gcc -x",
|
|
||||||
lintFormats = { "%f:%l:%c: %trror: %m", "%f:%l:%c: %tarning: %m", "%f:%l:%c: %tote: %m" },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if O.lang.sh.linter == "shellcheck" then
|
|
||||||
table.insert(sh_arguments, shellcheck)
|
|
||||||
end
|
|
||||||
|
|
||||||
if not require("lv-utils").check_lsp_client_active "efm" then
|
|
||||||
require("lspconfig").efm.setup {
|
|
||||||
-- init_options = {initializationOptions},
|
|
||||||
cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
|
|
||||||
on_attach = require("lsp").common_on_attach,
|
|
||||||
init_options = { documentFormatting = true, codeAction = false },
|
|
||||||
root_dir = require("lspconfig").util.root_pattern ".git/",
|
|
||||||
filetypes = { "sh" },
|
|
||||||
settings = {
|
|
||||||
rootMarkers = { ".git/" },
|
|
||||||
languages = {
|
|
||||||
sh = sh_arguments,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lsp = function()
|
M.lsp = function()
|
||||||
|
|
|
@ -31,6 +31,7 @@ M.config = function()
|
||||||
signs = true,
|
signs = true,
|
||||||
underline = true,
|
underline = true,
|
||||||
},
|
},
|
||||||
|
linters = { "chktex" },
|
||||||
auto_save = false,
|
auto_save = false,
|
||||||
ignore_errors = {},
|
ignore_errors = {},
|
||||||
}
|
}
|
||||||
|
@ -42,8 +43,9 @@ M.format = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lint = function()
|
M.lint = function()
|
||||||
-- TODO: implement linters (if applicable)
|
require("lint").linters_by_ft = {
|
||||||
return "No linters configured!"
|
tex = O.lang.latex.linters,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lsp = function()
|
M.lsp = function()
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.config = function()
|
M.config = function()
|
||||||
O.lang.vim = {}
|
O.lang.vim = {
|
||||||
|
linters = { "vint" },
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.format = function()
|
M.format = function()
|
||||||
|
@ -10,8 +12,9 @@ M.format = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lint = function()
|
M.lint = function()
|
||||||
-- TODO: implement linters (if applicable)
|
require("lint").linters_by_ft = {
|
||||||
return "No linters configured!"
|
vim = O.lang.vim.linters,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lsp = function()
|
M.lsp = function()
|
||||||
|
|
|
@ -86,6 +86,12 @@ return require("packer").startup(function(use)
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Linter
|
||||||
|
use {
|
||||||
|
"mfussenegger/nvim-lint",
|
||||||
|
config = require("core.linter").setup,
|
||||||
|
}
|
||||||
|
|
||||||
-- NvimTree
|
-- NvimTree
|
||||||
use {
|
use {
|
||||||
"kyazdani42/nvim-tree.lua",
|
"kyazdani42/nvim-tree.lua",
|
||||||
|
|
|
@ -11,6 +11,7 @@ an executable
|
||||||
-- general
|
-- general
|
||||||
|
|
||||||
O.format_on_save = true
|
O.format_on_save = true
|
||||||
|
O.lint_on_save = true
|
||||||
O.completion.autocomplete = true
|
O.completion.autocomplete = true
|
||||||
O.colorscheme = "spacegray"
|
O.colorscheme = "spacegray"
|
||||||
O.auto_close_tree = 0
|
O.auto_close_tree = 0
|
||||||
|
@ -35,12 +36,15 @@ O.treesitter.highlight.enabled = true
|
||||||
O.lang.python.isort = true
|
O.lang.python.isort = true
|
||||||
O.lang.python.diagnostics.virtual_text = true
|
O.lang.python.diagnostics.virtual_text = true
|
||||||
O.lang.python.analysis.use_library_code_types = true
|
O.lang.python.analysis.use_library_code_types = true
|
||||||
-- to change default formatter from yapf to black
|
-- To change default formatter from yapf to black
|
||||||
-- O.lang.python.formatter.exe = "black"
|
-- O.lang.python.formatter.exe = "black"
|
||||||
-- O.lang.python.formatter.args = {"-"}
|
-- O.lang.python.formatter.args = {"-"}
|
||||||
|
-- To change enabled linters
|
||||||
|
-- https://github.com/mfussenegger/nvim-lint#available-linters
|
||||||
|
-- O.lang.python.linters = { "flake8", "pylint", "mypy", ... }
|
||||||
|
|
||||||
-- go
|
-- go
|
||||||
-- to change default formatter from gofmt to goimports
|
-- To change default formatter from gofmt to goimports
|
||||||
-- O.lang.formatter.go.exe = "goimports"
|
-- O.lang.formatter.go.exe = "goimports"
|
||||||
|
|
||||||
-- javascript
|
-- javascript
|
||||||
|
|
|
@ -11,6 +11,7 @@ an executable
|
||||||
-- general
|
-- general
|
||||||
|
|
||||||
O.format_on_save = true
|
O.format_on_save = true
|
||||||
|
O.lint_on_save = true
|
||||||
O.completion.autocomplete = true
|
O.completion.autocomplete = true
|
||||||
O.colorscheme = "spacegray"
|
O.colorscheme = "spacegray"
|
||||||
O.auto_close_tree = 0
|
O.auto_close_tree = 0
|
||||||
|
@ -35,12 +36,15 @@ O.treesitter.highlight.enabled = true
|
||||||
O.lang.python.isort = true
|
O.lang.python.isort = true
|
||||||
O.lang.python.diagnostics.virtual_text = true
|
O.lang.python.diagnostics.virtual_text = true
|
||||||
O.lang.python.analysis.use_library_code_types = true
|
O.lang.python.analysis.use_library_code_types = true
|
||||||
-- to change default formatter from yapf to black
|
-- To change default formatter from yapf to black
|
||||||
-- O.lang.python.formatter.exe = "black"
|
-- O.lang.python.formatter.exe = "black"
|
||||||
-- O.lang.python.formatter.args = {"-"}
|
-- O.lang.python.formatter.args = {"-"}
|
||||||
|
-- To change enabled linters
|
||||||
|
-- https://github.com/mfussenegger/nvim-lint#available-linters
|
||||||
|
-- O.lang.python.linters = { "flake8", "pylint", "mypy", ... }
|
||||||
|
|
||||||
-- go
|
-- go
|
||||||
-- to change default formatter from gofmt to goimports
|
-- To change default formatter from gofmt to goimports
|
||||||
-- O.lang.formatter.go.exe = "goimports"
|
-- O.lang.formatter.go.exe = "goimports"
|
||||||
|
|
||||||
-- javascript
|
-- javascript
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue