-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbandit.lua
More file actions
73 lines (68 loc) · 1.99 KB
/
bandit.lua
File metadata and controls
73 lines (68 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
local null_ls = require("null-ls")
local Path = require("plenary.path")
local helpers = require("null-ls.helpers")
local utils = require("null-ls.utils")
return {
method = null_ls.methods.DIAGNOSTICS,
name = "bandit",
filetypes = { "python" },
generator = helpers.generator_factory({
command = "bandit",
name = "bandit",
args = {
"-",
"--format",
"json",
},
to_stdin = true,
from_stderr = false,
ignore_stderr = true,
format = "json",
check_exit_code = { 0, 1 },
runtime_condition = function(params)
-- HACK: mimic bandit excludes so I can use it with null-ls for now
local bandit_ini = Path:new(utils.get_root() .. "/" .. ".bandit")
-- see
-- https://github.com/PyCQA/bandit/blob/a2ac371f30812e1c393dfacb7611c6c162564988/bandit/core/manager.py#L230-L234
-- https://github.com/PyCQA/bandit/blob/a2ac371f30812e1c393dfacb7611c6c162564988/bandit/core/manager.py#L411-L415
-- when searching subdirectories bandit just checks if the exclude-string is anywhere in the path
if bandit_ini:exists() and bandit_ini:is_file() then
for _, line in ipairs(bandit_ini:readlines()) do
local excludes = string.match(line, "^exclude%:%s*(.*)")
if excludes then
for _, pattern in ipairs(vim.split(excludes, ",", { plain = true })) do
if string.find(params.bufname, pattern) then
return false
end
end
end
end
end
return true
end,
on_output = function(params)
local parse = helpers.diagnostics.from_json({
attributes = {
row = "line_number",
col = "col_offset",
code = "test_id",
message = "issue_text",
severity = "issue_severity",
},
offsets = {
col = 1,
},
severities = {
HIGH = helpers.diagnostics.severities["error"],
MEDIUM = helpers.diagnostics.severities["warning"],
LOW = helpers.diagnostics.severities["information"],
},
})
if params.output then
params.output = params.output.results
return parse(params)
end
return {}
end,
}),
}