Skip to content

Commit

Permalink
Add sphinx-lint support
Browse files Browse the repository at this point in the history
This adds support for sphinx-lint, the linter provided by Sphinx here:
https://github.com/sphinx-contrib/sphinx-lint

Signed-off-by: Antonin Godard <[email protected]>
  • Loading branch information
antznin authored and mfussenegger committed Nov 18, 2024
1 parent 36da8dd commit 8e9562d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ Other dedicated linters that are built-in are:
| [snyk][snyk] | `snyk_iac` |
| [Solhint][solhint] | `solhint` |
| [Spectral][spectral] | `spectral` |
| [sphinx-lint][sphinx-lint] | `sphinx-lint` |
| [sqlfluff][sqlfluff] | `sqlfluff` |
| [standardjs][standardjs] | `standardjs` |
| [StandardRB][27] | `standardrb` |
Expand Down Expand Up @@ -551,6 +552,7 @@ busted tests/
[snakemake]: https://snakemake.github.io
[snyk]: https://github.com/snyk/cli
[spectral]: https://github.com/stoplightio/spectral
[sphinx-lint]: https://github.com/sphinx-contrib/sphinx-lint
[gitlint]: https://github.com/jorisroovers/gitlint
[pflake8]: https://github.com/csachs/pyproject-flake8
[fish]: https://github.com/fish-shell/fish-shell
Expand Down
12 changes: 12 additions & 0 deletions lua/lint/linters/sphinx-lint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local efm = '%f:%l: %m'

return {
cmd = 'sphinx-lint',

stream = 'stderr',
ignore_exitcode = true,
parser = require('lint.parser').from_errorformat(efm, {
source = 'sphinx-lint',
severity = vim.diagnostic.severity.WARN,
}),
}
35 changes: 35 additions & 0 deletions spec/sphinx-lint_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
describe('linter.sphinx-lint', function()
it('can parse the output', function()
local parser = require('lint.linters.sphinx-lint').parser
local bufnr = vim.uri_to_bufnr('file:///foo.rst')
local result = parser([[
/foo.rst:42: trailing whitespace (trailing-whitespace)
/foo.rst:420: missing space before default role: beep boop (missing-space-before-default-role)
]], bufnr)

assert.are.same(2, #result)

local expected_error = {
source = 'sphinx-lint',
message = 'trailing whitespace (trailing-whitespace)',
lnum = 41,
col = 0,
end_lnum = 41,
end_col = 0,
severity = vim.diagnostic.severity.WARN,
}
assert.are.same(expected_error, result[1])

expected_error = {
source = 'sphinx-lint',
message = 'missing space before default role: beep boop (missing-space-before-default-role)',
lnum = 419,
col = 0,
end_lnum = 419,
end_col = 0,
severity = vim.diagnostic.severity.WARN,
}
assert.are.same(expected_error, result[2])

end)
end)

0 comments on commit 8e9562d

Please sign in to comment.