public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/gentoo-syntax:master commit in: ale_linters/ebuild/, /
@ 2023-02-01 11:03 Michał Górny
  0 siblings, 0 replies; only message in thread
From: Michał Górny @ 2023-02-01 11:03 UTC (permalink / raw
  To: gentoo-commits

commit:     8abf42d2035374df1c87cb1b26039393c807ddd5
Author:     Anna Vyalkova <cyber+gentoo <AT> sysrq <DOT> in>
AuthorDate: Sat Jan 14 15:44:39 2023 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Feb  1 11:03:43 2023 +0000
URL:        https://gitweb.gentoo.org/proj/gentoo-syntax.git/commit/?id=8abf42d2

pkgcheck: add new ALE linter

Signed-off-by: Anna Vyalkova <cyber+gentoo <AT> sysrq.in>
Closes: https://github.com/gentoo/gentoo-syntax/pull/52
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 Makefile                        |  1 +
 README.rst                      | 15 +++++++--
 ale_linters/ebuild/pkgcheck.vim | 68 +++++++++++++++++++++++++++++++++++++++++
 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',
+\})


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-01 11:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-01 11:03 [gentoo-commits] proj/gentoo-syntax:master commit in: ale_linters/ebuild/, / Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox