From 9e3d633c08b928fe10840dd076558ec90791f792 Mon Sep 17 00:00:00 2001 From: Andres Monge Date: Thu, 12 Sep 2024 16:29:31 +0200 Subject: [PATCH 1/4] 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, +}) From 96379381c21bedff71249ff3361be3fc20f7cdb3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:32:43 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- lua/null-ls/builtins/diagnostics/pydoclint.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/null-ls/builtins/diagnostics/pydoclint.lua b/lua/null-ls/builtins/diagnostics/pydoclint.lua index 7ba7f20c..f44f86d1 100644 --- a/lua/null-ls/builtins/diagnostics/pydoclint.lua +++ b/lua/null-ls/builtins/diagnostics/pydoclint.lua @@ -45,8 +45,7 @@ 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.", + 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" }, From 5321b21bba2868ffd6e3d4382fb99eb5cf3d1071 Mon Sep 17 00:00:00 2001 From: Andres Monge Date: Thu, 12 Sep 2024 17:59:09 +0200 Subject: [PATCH 3/4] fix(pydoclint): Linted file, no params used --- lua/null-ls/builtins/diagnostics/pydoclint.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/null-ls/builtins/diagnostics/pydoclint.lua b/lua/null-ls/builtins/diagnostics/pydoclint.lua index f44f86d1..dd10ac70 100644 --- a/lua/null-ls/builtins/diagnostics/pydoclint.lua +++ b/lua/null-ls/builtins/diagnostics/pydoclint.lua @@ -65,7 +65,7 @@ return h.make_builtin({ return code <= 2 end, multiple_files = false, - on_output = function(line, params) + on_output = function(line) -- Filter lines using Lua pattern matching if line:match("^[^:]+:%d+:") then -- Process the line as needed From bbb4fc1341cee1d1577b83885709b715d4641fb3 Mon Sep 17 00:00:00 2001 From: Andres Monge Date: Fri, 13 Sep 2024 09:20:20 +0200 Subject: [PATCH 4/4] feat(pydoclint): Including pydoclint in builtins --- doc/BUILTINS.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/BUILTINS.md b/doc/BUILTINS.md index ce4445b3..76803e6f 100644 --- a/doc/BUILTINS.md +++ b/doc/BUILTINS.md @@ -978,6 +978,23 @@ local sources = { null_ls.builtins.diagnostics.mypy } - Command: `mypy` - Args: dynamically resolved (see [source](https://github.com/nvimtools/none-ls.nvim/blob/main/lua/null-ls/builtins/diagnostics/mypy.lua)) +### [pydoclint](https://jsh9.github.io/pydoclint/) + +Pydoclint is a Python docstring linter to check whether a docstring's sections (arguments, returns, raises, ...) match the function signature or function implementation. +Usage + +```lua +local sources = { null_ls.builtins.diagnostics.pydoclint } +``` + +#### Defaults + +- Filetypes: `{ "python" }` +- Method: `diagnostics` +- Command: `pydoclint` +- Args: dynamically resolved (see source) + + ### [npm_groovy_lint](https://github.com/nvuillam/npm-groovy-lint) Lint, format and auto-fix Groovy, Jenkinsfile, and Gradle files.