From 8e9562de7261e5b862c631958df616e1a65552cd Mon Sep 17 00:00:00 2001 From: Antonin Godard Date: Sun, 17 Nov 2024 13:26:59 +0100 Subject: [PATCH] Add sphinx-lint support This adds support for sphinx-lint, the linter provided by Sphinx here: https://github.com/sphinx-contrib/sphinx-lint Signed-off-by: Antonin Godard --- README.md | 2 ++ lua/lint/linters/sphinx-lint.lua | 12 +++++++++++ spec/sphinx-lint_spec.lua | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 lua/lint/linters/sphinx-lint.lua create mode 100644 spec/sphinx-lint_spec.lua diff --git a/README.md b/README.md index 258ea0eb..b86dc83f 100644 --- a/README.md +++ b/README.md @@ -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` | @@ -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 diff --git a/lua/lint/linters/sphinx-lint.lua b/lua/lint/linters/sphinx-lint.lua new file mode 100644 index 00000000..0fe30c27 --- /dev/null +++ b/lua/lint/linters/sphinx-lint.lua @@ -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, + }), +} diff --git a/spec/sphinx-lint_spec.lua b/spec/sphinx-lint_spec.lua new file mode 100644 index 00000000..2aae92ab --- /dev/null +++ b/spec/sphinx-lint_spec.lua @@ -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)