Skip to content

Commit 739a98c

Browse files
author
Jose Alvarez
authored
Merge pull request #387 from klen/feature/pylama
feat: add pylama
2 parents d54053d + 1db9643 commit 739a98c

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

doc/BUILTINS.md

+18
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,24 @@ local sources = { null_ls.builtins.diagnostics.flake8 }
15561556
- `command = "flake8"`
15571557
- `args = { "--stdin-display-name", "$FILENAME", "-" }`
15581558

1559+
#### [pylama](https://github.com/klen/pylama)
1560+
1561+
##### About
1562+
1563+
Code audit tool for Python.
1564+
1565+
##### Usage
1566+
1567+
```lua
1568+
local sources = { null_ls.builtins.diagnostics.pylama }
1569+
```
1570+
1571+
##### Defaults
1572+
1573+
- `filetypes = { "python" }`
1574+
- `command = "pylama"`
1575+
- `args = { "--from-stdin", "$FILENAME", "-f", "json" }`
1576+
15591577
#### [hadolint](https://github.com/hadolint/hadolint)
15601578

15611579
##### About
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
local h = require("null-ls.helpers")
2+
local methods = require("null-ls.methods")
3+
4+
return h.make_builtin({
5+
method = methods.internal.DIAGNOSTICS,
6+
filetypes = { "python" },
7+
factory = h.generator_factory,
8+
generator_opts = {
9+
command = "pylama",
10+
to_stdin = true,
11+
from_stderr = true,
12+
args = { "--from-stdin", "$FILENAME", "-f", "json" },
13+
format = "json_raw",
14+
check_exit_code = function(code)
15+
return code < 1
16+
end,
17+
on_output = h.diagnostics.from_json({
18+
attributes = {
19+
message = "message",
20+
row = "lnum",
21+
col = "col",
22+
severity = "etype",
23+
code = "number",
24+
source = "source",
25+
},
26+
severities = {
27+
E = h.diagnostics.severities["error"],
28+
W = h.diagnostics.severities["warning"],
29+
S = h.diagnostics.severities["warning"],
30+
I = h.diagnostics.severities["warning"],
31+
C = h.diagnostics.severities["warning"],
32+
T = h.diagnostics.severities["warning"],
33+
F = h.diagnostics.severities["information"],
34+
D = h.diagnostics.severities["information"],
35+
R = h.diagnostics.severities["information"],
36+
},
37+
}),
38+
},
39+
})

test/spec/builtins/diagnostics_spec.lua

+20
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,26 @@ describe("diagnostics", function()
556556
end)
557557
end)
558558

559+
describe("pylama", function()
560+
local linter = diagnostics.flake8
561+
local parser = linter._opts.on_output
562+
local file = {
563+
[[#===- run-clang-tidy.py - Parallel clang-tidy runner ---------*- python -*--===#]],
564+
}
565+
566+
it("should create a diagnostic", function()
567+
local output = [[run-clang-tidy.py:3:1: E265 block comment should start with '# ']]
568+
local diagnostic = parser(output, { content = file })
569+
assert.are.same({
570+
row = "3", --
571+
col = "1",
572+
severity = 1,
573+
code = "E265",
574+
message = "block comment should start with '# '",
575+
}, diagnostic)
576+
end)
577+
end)
578+
559579
describe("misspell", function()
560580
local linter = diagnostics.misspell
561581
local parser = linter._opts.on_output

0 commit comments

Comments
 (0)