Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

feat(diagnostics): add cmake_lint to go alongside cmake_format #1067

Merged
Merged
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
3 changes: 3 additions & 0 deletions lua/null-ls/builtins/_meta/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ return {
clj_kondo = {
filetypes = { "clojure" }
},
cmake_lint = {
filetypes = { "cmake" }
},
codespell = {
filetypes = {}
},
Expand Down
2 changes: 1 addition & 1 deletion lua/null-ls/builtins/_meta/filetype_map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ return {
formatting = { "cljstyle", "zprint" }
},
cmake = {
formatting = { "cmake_format", "gersemi" }
formatting = { "cmake_format", "cmake_lint", "gersemi" }
},
cpp = {
diagnostics = { "cppcheck", "gccdiag" },
Expand Down
36 changes: 36 additions & 0 deletions lua/null-ls/builtins/diagnostics/cmake_lint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
local h = require("null-ls.helpers")
local methods = require("null-ls.methods")

return h.make_builtin({
name = "cmake_lint",
meta = {
url = "https://github.com/cheshirekow/cmake_format",
description = "Check cmake listfiles for style violations, common mistakes, and anti-patterns.",
},
method = methods.internal.DIAGNOSTICS_ON_SAVE,
filetypes = { "cmake" },
generator_opts = {
command = "cmake-lint",
args = {
"$FILENAME",
},
format = "line",
to_stdin = false,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So as currently written, the linter will read the file on disk, which means that diagnostics won't update properly until the file is actually written. It does seem that cmake-lint has stdin support, but this PR seems to imply that it doesn't currently work.

Using stdin would be ideal, but other options that we have are writing the buffer's contents to a temp file or only generating diagnostics on save.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the feedback. Personal preference would be to switch to DIAGNOSTICS_ON_SAVE. Judging by the age of that PR in cmake_format, stdin may not be fixed soon.

from_stderr = true,
on_output = h.diagnostics.from_pattern(
[[(%d+),(%d+): %[((%w)[%d]+)%] (.+)]],
{ "row", "col", "code", "severity", "message" },
{
severities = {
E = h.diagnostics.severities["error"],
W = h.diagnostics.severities["warning"],
C = h.diagnostics.severities["information"],
R = h.diagnostics.severities["information"],
I = h.diagnostics.severities["information"],
},
offsets = { col = 1 },
}
),
},
factory = h.generator_factory,
})