summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuc Sinet <[email protected]>2021-07-17 00:30:38 +0200
committerGitHub <[email protected]>2021-07-16 18:30:38 -0400
commit836286798e959fbaa43bd4502561cf85aea537c9 (patch)
tree821f5c459fb056c619aab9f34d802be8776a1cac
parentfe48ed9ef9de8da8b9fbf7f82f8e0af1758581a4 (diff)
[Feature] add linter support (#982)
-rw-r--r--lua/core/linter.lua33
-rw-r--r--lua/core/which-key.lua3
-rw-r--r--lua/default-config.lua1
-rw-r--r--lua/lang/clang.lua10
-rw-r--r--lua/lang/go.lua9
-rw-r--r--lua/lang/html.lua13
-rw-r--r--lua/lang/lua.lua6
-rw-r--r--lua/lang/python.lua41
-rw-r--r--lua/lang/ruby.lua6
-rw-r--r--lua/lang/sh.lua32
-rw-r--r--lua/lang/tex.lua6
-rw-r--r--lua/lang/vim.lua9
-rw-r--r--lua/plugins.lua6
-rw-r--r--utils/installer/lv-config.example-no-ts.lua8
-rw-r--r--utils/installer/lv-config.example.lua8
15 files changed, 107 insertions, 84 deletions
diff --git a/lua/core/linter.lua b/lua/core/linter.lua
new file mode 100644
index 00000000..9c6649a8
--- /dev/null
+++ b/lua/core/linter.lua
@@ -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
diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua
index 6f034e3e..ec64074b 100644
--- a/lua/core/which-key.lua
+++ b/lua/core/which-key.lua
@@ -127,9 +127,10 @@ M.config = function()
"<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>",
"Prev Diagnostic",
},
+ l = { "<cmd>silent lua require('lint').try_lint()<cr>", "Lint" },
q = { "<cmd>Telescope quickfix<cr>", "Quickfix" },
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 = {
"<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
"Workspace Symbols",
diff --git a/lua/default-config.lua b/lua/default-config.lua
index 3a019042..32a72483 100644
--- a/lua/default-config.lua
+++ b/lua/default-config.lua
@@ -10,6 +10,7 @@ O = {
line_wrap_cursor_movement = true,
transparent_window = false,
format_on_save = true,
+ lint_on_save = true,
vsnip_dir = vim.fn.stdpath "config" .. "/snippets",
default_options = {
diff --git a/lua/lang/clang.lua b/lua/lang/clang.lua
index 59f6deca..22fd0ed0 100644
--- a/lua/lang/clang.lua
+++ b/lua/lang/clang.lua
@@ -14,6 +14,10 @@ M.config = function()
exe = "clang-format",
args = {},
},
+ linters = {
+ "cppcheck",
+ "clangtidy",
+ },
debug = {
adapter = {
command = "/usr/bin/lldb-vscode",
@@ -45,8 +49,10 @@ M.format = function()
end
M.lint = function()
- -- TODO: implement linters (if applicable)
- return "No linters configured!"
+ require("lint").linters_by_ft = {
+ c = O.lang.clang.linters,
+ cpp = O.lang.clang.linters,
+ }
end
M.lsp = function()
diff --git a/lua/lang/go.lua b/lua/lang/go.lua
index 7997a911..4174629a 100644
--- a/lua/lang/go.lua
+++ b/lua/lang/go.lua
@@ -6,6 +6,10 @@ M.config = function()
exe = "gofmt",
args = {},
},
+ linters = {
+ "golangcilint",
+ "revive",
+ },
}
end
@@ -27,8 +31,9 @@ M.format = function()
end
M.lint = function()
- -- TODO: implement linters (if applicable)
- return "No linters configured!"
+ require("lint").linters_by_ft = {
+ go = O.lang.go.linters,
+ }
end
M.lsp = function()
diff --git a/lua/lang/html.lua b/lua/lang/html.lua
index 5f91becf..1c45cd05 100644
--- a/lua/lang/html.lua
+++ b/lua/lang/html.lua
@@ -1,7 +1,13 @@
local M = {}
M.config = function()
- O.lang.html = {}
+ O.lang.html = {
+ linters = {
+ "tidy",
+ -- https://docs.errata.ai/vale/scoping#html
+ "vale",
+ },
+ }
end
M.format = function()
@@ -10,8 +16,9 @@ M.format = function()
end
M.lint = function()
- -- TODO: implement linters (if applicable)
- return "No linters configured!"
+ require("lint").linters_by_ft = {
+ html = O.lang.html.linters,
+ }
end
M.lsp = function()
diff --git a/lua/lang/lua.lua b/lua/lang/lua.lua
index 39fde833..f14b0b1d 100644
--- a/lua/lang/lua.lua
+++ b/lua/lang/lua.lua
@@ -12,6 +12,7 @@ M.config = function()
args = {},
stdin = false,
},
+ linters = { "luacheck" },
}
end
@@ -34,8 +35,9 @@ M.format = function()
end
M.lint = function()
- -- TODO: implement linters (if applicable)
- return "No linters configured!"
+ require("lint").linters_by_ft = {
+ lua = O.lang.lua.linters,
+ }
end
M.lsp = function()
diff --git a/lua/lang/python.lua b/lua/lang/python.lua
index 3bab555a..b4f74a6a 100644
--- a/lua/lang/python.lua
+++ b/lua/lang/python.lua
@@ -19,6 +19,11 @@ M.config = function()
exe = "yapf",
args = {},
},
+ linters = {
+ "flake8",
+ "pylint",
+ "mypy",
+ },
}
end
@@ -40,41 +45,9 @@ M.format = function()
end
M.lint = function()
- if require("lv-utils").check_lsp_client_active "efm" then
- return
- end
- local python_arguments = {}
-
- local flake8 = {
- LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -",
- lintStdin = true,
- lintFormats = { "%f:%l:%c: %m" },
+ require("lint").linters_by_ft = {
+ python = O.lang.python.linters,
}
-
- 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
M.lsp = function()
diff --git a/lua/lang/ruby.lua b/lua/lang/ruby.lua
index f306025b..20618951 100644
--- a/lua/lang/ruby.lua
+++ b/lua/lang/ruby.lua
@@ -12,6 +12,7 @@ M.config = function()
exe = "rufo",
args = { "-x" },
},
+ linters = { "ruby" },
}
end
@@ -33,8 +34,9 @@ M.format = function()
end
M.lint = function()
- -- TODO: implement linters (if applicable)
- return "No linters configured!"
+ require("lint").linters_by_ft = {
+ ruby = O.lang.ruby.linters,
+ }
end
M.lsp = function()
diff --git a/lua/lang/sh.lua b/lua/lang/sh.lua
index f2a7fe78..e7c5ef16 100644
--- a/lua/lang/sh.lua
+++ b/lua/lang/sh.lua
@@ -15,6 +15,7 @@ M.config = function()
args = { "-w" },
stdin = false,
},
+ linters = { "shellcheck" },
}
end
@@ -37,36 +38,9 @@ M.format = function()
end
M.lint = function()
- -- sh
- local sh_arguments = {}
-
- 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" },
+ require("lint").linters_by_ft = {
+ sh = O.lang.sh.linters,
}
-
- 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
M.lsp = function()
diff --git a/lua/lang/tex.lua b/lua/lang/tex.lua
index 7ebc84a0..7fdc8757 100644
--- a/lua/lang/tex.lua
+++ b/lua/lang/tex.lua
@@ -31,6 +31,7 @@ M.config = function()
signs = true,
underline = true,
},
+ linters = { "chktex" },
auto_save = false,
ignore_errors = {},
}
@@ -42,8 +43,9 @@ M.format = function()
end
M.lint = function()
- -- TODO: implement linters (if applicable)
- return "No linters configured!"
+ require("lint").linters_by_ft = {
+ tex = O.lang.latex.linters,
+ }
end
M.lsp = function()
diff --git a/lua/lang/vim.lua b/lua/lang/vim.lua
index 4c29a84a..4386757e 100644
--- a/lua/lang/vim.lua
+++ b/lua/lang/vim.lua
@@ -1,7 +1,9 @@
local M = {}
M.config = function()
- O.lang.vim = {}
+ O.lang.vim = {
+ linters = { "vint" },
+ }
end
M.format = function()
@@ -10,8 +12,9 @@ M.format = function()
end
M.lint = function()
- -- TODO: implement linters (if applicable)
- return "No linters configured!"
+ require("lint").linters_by_ft = {
+ vim = O.lang.vim.linters,
+ }
end
M.lsp = function()
diff --git a/lua/plugins.lua b/lua/plugins.lua
index 0aa29d17..0059f342 100644
--- a/lua/plugins.lua
+++ b/lua/plugins.lua
@@ -86,6 +86,12 @@ return require("packer").startup(function(use)
end,
}
+ -- Linter
+ use {
+ "mfussenegger/nvim-lint",
+ config = require("core.linter").setup,
+ }
+
-- NvimTree
use {
"kyazdani42/nvim-tree.lua",
diff --git a/utils/installer/lv-config.example-no-ts.lua b/utils/installer/lv-config.example-no-ts.lua
index 7ab4536f..f06189cc 100644
--- a/utils/installer/lv-config.example-no-ts.lua
+++ b/utils/installer/lv-config.example-no-ts.lua
@@ -11,6 +11,7 @@ an executable
-- general
O.format_on_save = true
+O.lint_on_save = true
O.completion.autocomplete = true
O.colorscheme = "spacegray"
O.auto_close_tree = 0
@@ -35,12 +36,15 @@ O.treesitter.highlight.enabled = true
O.lang.python.isort = true
O.lang.python.diagnostics.virtual_text = 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.args = {"-"}
+-- To change enabled linters
+-- https://github.com/mfussenegger/nvim-lint#available-linters
+-- O.lang.python.linters = { "flake8", "pylint", "mypy", ... }
-- go
--- to change default formatter from gofmt to goimports
+-- To change default formatter from gofmt to goimports
-- O.lang.formatter.go.exe = "goimports"
-- javascript
diff --git a/utils/installer/lv-config.example.lua b/utils/installer/lv-config.example.lua
index 45bf4df8..cbc495e8 100644
--- a/utils/installer/lv-config.example.lua
+++ b/utils/installer/lv-config.example.lua
@@ -11,6 +11,7 @@ an executable
-- general
O.format_on_save = true
+O.lint_on_save = true
O.completion.autocomplete = true
O.colorscheme = "spacegray"
O.auto_close_tree = 0
@@ -35,12 +36,15 @@ O.treesitter.highlight.enabled = true
O.lang.python.isort = true
O.lang.python.diagnostics.virtual_text = 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.args = {"-"}
+-- To change enabled linters
+-- https://github.com/mfussenegger/nvim-lint#available-linters
+-- O.lang.python.linters = { "flake8", "pylint", "mypy", ... }
-- go
--- to change default formatter from gofmt to goimports
+-- To change default formatter from gofmt to goimports
-- O.lang.formatter.go.exe = "goimports"
-- javascript