aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Vyalkova <cyber+gentoo@sysrq.in>2023-01-14 20:44:39 +0500
committerMichał Górny <mgorny@gentoo.org>2023-02-01 12:03:43 +0100
commit8abf42d2035374df1c87cb1b26039393c807ddd5 (patch)
treeefbd2f0ba219958f28e1b8be937c997a36468af3
parentplugin/newebuild.vim: adjust dev-java template (diff)
downloadgentoo-syntax-6.tar.gz
gentoo-syntax-6.tar.bz2
gentoo-syntax-6.zip
pkgcheck: add new ALE linterv6
Signed-off-by: Anna Vyalkova <cyber+gentoo@sysrq.in> Closes: https://github.com/gentoo/gentoo-syntax/pull/52 Signed-off-by: Michał Górny <mgorny@gentoo.org>
-rw-r--r--Makefile1
-rw-r--r--README.rst15
-rw-r--r--ale_linters/ebuild/pkgcheck.vim68
3 files changed, 82 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 9d2d016..7e65de0 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,7 @@
PREFIX = ${HOME}/.vim/
files = $(wildcard \
+ ale_linters/* \
doc/* \
ftdetect/* \
ftplugin/* \
diff --git a/README.rst b/README.rst
index 6617aa4..5cb4009 100644
--- a/README.rst
+++ b/README.rst
@@ -11,8 +11,11 @@ Installing
* Gentoo users: ``emerge app-vim/gentoo-syntax``
* Everyone else: ``make PREFIX=~/.vim/ install``
-This plugin also provides a syntax checker for ebuilds and eclasses. To enable
-it, you need to install Syntastic_ and pkgcheck_ first::
+Syntastic
+---------
+
+This plugin provides a syntax checker for ebuilds and eclasses. To enable it,
+you need to install Syntastic_ and pkgcheck_ first::
# emerge app-vim/syntastic dev-util/pkgcheck
@@ -29,6 +32,14 @@ and enable it for filetype "sh"::
.. _Syntastic: https://github.com/vim-syntastic/syntastic
.. _pkgcheck: https://github.com/pkgcore/pkgcheck
+Asynchronous Lint Engine
+------------------------
+
+A pkgcheck-based linter for ALE_ is also installed. It will be enabled
+automatically if pkgcheck_ is installed, no manual action is required.
+
+.. _ALE: https://github.com/dense-analysis/ale
+
Bugs
====
diff --git a/ale_linters/ebuild/pkgcheck.vim b/ale_linters/ebuild/pkgcheck.vim
new file mode 100644
index 0000000..65b5537
--- /dev/null
+++ b/ale_linters/ebuild/pkgcheck.vim
@@ -0,0 +1,68 @@
+" Language: Gentoo Ebuilds/Eclasses
+" Author: Anna Vyalkova <cyber+gentoo@sysrq.in>
+" Copyright: Copyright (c) 2023 Anna Vyalkova
+" Licence: You may redistribute this under the same terms as Vim itself
+"
+" Asynchronous linter for ebuilds and eclasses powered by pkgcheck.
+" Requires vim 8.0 or later.
+"
+
+call ale#Set('ebuild_pkgcheck_executable', 'pkgcheck')
+call ale#Set('ebuild_pkgcheck_options', '')
+
+function! ale_linters#ebuild#pkgcheck#Handle(buffer, lines) abort
+ let l:output = ale#python#HandleTraceback(a:lines, 10)
+
+ if !empty(l:output)
+ return l:output
+ endif
+
+ let l:pkgcheck_type_to_ale_type = {
+ \ 'error': 'E',
+ \ 'info': 'I',
+ \ 'style': 'W',
+ \ 'warning': 'W',
+ \}
+ let l:pkgcheck_type_to_ale_sub_type = {
+ \ 'style': 'style',
+ \}
+
+ let l:pattern = '\v^(\d*):([a-z]+):(\w+): (.*)$'
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ let l:lnum = str2nr(l:match[1])
+ let l:type = l:match[2]
+ let l:code = l:match[3]
+ let l:text = l:match[4]
+
+ if l:lnum == 0
+ let l:lnum = str2nr(matchstr(l:text, '\m\<lines\? \zs\d\+\ze'))
+ endif
+
+ call add(l:output, {
+ \ 'lnum': l:lnum,
+ \ 'code': l:code,
+ \ 'type': get(l:pkgcheck_type_to_ale_type, l:type, 'E'),
+ \ 'sub_type': get(l:pkgcheck_type_to_ale_sub_type, l:type, ''),
+ \ 'text': l:text,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+function! ale_linters#ebuild#pkgcheck#GetCommand(buffer) abort
+ return '%e'
+ \ . ' scan'
+ \ . ale#Pad(ale#Var(a:buffer, 'ebuild_pkgcheck_options'))
+ \ . ' -R FormatReporter'
+ \ . ' --format "{lineno}:{level}:{name}: {desc}"'
+ \ . ' %s'
+endfunction
+
+call ale#linter#Define('ebuild', {
+\ 'name': 'pkgcheck',
+\ 'executable': {buffer -> ale#Var(buffer, 'ebuild_pkgcheck_executable')},
+\ 'command': function('ale_linters#ebuild#pkgcheck#GetCommand'),
+\ 'lint_file': 1,
+\ 'callback': 'ale_linters#ebuild#pkgcheck#Handle',
+\})