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

Commit

Permalink
feat(diagnostics): add cmake_lint to go alongside cmake_format (#1067)
Browse files Browse the repository at this point in the history
* feat(diagnostics): add cmake_lint to go alongside cmake_format

* Use diagnostics on save method
  • Loading branch information
mitchallain authored Sep 19, 2022
1 parent 97d497d commit aba04f5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
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 @@ -31,6 +31,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 = { "clang_check", "cppcheck", "cpplint", "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,
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,
})

0 comments on commit aba04f5

Please sign in to comment.