From 9e3d633c08b928fe10840dd076558ec90791f792 Mon Sep 17 00:00:00 2001 From: Andres Monge Date: Thu, 12 Sep 2024 16:29:31 +0200 Subject: [PATCH] Create pydoclint.lua Supporting extended python doc string documentation lint with https://jsh9.github.io/pydoclint/ --- .../builtins/diagnostics/pydoclint.lua | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 lua/null-ls/builtins/diagnostics/pydoclint.lua diff --git a/lua/null-ls/builtins/diagnostics/pydoclint.lua b/lua/null-ls/builtins/diagnostics/pydoclint.lua new file mode 100644 index 00000000..7ba7f20c --- /dev/null +++ b/lua/null-ls/builtins/diagnostics/pydoclint.lua @@ -0,0 +1,92 @@ +local h = require("null-ls.helpers") +local methods = require("null-ls.methods") +local u = require("null-ls.utils") + +local DIAGNOSTICS = methods.internal.DIAGNOSTICS + +local overrides = { + severities = { + DOC101 = h.diagnostics.severities["warning"], + DOC102 = h.diagnostics.severities["warning"], + DOC103 = h.diagnostics.severities["warning"], + DOC104 = h.diagnostics.severities["warning"], + DOC105 = h.diagnostics.severities["warning"], + DOC106 = h.diagnostics.severities["warning"], + DOC107 = h.diagnostics.severities["warning"], + DOC108 = h.diagnostics.severities["warning"], + DOC109 = h.diagnostics.severities["warning"], + DOC110 = h.diagnostics.severities["warning"], + DOC111 = h.diagnostics.severities["warning"], + DOC201 = h.diagnostics.severities["warning"], + DOC202 = h.diagnostics.severities["warning"], + DOC203 = h.diagnostics.severities["warning"], + DOC301 = h.diagnostics.severities["warning"], + DOC302 = h.diagnostics.severities["warning"], + DOC303 = h.diagnostics.severities["warning"], + DOC304 = h.diagnostics.severities["warning"], + DOC305 = h.diagnostics.severities["warning"], + DOC306 = h.diagnostics.severities["warning"], + DOC307 = h.diagnostics.severities["warning"], + DOC402 = h.diagnostics.severities["warning"], + DOC403 = h.diagnostics.severities["warning"], + DOC404 = h.diagnostics.severities["warning"], + DOC501 = h.diagnostics.severities["warning"], + DOC502 = h.diagnostics.severities["warning"], + DOC503 = h.diagnostics.severities["warning"], + DOC601 = h.diagnostics.severities["warning"], + DOC602 = h.diagnostics.severities["warning"], + DOC603 = h.diagnostics.severities["warning"], + DOC604 = h.diagnostics.severities["warning"], + DOC605 = h.diagnostics.severities["warning"], + }, +} + +return h.make_builtin({ + name = "pydoclint", + meta = { + url = "https://github.com/jsh9/pydoclint", + description = + "Pydoclint is a Python docstring linter to check whether a docstring's sections (arguments, returns, raises, ...) match the function signature or function implementation.", + }, + method = DIAGNOSTICS, + filetypes = { "python" }, + generator_opts = { + command = "pydoclint", + args = function(params) + return { + "--show-filenames-in-every-violation-message=true", + "-q", + params.temp_path, + } + end, + to_temp_file = true, + from_stderr = true, + format = "line", + check_exit_code = function(code) + return code <= 2 + end, + multiple_files = false, + on_output = function(line, params) + -- Filter lines using Lua pattern matching + if line:match("^[^:]+:%d+:") then + -- Process the line as needed + -- Example: Extract components and create a diagnostic + local filename, row, code, message = line:match("([^:]+):(%d+): (%w+): (.+)") + if filename and row and code and message then + -- Create and return the diagnostic + return { + filename = filename, + row = tonumber(row), + code = code, + message = message, + severity = overrides.severities[code] or h.diagnostics.severities["warning"], + } + end + end + end, + }, + factory = h.generator_factory, + can_run = function() + return u.is_executable("null_pydoclint") + end, +})