Skip to content
This repository was archived by the owner on Aug 12, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions lua/null-ls/builtins/diagnostics/lintr.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
local h = require("null-ls.helpers")
local methods = require("null-ls.methods")

local DIAGNOSTICS = methods.internal.DIAGNOSTICS
local handle_lintr_output = function(params)
local parser = h.diagnostics.from_json({
attributes = {
row = "line",
col = "column",
end_col = "endColumn",
message = "message",
filename = "filename",
},
severities = {
["style"] = 4,
["warning"] = 2,
["error"] = 1,
},
})
local offenses = {}
for _, offense in ipairs(params.output) do
table.insert(offenses, {
line = offense.line_number,
column = offense.ranges[1][1],
level = offense.type,
message = offense.message,
endColumn = offense.ranges[1][2],
filename = offense.filename,
})
end
return parser({ output = offenses })
end

return h.make_builtin({
name = "lintr",
meta = {
url = "https://github.com/r-lib/lintr",
description = "provides static code analysis for R code.",
notes = {
"requires lintr and jsonlite packages installed on R",
},
},
method = DIAGNOSTICS,
filetypes = { "r", "Rmd", "qmd", "quarto", "RMarkdown" },
generator_opts = {
command = "R",
to_temp_file = true,
args = {
"--slave",
"--vanilla",
"-e",
[[lintr::lint(file='$FILENAME')|>jsonlite::toJSON(force=TRUE,auto_unbox=TRUE)]],
},
format = "json",
on_output = handle_lintr_output,
},
factory = h.generator_factory,
})