-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add mypy,mypyc,dmypy * try fix test
- Loading branch information
Showing
6 changed files
with
191 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
local lint = require('guard.lint') | ||
|
||
return function(cmd, args) | ||
local opts = { | ||
offset = 1, | ||
severities = { | ||
error = lint.severities.error, | ||
warning = lint.severities.warning, | ||
note = lint.severities.info, | ||
}, | ||
source = 'mypy', | ||
} | ||
|
||
-- see spec for pattern examples | ||
local full = { | ||
regex = '([^:]+):(%d+):(%d+):(%d+):(%d+): (%a+): (.*) %[([%a-]+)%]', | ||
groups = { 'filename', 'lnum', 'col', 'end_lnum', 'end_col', 'severity', 'message', 'code' }, | ||
} | ||
|
||
-- no err code | ||
local no_err = { | ||
regex = '([^:]+):(%d+):(%d+):(%d+):(%d+): (%a+): (.*)', | ||
groups = { 'filename', 'lnum', 'col', 'end_lnum', 'end_col', 'severity', 'message' }, | ||
} | ||
|
||
return { | ||
cmd = cmd, | ||
args = args, | ||
fname = true, | ||
parse = function(result, bufnr) | ||
local diags, offences = {}, {} | ||
|
||
local lines = vim.split(result, '\n', { trimempty = true }) | ||
|
||
for _, line in ipairs(lines) do | ||
local offence = {} | ||
|
||
local groups = full.groups | ||
local matches = { line:match(full.regex) } | ||
|
||
if #matches ~= #groups then | ||
matches = { line:match(no_err.regex) } | ||
groups = no_err.groups | ||
end | ||
|
||
-- regex matched | ||
if #matches == #groups then | ||
for i = 1, #groups do | ||
offence[groups[i]] = matches[i] | ||
end | ||
|
||
offences[#offences + 1] = offence | ||
end | ||
end | ||
|
||
vim.tbl_map(function(mes) | ||
local code = mes.code | ||
if not mes.code then | ||
code = '' | ||
end | ||
local diag = lint.diag_fmt( | ||
bufnr, | ||
tonumber(mes.lnum) - opts.offset, | ||
tonumber(mes.col) - opts.offset, | ||
('%s [%s]'):format(mes.message, code), | ||
opts.severities[mes.severity], | ||
opts.source | ||
) | ||
|
||
diag.end_col = tonumber(mes.end_col) - opts.offset | ||
diag.end_lnum = tonumber(mes.end_lnum) - opts.offset | ||
diags[#diags + 1] = diag | ||
end, offences) | ||
|
||
return diags | ||
end, | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
local base = require('guard-collection.linter.mypy.base') | ||
|
||
local args = { | ||
'--hide-error-codes', | ||
'--hide-error-context', | ||
'--no-color-output', | ||
'--show-absolute-path', | ||
'--show-column-numbers', | ||
'--show-error-codes', | ||
'--show-error-end', | ||
'--no-error-summary', | ||
'--no-pretty', | ||
} | ||
|
||
local unpack = table.unpack or unpack | ||
return { | ||
mypy = base('mypy', args), | ||
mypyc = base('mypyc', args), | ||
dmypy = base('dmypy', { 'run', '--', unpack(args) }), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
describe('mypy', function() | ||
it('can lint', function() | ||
local helper = require('test.linter.helper') | ||
local ns = helper.namespace | ||
local ft = require('guard.filetype') | ||
ft('python'):lint('mypy') | ||
require('guard').setup() | ||
|
||
local diagnostics = helper.test_with('python', { | ||
[[def f(i: int) -> int:]], | ||
[[ i += "123"]], | ||
[[ return i]], | ||
[[sum()]], | ||
}) | ||
assert.are.same({ | ||
{ | ||
bufnr = 3, | ||
col = 9, | ||
end_col = 13, | ||
end_lnum = 1, | ||
lnum = 1, | ||
message = 'Unsupported operand types for + ("int" and "str") [operator]', | ||
namespace = 33, | ||
severity = 1, | ||
source = 'mypy', | ||
}, | ||
{ | ||
bufnr = 3, | ||
col = 0, | ||
end_col = 4, | ||
end_lnum = 3, | ||
lnum = 3, | ||
message = 'All overload variants of "sum" require at least one argument [call-overload]', | ||
namespace = 33, | ||
severity = 1, | ||
source = 'mypy', | ||
}, | ||
{ | ||
bufnr = 3, | ||
col = 0, | ||
end_col = 4, | ||
end_lnum = 3, | ||
lnum = 3, | ||
message = 'Possible overload variants: []', | ||
namespace = 33, | ||
severity = 3, | ||
source = 'mypy', | ||
}, | ||
{ | ||
bufnr = 3, | ||
col = 0, | ||
end_col = 4, | ||
end_lnum = 3, | ||
lnum = 3, | ||
message = ' def sum(Iterable[bool], /, start: int = ...) -> int []', | ||
namespace = 33, | ||
severity = 3, | ||
source = 'mypy', | ||
}, | ||
{ | ||
bufnr = 3, | ||
col = 0, | ||
end_col = 4, | ||
end_lnum = 3, | ||
lnum = 3, | ||
message = ' def [_SupportsSumNoDefaultT <: _SupportsSumWithNoDefaultGiven] sum(Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0] []', | ||
namespace = 33, | ||
severity = 3, | ||
source = 'mypy', | ||
}, | ||
{ | ||
bufnr = 3, | ||
col = 0, | ||
end_col = 4, | ||
end_lnum = 3, | ||
lnum = 3, | ||
message = ' def [_AddableT1 <: SupportsAdd[Any, Any], _AddableT2 <: SupportsAdd[Any, Any]] sum(Iterable[_AddableT1], /, start: _AddableT2) -> _AddableT1 | _AddableT2 []', | ||
namespace = 33, | ||
severity = 3, | ||
source = 'mypy', | ||
}, | ||
}, diagnostics) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,14 @@ sudo apt-get install -qqq \ | |
clang-format clang-tidy fish elixir & | ||
luarocks install luacheck & | ||
go install github.com/segmentio/golines@latest & | ||
pip -qqq install autopep8 black djhtml flake8 isort pylint yapf codespell ruff sqlfluff & | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] & | ||
pip -qqq install autopep8 black djhtml flake8 isort pylint yapf codespell ruff sqlfluff mypy & | ||
npm install -g --silent \ | ||
prettier @fsouza/prettierd sql-formatter shellcheck shfmt @taplo/cli & | ||
gem install -q rubocop & | ||
# Block, homebrew takes the longest time | ||
brew install \ | ||
swiftformat swift-format hadolint google-java-format pgformatter fnlfmt ormolu golangci-lint | ||
swiftformat swift-format hadolint google-java-format pgformatter fnlfmt ormolu | ||
|
||
# Install standalone binary packages | ||
bin="/home/runner/.local/bin" | ||
|