pyproject dependent linters

This commit is contained in:
2026-04-28 17:07:18 +02:00
parent 68484156fc
commit d0f14ed4a1
2 changed files with 38 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ return {
conform.setup { conform.setup {
formatters_by_ft = { formatters_by_ft = {
lua = { "stylua" }, lua = { "stylua" },
python = { "isort", "black", lsp_format = "fallback" }, python = { "isort", "black", "ruff", lsp_format = "fallback" },
gotmpl = { "djlint" } gotmpl = { "djlint" }
}, },
format_on_save = { format_on_save = {

View File

@@ -2,9 +2,43 @@ return {
'mfussenegger/nvim-lint', 'mfussenegger/nvim-lint',
config = function() config = function()
local lint = require("lint") local lint = require("lint")
lint.linters_by_ft = { -- lint.linters_by_ft = {
python = { 'mypy' } -- 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 }) local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, { vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {