1 |
commit: 8abf42d2035374df1c87cb1b26039393c807ddd5 |
2 |
Author: Anna Vyalkova <cyber+gentoo <AT> sysrq <DOT> in> |
3 |
AuthorDate: Sat Jan 14 15:44:39 2023 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Feb 1 11:03:43 2023 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gentoo-syntax.git/commit/?id=8abf42d2 |
7 |
|
8 |
pkgcheck: add new ALE linter |
9 |
|
10 |
Signed-off-by: Anna Vyalkova <cyber+gentoo <AT> sysrq.in> |
11 |
Closes: https://github.com/gentoo/gentoo-syntax/pull/52 |
12 |
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> |
13 |
|
14 |
Makefile | 1 + |
15 |
README.rst | 15 +++++++-- |
16 |
ale_linters/ebuild/pkgcheck.vim | 68 +++++++++++++++++++++++++++++++++++++++++ |
17 |
3 files changed, 82 insertions(+), 2 deletions(-) |
18 |
|
19 |
diff --git a/Makefile b/Makefile |
20 |
index 9d2d016..7e65de0 100644 |
21 |
--- a/Makefile |
22 |
+++ b/Makefile |
23 |
@@ -3,6 +3,7 @@ |
24 |
PREFIX = ${HOME}/.vim/ |
25 |
|
26 |
files = $(wildcard \ |
27 |
+ ale_linters/* \ |
28 |
doc/* \ |
29 |
ftdetect/* \ |
30 |
ftplugin/* \ |
31 |
|
32 |
diff --git a/README.rst b/README.rst |
33 |
index 6617aa4..5cb4009 100644 |
34 |
--- a/README.rst |
35 |
+++ b/README.rst |
36 |
@@ -11,8 +11,11 @@ Installing |
37 |
* Gentoo users: ``emerge app-vim/gentoo-syntax`` |
38 |
* Everyone else: ``make PREFIX=~/.vim/ install`` |
39 |
|
40 |
-This plugin also provides a syntax checker for ebuilds and eclasses. To enable |
41 |
-it, you need to install Syntastic_ and pkgcheck_ first:: |
42 |
+Syntastic |
43 |
+--------- |
44 |
+ |
45 |
+This plugin provides a syntax checker for ebuilds and eclasses. To enable it, |
46 |
+you need to install Syntastic_ and pkgcheck_ first:: |
47 |
|
48 |
# emerge app-vim/syntastic dev-util/pkgcheck |
49 |
|
50 |
@@ -29,6 +32,14 @@ and enable it for filetype "sh":: |
51 |
.. _Syntastic: https://github.com/vim-syntastic/syntastic |
52 |
.. _pkgcheck: https://github.com/pkgcore/pkgcheck |
53 |
|
54 |
+Asynchronous Lint Engine |
55 |
+------------------------ |
56 |
+ |
57 |
+A pkgcheck-based linter for ALE_ is also installed. It will be enabled |
58 |
+automatically if pkgcheck_ is installed, no manual action is required. |
59 |
+ |
60 |
+.. _ALE: https://github.com/dense-analysis/ale |
61 |
+ |
62 |
Bugs |
63 |
==== |
64 |
|
65 |
|
66 |
diff --git a/ale_linters/ebuild/pkgcheck.vim b/ale_linters/ebuild/pkgcheck.vim |
67 |
new file mode 100644 |
68 |
index 0000000..65b5537 |
69 |
--- /dev/null |
70 |
+++ b/ale_linters/ebuild/pkgcheck.vim |
71 |
@@ -0,0 +1,68 @@ |
72 |
+" Language: Gentoo Ebuilds/Eclasses |
73 |
+" Author: Anna Vyalkova <cyber+gentoo@×××××.in> |
74 |
+" Copyright: Copyright (c) 2023 Anna Vyalkova |
75 |
+" Licence: You may redistribute this under the same terms as Vim itself |
76 |
+" |
77 |
+" Asynchronous linter for ebuilds and eclasses powered by pkgcheck. |
78 |
+" Requires vim 8.0 or later. |
79 |
+" |
80 |
+ |
81 |
+call ale#Set('ebuild_pkgcheck_executable', 'pkgcheck') |
82 |
+call ale#Set('ebuild_pkgcheck_options', '') |
83 |
+ |
84 |
+function! ale_linters#ebuild#pkgcheck#Handle(buffer, lines) abort |
85 |
+ let l:output = ale#python#HandleTraceback(a:lines, 10) |
86 |
+ |
87 |
+ if !empty(l:output) |
88 |
+ return l:output |
89 |
+ endif |
90 |
+ |
91 |
+ let l:pkgcheck_type_to_ale_type = { |
92 |
+ \ 'error': 'E', |
93 |
+ \ 'info': 'I', |
94 |
+ \ 'style': 'W', |
95 |
+ \ 'warning': 'W', |
96 |
+ \} |
97 |
+ let l:pkgcheck_type_to_ale_sub_type = { |
98 |
+ \ 'style': 'style', |
99 |
+ \} |
100 |
+ |
101 |
+ let l:pattern = '\v^(\d*):([a-z]+):(\w+): (.*)$' |
102 |
+ for l:match in ale#util#GetMatches(a:lines, l:pattern) |
103 |
+ let l:lnum = str2nr(l:match[1]) |
104 |
+ let l:type = l:match[2] |
105 |
+ let l:code = l:match[3] |
106 |
+ let l:text = l:match[4] |
107 |
+ |
108 |
+ if l:lnum == 0 |
109 |
+ let l:lnum = str2nr(matchstr(l:text, '\m\<lines\? \zs\d\+\ze')) |
110 |
+ endif |
111 |
+ |
112 |
+ call add(l:output, { |
113 |
+ \ 'lnum': l:lnum, |
114 |
+ \ 'code': l:code, |
115 |
+ \ 'type': get(l:pkgcheck_type_to_ale_type, l:type, 'E'), |
116 |
+ \ 'sub_type': get(l:pkgcheck_type_to_ale_sub_type, l:type, ''), |
117 |
+ \ 'text': l:text, |
118 |
+ \}) |
119 |
+ endfor |
120 |
+ |
121 |
+ return l:output |
122 |
+endfunction |
123 |
+ |
124 |
+function! ale_linters#ebuild#pkgcheck#GetCommand(buffer) abort |
125 |
+ return '%e' |
126 |
+ \ . ' scan' |
127 |
+ \ . ale#Pad(ale#Var(a:buffer, 'ebuild_pkgcheck_options')) |
128 |
+ \ . ' -R FormatReporter' |
129 |
+ \ . ' --format "{lineno}:{level}:{name}: {desc}"' |
130 |
+ \ . ' %s' |
131 |
+endfunction |
132 |
+ |
133 |
+call ale#linter#Define('ebuild', { |
134 |
+\ 'name': 'pkgcheck', |
135 |
+\ 'executable': {buffer -> ale#Var(buffer, 'ebuild_pkgcheck_executable')}, |
136 |
+\ 'command': function('ale_linters#ebuild#pkgcheck#GetCommand'), |
137 |
+\ 'lint_file': 1, |
138 |
+\ 'callback': 'ale_linters#ebuild#pkgcheck#Handle', |
139 |
+\}) |