Add desktop-file-validate

This commit is contained in:
w0rp 2021-03-19 22:29:06 +00:00
parent 8319e0f8c7
commit 3838ae118d
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
7 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,31 @@
call ale#Set('desktop_desktop_file_validate_options', '')
" Example matches for pattern:
"
" foo.desktop: warning: key "TerminalOptions" in group ...
" foo.desktop: error: action "new-private-window" is defined, ...
let s:pattern = '\v^(.+): ([a-z]+): (.+)$'
function! ale_linters#desktop#desktop_file_validate#Handle(buffer, lines) abort
" The error format doesn't specify lines, so we can just put all of the
" errors on line 1.
return ale#util#MapMatches(a:lines, s:pattern, {match -> {
\ 'lnum': 1,
\ 'col': 1,
\ 'type': match[2] is? 'error' ? 'E' : 'W',
\ 'text': match[3],
\}})
endfunction
call ale#linter#Define('desktop', {
\ 'name': 'desktop_file_validate',
\ 'aliases': ['desktop-file-validate'],
\ 'executable': 'desktop-file-validate',
\ 'command': {b ->
\ '%e'
\ . ale#Pad(ale#Var(b, 'desktop_desktop_file_validate_options'))
\ . ' %t'
\ },
\ 'callback': 'ale_linters#desktop#desktop_file_validate#Handle',
\ 'output_stream': 'both',
\})

21
doc/ale-desktop.txt Normal file
View File

@ -0,0 +1,21 @@
===============================================================================
ALE desktop Integration *ale-desktop-options*
===============================================================================
desktop-file-validate *ale-desktop-desktop-file-validate*
ALE supports checking .desktop files with `desktop-file-validate.`
g:ale_desktop_desktop_file_validate_options
*g:ale_desktop_desktop_file_validate_options*
*b:ale_desktop_desktop_file_validate_options*
Type: |String|
Default: `''`
This variable can be changed to set options for `desktop-file-validate`,
such as `'--warn-kde'`.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -126,6 +126,8 @@ Notes:
* `dartanalyzer`!! * `dartanalyzer`!!
* `dartfmt`!! * `dartfmt`!!
* `language_server` * `language_server`
* desktop
* `desktop-file-validate`
* Dhall * Dhall
* `dhall-format` * `dhall-format`
* `dhall-freeze` * `dhall-freeze`

View File

@ -2697,6 +2697,8 @@ documented in additional help files.
analysis_server.......................|ale-dart-analysis_server| analysis_server.......................|ale-dart-analysis_server|
dartanalyzer..........................|ale-dart-dartanalyzer| dartanalyzer..........................|ale-dart-dartanalyzer|
dartfmt...............................|ale-dart-dartfmt| dartfmt...............................|ale-dart-dartfmt|
desktop.................................|ale-desktop-options|
desktop-file-validate.................|ale-desktop-desktop-file-validate|
dhall...................................|ale-dhall-options| dhall...................................|ale-dhall-options|
dhall-format..........................|ale-dhall-format| dhall-format..........................|ale-dhall-format|
dhall-freeze..........................|ale-dhall-freeze| dhall-freeze..........................|ale-dhall-freeze|

View File

@ -135,6 +135,8 @@ formatting.
* [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) :floppy_disk: * [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) :floppy_disk:
* [dartfmt](https://github.com/dart-lang/sdk/tree/master/utils/dartfmt) * [dartfmt](https://github.com/dart-lang/sdk/tree/master/utils/dartfmt)
* [language_server](https://github.com/natebosch/dart_language_server) * [language_server](https://github.com/natebosch/dart_language_server)
* desktop
* [desktop-file-validate](https://www.freedesktop.org/wiki/Software/desktop-file-utils/)
* Dhall * Dhall
* [dhall-format](https://github.com/dhall-lang/dhall-lang) * [dhall-format](https://github.com/dhall-lang/dhall-lang)
* [dhall-freeze](https://github.com/dhall-lang/dhall-lang) * [dhall-freeze](https://github.com/dhall-lang/dhall-lang)

View File

@ -0,0 +1,15 @@
Before:
call ale#assert#SetUpLinterTest('desktop', 'desktop_file_validate')
After:
call ale#assert#TearDownLinterTest()
Execute(The default command should be correct):
AssertLinter 'desktop-file-validate',
\ ale#Escape('desktop-file-validate') . ' %t'
Execute(Extra options should work):
let b:ale_desktop_desktop_file_validate_options = '--warn-kde'
AssertLinter 'desktop-file-validate',
\ ale#Escape('desktop-file-validate') . ' --warn-kde %t'

View File

@ -0,0 +1,26 @@
Before:
runtime ale_linters/desktop/desktop_file_validate.vim
After:
call ale#linter#Reset()
Execute(The desktop-file-validate handler should parse lines correctly):
AssertEqual
\ [
\ {
\ 'lnum': 1,
\ 'col': 1,
\ 'type': 'W',
\ 'text': 'key "TerminalOptions" in group "Desktop Entry" is deprecated',
\ },
\ {
\ 'lnum': 1,
\ 'col': 1,
\ 'type': 'E',
\ 'text': 'action "new-private-window" is defined, but there is no matching "Desktop Action new-private-window" group',
\ },
\ ],
\ ale_linters#desktop#desktop_file_validate#Handle(bufnr(''), [
\ 'foo.desktop: warning: key "TerminalOptions" in group "Desktop Entry" is deprecated',
\ 'foo.desktop: error: action "new-private-window" is defined, but there is no matching "Desktop Action new-private-window" group',
\ ])