From b93e44d8a8dd0dfc015001154ac1b35291a09e42 Mon Sep 17 00:00:00 2001 From: Andres Monge Date: Fri, 17 Jan 2025 15:13:12 +0000 Subject: [PATCH] builtins/diagnostics: add pydoclint (#181) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Zephyr Lykos --- doc/BUILTINS.md | 17 +++++++++ .../builtins/diagnostics/pydoclint.lua | 36 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 lua/null-ls/builtins/diagnostics/pydoclint.lua diff --git a/doc/BUILTINS.md b/doc/BUILTINS.md index 1ead71dc..f2b4ac86 100644 --- a/doc/BUILTINS.md +++ b/doc/BUILTINS.md @@ -1010,6 +1010,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. diff --git a/lua/null-ls/builtins/diagnostics/pydoclint.lua b/lua/null-ls/builtins/diagnostics/pydoclint.lua new file mode 100644 index 00000000..cab135b9 --- /dev/null +++ b/lua/null-ls/builtins/diagnostics/pydoclint.lua @@ -0,0 +1,36 @@ +local h = require("null-ls.helpers") +local methods = require("null-ls.methods") + +local DIAGNOSTICS = methods.internal.DIAGNOSTICS + +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. To see all violation codes go to [pydoclint](https://jsh9.github.io/pydoclint/violation_codes.html)", + }, + method = DIAGNOSTICS, + filetypes = { "python" }, + generator_opts = { + command = "pydoclint", + args = { + "--show-filenames-in-every-violation-message=true", + "-q", + "$FILENAME", + }, + 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) + local path = params.temp_path + -- rel/path/to/file.py:42: DOC000: Diagnostic message + local pattern = path .. [[:(%d+): (DOC%d+: .*)]] + return h.diagnostics.from_pattern(pattern, { "row", "message" })(line, params) + end, + }, + factory = h.generator_factory, +})