aboutsummaryrefslogtreecommitdiff
path: root/dot_config/nvim/lua/plugins/linter.lua
diff options
context:
space:
mode:
authorpablu <me@pablu.de>2026-04-28 17:07:18 +0200
committerpablu <me@pablu.de>2026-04-28 17:07:18 +0200
commitd0f14ed4a19dd392938ea8ef3bd4e5ae559ecfd2 (patch)
treefeccab9eca67b7333e98d0eb58308c3af6e23891 /dot_config/nvim/lua/plugins/linter.lua
parent68484156fc1f978601dcccfbe284f0d92dffdb35 (diff)
pyproject dependent linters
Diffstat (limited to 'dot_config/nvim/lua/plugins/linter.lua')
-rw-r--r--dot_config/nvim/lua/plugins/linter.lua40
1 files changed, 37 insertions, 3 deletions
diff --git a/dot_config/nvim/lua/plugins/linter.lua b/dot_config/nvim/lua/plugins/linter.lua
index 1628ca6..653e268 100644
--- a/dot_config/nvim/lua/plugins/linter.lua
+++ b/dot_config/nvim/lua/plugins/linter.lua
@@ -2,9 +2,43 @@ return {
'mfussenegger/nvim-lint',
config = function()
local lint = require("lint")
- lint.linters_by_ft = {
- python = { 'mypy' }
- }
+ -- lint.linters_by_ft = {
+ -- python = { 'mypy' }
+ -- }
+
+ local function read_pyproject()
+ local results = vim.fs.find("pyproject.toml", { upward = true, stop = vim.loop.os_homedir() })
+
+ local path = results[1]
+ if not path then
+ return nil
+ end
+
+ local ok, lines = pcall(vim.fn.readfile, path)
+ if not ok then
+ return nil
+ end
+
+ return table.concat(lines, "\n")
+ end
+
+ local function python_linters()
+ local linters = {}
+ local pyproject = read_pyproject()
+
+ if pyproject then
+ if pyproject:match("%[tool%.ruff%]") then
+ table.insert(linters, "ruff")
+ end
+ if pyproject:match("%[tool%.mypy%]") then
+ table.insert(linters, "mypy")
+ end
+ end
+
+ return linters
+ end
+
+ lint.linters_by_ft.python = python_linters()
local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {