summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2021-03-19 22:29:06 +0000
committerw0rp <devw0rp@gmail.com>2021-03-19 22:29:06 +0000
commit3838ae118d8f05fa1b1be7952a1c8aa3055d6728 (patch)
treecd4c7ce2c78092b348862b5cc1b1617286a8ffbe
parent8319e0f8c7e11a6c5f6aa58fb7669f6ccb2651df (diff)
downloadale-3838ae118d8f05fa1b1be7952a1c8aa3055d6728.zip
Add desktop-file-validate
-rw-r--r--ale_linters/desktop/desktop_file_validate.vim31
-rw-r--r--doc/ale-desktop.txt21
-rw-r--r--doc/ale-supported-languages-and-tools.txt2
-rw-r--r--doc/ale.txt2
-rw-r--r--supported-tools.md2
-rw-r--r--test/command_callback/test_desktop_file_validate.vader15
-rw-r--r--test/handler/test_desktop_file_validate_handler.vader26
7 files changed, 99 insertions, 0 deletions
diff --git a/ale_linters/desktop/desktop_file_validate.vim b/ale_linters/desktop/desktop_file_validate.vim
new file mode 100644
index 00000000..5a97d315
--- /dev/null
+++ b/ale_linters/desktop/desktop_file_validate.vim
@@ -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',
+\})
diff --git a/doc/ale-desktop.txt b/doc/ale-desktop.txt
new file mode 100644
index 00000000..62269e9c
--- /dev/null
+++ b/doc/ale-desktop.txt
@@ -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:
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 2e7d2f77..26e91e5c 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -126,6 +126,8 @@ Notes:
* `dartanalyzer`!!
* `dartfmt`!!
* `language_server`
+* desktop
+ * `desktop-file-validate`
* Dhall
* `dhall-format`
* `dhall-freeze`
diff --git a/doc/ale.txt b/doc/ale.txt
index 36e02d54..63086611 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2697,6 +2697,8 @@ documented in additional help files.
analysis_server.......................|ale-dart-analysis_server|
dartanalyzer..........................|ale-dart-dartanalyzer|
dartfmt...............................|ale-dart-dartfmt|
+ desktop.................................|ale-desktop-options|
+ desktop-file-validate.................|ale-desktop-desktop-file-validate|
dhall...................................|ale-dhall-options|
dhall-format..........................|ale-dhall-format|
dhall-freeze..........................|ale-dhall-freeze|
diff --git a/supported-tools.md b/supported-tools.md
index b73d4607..4c65a324 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -135,6 +135,8 @@ formatting.
* [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)
* [language_server](https://github.com/natebosch/dart_language_server)
+* desktop
+ * [desktop-file-validate](https://www.freedesktop.org/wiki/Software/desktop-file-utils/)
* Dhall
* [dhall-format](https://github.com/dhall-lang/dhall-lang)
* [dhall-freeze](https://github.com/dhall-lang/dhall-lang)
diff --git a/test/command_callback/test_desktop_file_validate.vader b/test/command_callback/test_desktop_file_validate.vader
new file mode 100644
index 00000000..4a49057b
--- /dev/null
+++ b/test/command_callback/test_desktop_file_validate.vader
@@ -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'
diff --git a/test/handler/test_desktop_file_validate_handler.vader b/test/handler/test_desktop_file_validate_handler.vader
new file mode 100644
index 00000000..88163433
--- /dev/null
+++ b/test/handler/test_desktop_file_validate_handler.vader
@@ -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',
+ \ ])