Skip to content

Commit

Permalink
ruff: Treat most results as warning instead of error
Browse files Browse the repository at this point in the history
ruff doesn't really implement severities by itself [1], and one could
argue it doesn't make any sense that all diagnostics are warnings.

The official lsp implmentation for ruff, ruff-lsp implements a basic
mapping from codes to severity [2], so at the very least we should feel
comfortable migrating that mapping for our use.

1. astral-sh/ruff#1256
2. https://github.com/astral-sh/ruff-lsp/blob/6a1a7b18711cf65b058492d5800e606f14556861/ruff_lsp/server.py#L346-L354
  • Loading branch information
Avishay Matayev authored and mfussenegger committed Nov 8, 2023
1 parent 2eb6518 commit 06e4bb4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lua/lint/linters/ruff.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ local function get_file_name()
return vim.api.nvim_buf_get_name(0)
end

local error = vim.diagnostic.severity.ERROR
local severities = {
["F821"] = error, -- undefined name `name`
["E902"] = error, -- `IOError`
["E999"] = error, -- `SyntaxError`
}

return {
cmd = "ruff",
stdin = true,
Expand All @@ -24,16 +31,17 @@ return {
return diagnostics
end
for _, result in ipairs(results or {}) do
local err = {
local diagnostic = {
message = result.message,
col = result.location.column - 1,
end_col = result.end_location.column - 1,
lnum = result.location.row - 1,
end_lnum = result.end_location.row - 1,
code = result.code,
severity = vim.diagnostic.severity.WARN,
severity = severities[result.code] or vim.diagnostic.severity.WARN,
source = "ruff",
}
table.insert(diagnostics, err)
table.insert(diagnostics, diagnostic)
end
return diagnostics
end,
Expand Down

0 comments on commit 06e4bb4

Please sign in to comment.