Skip to content

Commit 4e54e67

Browse files
feat(diagnostics): Add kube-linter (#294)
* feat(diagnostics): Add kube-linter Adding https://github.com/stackrox/kube-linter which supports diagnostics for Helm and Kubernetes YAML files. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 103b092 commit 4e54e67

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

doc/BUILTINS.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,12 @@ local sources = {
473473
- Checkstyle only offers a jar file as download. It is recommended to put an executable wrapper script in
474474
your path.
475475
Example wrapper script:
476+
476477
```bash
477478
#!/usr/bin/env bash
478479
java -jar path/to/checkstyle.jar "$@"
479480
```
481+
480482
- Checkstyle needs a mandatory `-c` argument. Use `extra_args` to add yours. `extra_args` can also be a
481483
function to build more sophisticated logic.
482484

@@ -501,14 +503,16 @@ local sources = { null_ls.builtins.diagnostics.clazy }
501503

502504
- `clazy` needs a compilation database (`compile_commands.json`) to work. By default `clazy` will search for a compilation database in all parent folders of the input file.
503505
- If the compilation database is not in a parent folder, the `-p` option can be used to point to the corresponding folder (e.g. the projects build directory):
506+
504507
```lua
505508
local sources = {
506509
null_ls.builtins.diagnostics.clazy.with({
507510
extra_args = { "-p=$ROOT/build" },
508511
}),
509512
}
510513
```
511-
- Alternatively, `compile_commands.json` can be linked into the project's root directory. For more information see https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
514+
515+
- Alternatively, `compile_commands.json` can be linked into the project's root directory. For more information see <https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html>
512516
- `clazy` will be run only when files are saved to disk, so that `compile_commands.json` can be used.
513517

514518
### [clj_kondo](https://github.com/clj-kondo/clj-kondo)
@@ -1165,10 +1169,12 @@ local sources = {
11651169
- PMD only offers parameterized wrapper scripts as download. It is recommended to put an executable wrapper
11661170
script in your path.
11671171
Example wrapper script:
1172+
11681173
```bash
11691174
#!/usr/bin/env bash
11701175
path/to/pmd/bin/run.sh pmd "$@"
11711176
```
1177+
11721178
- PMD needs a mandatory `--rulesets`/`-rulesets`/`-R` argument. Use `extra_args` to add yours. `extra_args`
11731179
can also be a function to build more sophisticated logic.
11741180

@@ -2093,27 +2099,35 @@ local sources = { null_ls.builtins.formatting.blackd }
20932099
##### `hostname` (string)
20942100

20952101
Address to bind the server to. Defaults to localhost.
2102+
20962103
##### `port` (string)
20972104

20982105
Port to listen on. Defaults to 45484.
2106+
20992107
##### `line_length` (number)
21002108

21012109
Set how many characters per line to allow. Defaults to 88.
2110+
21022111
##### `skip_source_first_line` (boolean)
21032112

21042113
If set to true, the first line of the source code will be ignored. Defaults to false.
2114+
21052115
##### `skip_string_normalization` (boolean)
21062116

21072117
If set to true, no string normalization will be performed. Defaults to false.
2118+
21082119
##### `skip_magic_trailing_comma` (boolean)
21092120

21102121
If set to true, trailing commas will not be used as a reason to split lines. Defaults to false.
2122+
21112123
##### `preview` (boolean)
21122124

21132125
If set to true, experimental and potentially disruptive style changes will be used. Defaults to false.
2126+
21142127
##### `fast` (boolean)
21152128

21162129
If set to true, Black will not perform an AST safety check after formatting. Defaults to false.
2130+
21172131
##### `python_variant` (string)
21182132

21192133
If set to pyi, Black will format all input files like typing stubs regardless of the file extension. Otherwise, its value must correspond to a Python version or a set of comma-separated Python versions, optionally prefixed with py. (e.g. py3.5,py3.6). Defaults to empty string.
@@ -2964,6 +2978,7 @@ local sources = { null_ls.builtins.formatting.isortd }
29642978
##### `hostname` (string)
29652979

29662980
Address that the isortd server listens on. Defaults to localhost.
2981+
29672982
##### `port` (string)
29682983

29692984
Port that the isortd server listens on. Defaults to 47393.
@@ -3002,6 +3017,24 @@ local sources = { null_ls.builtins.formatting.just }
30023017
- Command: `just`
30033018
- Args: `{ "--fmt", "--unstable", "-f", "$FILENAME" }`
30043019

3020+
### [kube-linter](https://github.com/stackrox/kube-linter)
3021+
3022+
KubeLinter is a static analysis tool that checks Kubernetes YAML files and Helm charts to ensure
3023+
the applications represented in them adhere to best practices.
3024+
3025+
#### Usage
3026+
3027+
```lua
3028+
local sources = { null_ls.builtins.diagnostics.kube_linter }
3029+
```
3030+
3031+
#### Defaults
3032+
3033+
- Filetypes: `{ "helm", "yaml" }`
3034+
- Method: `diagnostics`
3035+
- Command: `kube-linter`
3036+
- Args: `{ "lint", "--format", "json" "$ROOT" }`
3037+
30053038
### [ktlint](https://ktlint.github.io/)
30063039

30073040
An anti-bikeshedding Kotlin linter with built-in formatter.

lua/null-ls/builtins/_meta/diagnostics.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ return {
9494
haml_lint = {
9595
filetypes = { "haml" }
9696
},
97+
kube_linter = {
98+
filetypes = { "helm", "yaml" }
99+
},
97100
ktlint = {
98101
filetypes = { "kotlin" }
99102
},

lua/null-ls/builtins/_meta/filetype_map.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ return {
208208
formatting = { "atlas_fmt", "hclfmt", "packer", "terragrunt_fmt" }
209209
},
210210
helm = {
211-
diagnostics = { "trivy" }
211+
diagnostics = { "trivy", "kube_linter" },
212212
},
213213
html = {
214214
diagnostics = { "markuplint", "tidy" },
@@ -497,7 +497,7 @@ return {
497497
formatting = { "tidy", "xmllint" }
498498
},
499499
yaml = {
500-
diagnostics = { "actionlint", "cfn_lint", "spectral", "vacuum", "yamllint" },
500+
diagnostics = { "actionlint", "cfn_lint", "spectral", "vacuum", "yamllint", "kube_linter" },
501501
formatting = { "prettier", "prettierd", "yamlfix", "yamlfmt" }
502502
},
503503
["yaml.ansible"] = {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
local null_ls = require("null-ls")
2+
local helpers = require("null-ls.helpers")
3+
4+
return helpers.make_builtin({
5+
name = "kube_linter",
6+
meta = {
7+
url = "https://github.com/stackrox/kube-linter",
8+
description = "KubeLinter is a static analysis tool that checks Kubernetes YAML files and Helm charts to ensure the applications represented in them adhere to best practices.",
9+
},
10+
method = null_ls.methods.DIAGNOSTICS,
11+
filetypes = { "helm", "yaml" },
12+
factory = helpers.generator_factory,
13+
generator_opts = {
14+
command = "kube-linter",
15+
args = {
16+
"lint",
17+
"--format",
18+
"json",
19+
"$ROOT",
20+
},
21+
from_stderr = false,
22+
ignore_stderr = true,
23+
multiple_files = true,
24+
format = "json",
25+
check_exit_code = function(c)
26+
return c <= 1
27+
end,
28+
on_output = function(params)
29+
local diags = {}
30+
for _, diag in ipairs(params.output.Reports) do
31+
table.insert(diags, {
32+
source = "kube-linter",
33+
code = diag.Check,
34+
message = diag.Diagnostic.Message .. "\n" .. diag.Remediation,
35+
severity = helpers.diagnostics.severities["error"],
36+
filename = diag.Object.Metadata.FilePath,
37+
})
38+
end
39+
return diags
40+
end,
41+
},
42+
})

0 commit comments

Comments
 (0)