Skip to content

Commit cec9954

Browse files
authored
feat: Add protolint as linter and fixer (#2911)
1 parent f0887d3 commit cec9954

File tree

9 files changed

+142
-5
lines changed

9 files changed

+142
-5
lines changed

ale_linters/proto/protolint.vim

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
" Author: Yohei Yoshimuta <[email protected]>
2+
" Description: run the protolint for Protocol Buffer files
3+
4+
call ale#Set('proto_protolint_executable', 'protolint')
5+
call ale#Set('proto_protolint_config', '')
6+
7+
function! ale_linters#proto#protolint#GetCommand(buffer) abort
8+
let l:config = ale#Var(a:buffer, 'proto_protolint_config')
9+
10+
return '%e lint'
11+
\ . (!empty(l:config) ? ' -config_path=' . ale#Escape(l:config) : '')
12+
\ . ' -reporter=unix'
13+
\ . ' %s'
14+
endfunction
15+
16+
call ale#linter#Define('proto', {
17+
\ 'name': 'protolint',
18+
\ 'lint_file': 1,
19+
\ 'output_stream': 'stderr',
20+
\ 'executable': {b -> ale#Var(b, 'proto_protolint_executable')},
21+
\ 'command': function('ale_linters#proto#protolint#GetCommand'),
22+
\ 'callback': 'ale#handlers#unix#HandleAsError',
23+
\})
24+

autoload/ale/fix/registry.vim

+5
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ let s:default_registry = {
346346
\ 'suggested_filetypes': ['json'],
347347
\ 'description': 'Fix JSON files with jq.',
348348
\ },
349+
\ 'protolint': {
350+
\ 'function': 'ale#fixers#protolint#Fix',
351+
\ 'suggested_filetypes': ['proto'],
352+
\ 'description': 'Fix Protocol Buffer files with protolint.',
353+
\ },
349354
\ 'perltidy': {
350355
\ 'function': 'ale#fixers#perltidy#Fix',
351356
\ 'suggested_filetypes': ['perl'],

autoload/ale/fixers/protolint.vim

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
" Author: Yohei Yoshimuta <[email protected]>
2+
" Description: Integration of protolint with ALE.
3+
4+
call ale#Set('proto_protolint_executable', 'protolint')
5+
call ale#Set('proto_protolint_config', '')
6+
7+
function! ale#fixers#protolint#GetExecutable(buffer) abort
8+
let l:executable = ale#Var(a:buffer, 'proto_protolint_executable')
9+
10+
return ale#Escape(l:executable)
11+
endfunction
12+
13+
function! ale#fixers#protolint#Fix(buffer) abort
14+
let l:executable = ale#fixers#protolint#GetExecutable(a:buffer)
15+
let l:config = ale#Var(a:buffer, 'proto_protolint_config')
16+
17+
return {
18+
\ 'command': l:executable
19+
\ . (!empty(l:config) ? ' -config_path=' . ale#Escape(l:config) : '')
20+
\ . ' -fix'
21+
\ . ' %t',
22+
\ 'read_temporary_file': 1,
23+
\}
24+
endfunction
25+
26+

doc/ale-proto.txt

+32-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ ALE Proto Integration *ale-proto-options
55
===============================================================================
66
Integration Information
77

8-
Linting of `.proto` files requires that the `protoc` binary is installed in the
9-
system path and that the `protoc-gen-lint` plugin for the `protoc` binary is also
10-
installed.
11-
128
To enable `.proto` file linting, update |g:ale_linters| as appropriate:
139
>
1410
" Enable linter for .proto files
15-
let g:ale_linters = {'proto': ['protoc-gen-lint']}
11+
let g:ale_linters = {'proto': ['protoc-gen-lint', 'protolint']}
12+
13+
To enable `.proto` file fixing, update |g:ale_fixers| as appropriate:
14+
>
15+
" Enable linter for .proto files
16+
let b:ale_fixers = {'proto': ['protolint']}
1617
<
1718
===============================================================================
1819
protoc-gen-lint *ale-proto-protoc-gen-lint*
@@ -29,5 +30,31 @@ g:ale_proto_protoc_gen_lint_options *g:ale_proto_protoc_gen_lint_options*
2930
directory of the linted file is always passed as an include path with '-I'
3031
before any user-supplied options.
3132

33+
===============================================================================
34+
protolint *ale-proto-protolint*
35+
36+
The linter is a pluggable tool that doesn't depend on the `protoc` binary.
37+
This supports both linting and fixing.
38+
Make sure the binary is available in the system path, or set
39+
ale_proto_protolint_executable.
40+
Note that the binary with v0.22.0 or above is supported.
41+
42+
g:ale_proto_protolint_executable *g:ale_proto_protolint_executable*
43+
44+
Type: |String|
45+
Default: 'protolint'
46+
47+
This variable can be changed to modify the executable used for protolint.
48+
49+
g:ale_proto_protolint_config *g:ale_proto_protolint_config*
50+
51+
Type: |String|
52+
Default: `''`
53+
54+
A path to a protolint configuration file.
55+
56+
The path to the configuration file can be an absolute path or a relative
57+
path. ALE will search for the relative path in parent directories.
58+
3259
===============================================================================
3360
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

doc/ale-supported-languages-and-tools.txt

+1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ Notes:
385385
* `swipl`
386386
* proto
387387
* `protoc-gen-lint`
388+
* `protolint`
388389
* Pug
389390
* `pug-lint`
390391
* Puppet

doc/ale.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2918,6 +2918,7 @@ documented in additional help files.
29182918
swipl.................................|ale-prolog-swipl|
29192919
proto...................................|ale-proto-options|
29202920
protoc-gen-lint.......................|ale-proto-protoc-gen-lint|
2921+
protolint.............................|ale-proto-protolint|
29212922
pug.....................................|ale-pug-options|
29222923
puglint...............................|ale-pug-puglint|
29232924
puppet..................................|ale-puppet-options|

supported-tools.md

+1
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ formatting.
394394
* [swipl](https://github.com/SWI-Prolog/swipl-devel)
395395
* proto
396396
* [protoc-gen-lint](https://github.com/ckaznocha/protoc-gen-lint)
397+
* [protolint](https://github.com/yoheimuta/protolint)
397398
* Pug
398399
* [pug-lint](https://github.com/pugjs/pug-lint)
399400
* Puppet
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Before:
2+
call ale#assert#SetUpLinterTest('proto', 'protolint')
3+
call ale#test#SetFilename('test.proto')
4+
5+
After:
6+
call ale#assert#TearDownLinterTest()
7+
8+
Execute(The default command should be correct):
9+
AssertLinter 'protolint',
10+
\ ale#Escape('protolint')
11+
\ . ' lint'
12+
\ . ' -reporter=unix'
13+
\ . ' %s'
14+
15+
Execute(The callback should include any additional options):
16+
let b:ale_proto_protolint_executable = '/tmp/protolint'
17+
let b:ale_proto_protolint_config = '/tmp/protolint.yaml'
18+
19+
AssertLinter '/tmp/protolint',
20+
\ ale#Escape('/tmp/protolint')
21+
\ . ' lint'
22+
\ . ' -config_path=' . ale#Escape('/tmp/protolint.yaml')
23+
\ . ' -reporter=unix'
24+
\ . ' %s'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Before:
2+
call ale#assert#SetUpFixerTest('proto', 'protolint')
3+
call ale#test#SetFilename('test.proto')
4+
5+
After:
6+
call ale#assert#TearDownFixerTest()
7+
8+
Execute(The default command should be correct):
9+
AssertFixer
10+
\ {
11+
\ 'command': ale#Escape('protolint')
12+
\ . ' -fix'
13+
\ . ' %t',
14+
\ 'read_temporary_file': 1,
15+
\ }
16+
17+
Execute(The callback should include any additional options):
18+
let b:ale_proto_protolint_executable = '/tmp/protolint'
19+
let b:ale_proto_protolint_config = '/tmp/protolint.yaml'
20+
21+
AssertFixer
22+
\ {
23+
\ 'command': ale#Escape('/tmp/protolint')
24+
\ . ' -config_path=' . ale#Escape('/tmp/protolint.yaml')
25+
\ . ' -fix'
26+
\ . ' %t',
27+
\ 'read_temporary_file': 1,
28+
\ }

0 commit comments

Comments
 (0)