Skip to content

Commit

Permalink
mypy: Add error codes to diagnostics (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
tahv authored Oct 10, 2024
1 parent 7e9eb8f commit 11ddccb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lua/lint/linters/mypy.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- path/to/file:line:col: severity: message
local pattern = '([^:]+):(%d+):(%d+):(%d+):(%d+): (%a+): (.*)'
local groups = { 'file', 'lnum', 'col', 'end_lnum', 'end_col', 'severity', 'message' }
local pattern = '([^:]+):(%d+):(%d+):(%d+):(%d+): (%a+): (.*) %[(%a[%a-]+)%]'
local groups = { 'file', 'lnum', 'col', 'end_lnum', 'end_col', 'severity', 'message', 'code' }
local severities = {
error = vim.diagnostic.severity.ERROR,
warning = vim.diagnostic.severity.WARN,
Expand All @@ -14,7 +14,6 @@ return {
args = {
'--show-column-numbers',
'--show-error-end',
'--hide-error-codes',
'--hide-error-context',
'--no-color-output',
'--no-error-summary',
Expand Down
16 changes: 14 additions & 2 deletions spec/mypy_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ describe('linter.mypy', function()
local parser = require('lint.linters.mypy').parser
local bufnr = vim.uri_to_bufnr('file:///foo.py')
local output = [[
/foo.py:10:15:10:20: error: Incompatible return value type (got "str", expected "bool")
/foo.py:20:25:20:30: error: Argument 1 to "foo" has incompatible type "str"; expected "int"
/foo.py:10:15:10:20: error: Incompatible return value type (got "str", expected "bool") [return-value]
/foo.py:20:25:20:30: error: Argument 1 to "foo" has incompatible type "str"; expected "int" [arg-type]
]]
local result = parser(output, bufnr)

Expand All @@ -13,22 +13,34 @@ describe('linter.mypy', function()
local expected_error = {
source = 'mypy',
message = 'Incompatible return value type (got "str", expected "bool")',
code = 'return-value',
lnum = 9,
col = 14,
end_lnum = 9,
end_col = 20,
severity = vim.diagnostic.severity.ERROR,
user_data = {
lsp = {
code = 'return-value'
}
}
}
assert.are.same(expected_error, result[1])

local expected_warning = {
source = 'mypy',
message = 'Argument 1 to "foo" has incompatible type "str"; expected "int"',
code = 'arg-type',
lnum = 19,
col = 24,
end_lnum = 19,
end_col = 30,
severity = vim.diagnostic.severity.ERROR,
user_data = {
lsp = {
code = 'arg-type'
}
}
}
assert.are.same(expected_warning, result[2])
end)
Expand Down

0 comments on commit 11ddccb

Please sign in to comment.