Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create pydoclint.lua #181

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions doc/BUILTINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
91 changes: 91 additions & 0 deletions lua/null-ls/builtins/diagnostics/pydoclint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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)
-- 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,
})