From 8abf42d2035374df1c87cb1b26039393c807ddd5 Mon Sep 17 00:00:00 2001 From: Anna Vyalkova Date: Sat, 14 Jan 2023 20:44:39 +0500 Subject: pkgcheck: add new ALE linter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Anna Vyalkova Closes: https://github.com/gentoo/gentoo-syntax/pull/52 Signed-off-by: Michał Górny --- Makefile | 1 + README.rst | 15 +++++++-- ale_linters/ebuild/pkgcheck.vim | 68 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 ale_linters/ebuild/pkgcheck.vim 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 +" 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\ ale#Var(buffer, 'ebuild_pkgcheck_executable')}, +\ 'command': function('ale_linters#ebuild#pkgcheck#GetCommand'), +\ 'lint_file': 1, +\ 'callback': 'ale_linters#ebuild#pkgcheck#Handle', +\}) -- cgit v1.2.3-65-gdbad