Check user systemd unit files with systemd-analyze

This commit is contained in:
w0rp 2021-03-14 23:34:38 +00:00
parent b45ee8ec6c
commit f43e4abc88
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
7 changed files with 77 additions and 1 deletions

View File

@ -0,0 +1,25 @@
function! ale_linters#systemd#systemd_analyze#Handle(buffer, lines) abort
let l:re = '\v(.+):([0-9]+): (.+)'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:re)
call add(l:output, {
\ 'lnum': str2nr(l:match[2]),
\ 'col': 1,
\ 'type': 'W',
\ 'text': l:match[3],
\})
endfor
return l:output
endfunction
call ale#linter#Define('systemd', {
\ 'name': 'systemd_analyze',
\ 'aliases': ['systemd-analyze'],
\ 'executable': 'systemd-analyze',
\ 'command': 'SYSTEMD_LOG_COLOR=0 %e --user verify %s',
\ 'callback': 'ale_linters#systemd#systemd_analyze#Handle',
\ 'output_stream': 'both',
\ 'lint_file': 1,
\})

View File

@ -167,7 +167,7 @@ Notes:
* Git Commit Messages
* `gitlint`
* GLSL
* glslang
* `glslang`
* `glslls`
* Go
* `bingo`
@ -492,6 +492,8 @@ Notes:
* `sourcekit-lsp`
* `swiftformat`
* `swiftlint`
* systemd
* `systemd-analyze`!!
* Tcl
* `nagelfar`!!
* Terraform
@ -562,3 +564,6 @@ Notes:
* `yang-lsp`
* Zig
* `zls`
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

14
doc/ale-systemd.txt Normal file
View File

@ -0,0 +1,14 @@
===============================================================================
ALE systemd Integration *ale-systemd-options*
===============================================================================
systemd-analyze *ale-systemd-analyze*
ALE supports checking user systemd units with `systemd-analyze --user verify`
Checks will only work with user unit files in their proper location. There
aren't any options, and checks can only run after saving the file.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -3010,6 +3010,8 @@ documented in additional help files.
stylelint.............................|ale-sugarss-stylelint|
swift...................................|ale-swift-options|
sourcekitlsp..........................|ale-swift-sourcekitlsp|
systemd.................................|ale-systemd-options|
systemd-analyze.......................|ale-systemd-analyze|
tcl.....................................|ale-tcl-options|
nagelfar..............................|ale-tcl-nagelfar|
terraform...............................|ale-terraform-options|

View File

@ -501,6 +501,8 @@ formatting.
* [sourcekit-lsp](https://github.com/apple/sourcekit-lsp)
* [swiftformat](https://github.com/nicklockwood/SwiftFormat)
* [swiftlint](https://github.com/realm/SwiftLint)
* systemd
* [systemd-analyze](https://www.freedesktop.org/software/systemd/man/systemd-analyze.html) :floppy_disk:
* Tcl
* [nagelfar](http://nagelfar.sourceforge.net) :floppy_disk:
* Terraform

View File

@ -0,0 +1,9 @@
Before:
call ale#assert#SetUpLinterTest('systemd', 'systemd_analyze')
After:
call ale#assert#TearDownLinterTest()
Execute(The default command should be correct):
AssertLinter 'systemd-analyze',
\ 'SYSTEMD_LOG_COLOR=0 ' . ale#Escape('systemd-analyze') . ' --user verify %s'

View File

@ -0,0 +1,19 @@
Before:
runtime ale_linters/systemd/systemd_analyze.vim
After:
call ale#linter#Reset()
Execute(The systemd-analyze handler should parse lines correctly):
AssertEqual
\ [
\ {
\ 'lnum': 9,
\ 'col': 1,
\ 'type': 'W',
\ 'text': 'Unknown key name ''Wat'' in section ''Service'', ignoring.',
\ },
\ ],
\ ale_linters#systemd#systemd_analyze#Handle(bufnr(''), [
\ '/home/user/.config/systemd/user/foo.service:9: Unknown key name ''Wat'' in section ''Service'', ignoring.',
\ ])