Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add protolint linter and fixer #2911

Merged
merged 1 commit into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions ale_linters/proto/protolint.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
" Author: Yohei Yoshimuta <[email protected]>
" Description: run the protolint for Protocol Buffer files

call ale#Set('proto_protolint_executable', 'protolint')
call ale#Set('proto_protolint_config', '')

function! ale_linters#proto#protolint#GetCommand(buffer) abort
let l:config = ale#Var(a:buffer, 'proto_protolint_config')

return '%e lint'
\ . (!empty(l:config) ? ' -config_path=' . ale#Escape(l:config) : '')
\ . ' -reporter=unix'
\ . ' %s'
endfunction

call ale#linter#Define('proto', {
\ 'name': 'protolint',
\ 'lint_file': 1,
\ 'output_stream': 'stderr',
\ 'executable': {b -> ale#Var(b, 'proto_protolint_executable')},
\ 'command': function('ale_linters#proto#protolint#GetCommand'),
\ 'callback': 'ale#handlers#unix#HandleAsError',
\})

5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['json'],
\ 'description': 'Fix JSON files with jq.',
\ },
\ 'protolint': {
\ 'function': 'ale#fixers#protolint#Fix',
\ 'suggested_filetypes': ['proto'],
\ 'description': 'Fix Protocol Buffer files with protolint.',
\ },
\ 'perltidy': {
\ 'function': 'ale#fixers#perltidy#Fix',
\ 'suggested_filetypes': ['perl'],
Expand Down
26 changes: 26 additions & 0 deletions autoload/ale/fixers/protolint.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
" Author: Yohei Yoshimuta <[email protected]>
" Description: Integration of protolint with ALE.

call ale#Set('proto_protolint_executable', 'protolint')
call ale#Set('proto_protolint_config', '')

function! ale#fixers#protolint#GetExecutable(buffer) abort
let l:executable = ale#Var(a:buffer, 'proto_protolint_executable')

return ale#Escape(l:executable)
endfunction

function! ale#fixers#protolint#Fix(buffer) abort
let l:executable = ale#fixers#protolint#GetExecutable(a:buffer)
let l:config = ale#Var(a:buffer, 'proto_protolint_config')

return {
\ 'command': l:executable
\ . (!empty(l:config) ? ' -config_path=' . ale#Escape(l:config) : '')
\ . ' -fix'
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction


37 changes: 32 additions & 5 deletions doc/ale-proto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ ALE Proto Integration *ale-proto-options
===============================================================================
Integration Information

Linting of `.proto` files requires that the `protoc` binary is installed in the
system path and that the `protoc-gen-lint` plugin for the `protoc` binary is also
installed.

To enable `.proto` file linting, update |g:ale_linters| as appropriate:
>
" Enable linter for .proto files
let g:ale_linters = {'proto': ['protoc-gen-lint']}
let g:ale_linters = {'proto': ['protoc-gen-lint', 'protolint']}

To enable `.proto` file fixing, update |g:ale_fixers| as appropriate:
>
" Enable linter for .proto files
let b:ale_fixers = {'proto': ['protolint']}
<
===============================================================================
protoc-gen-lint *ale-proto-protoc-gen-lint*
Expand All @@ -29,5 +30,31 @@ g:ale_proto_protoc_gen_lint_options *g:ale_proto_protoc_gen_lint_options*
directory of the linted file is always passed as an include path with '-I'
before any user-supplied options.

===============================================================================
protolint *ale-proto-protolint*

The linter is a pluggable tool that doesn't depend on the `protoc` binary.
This supports both linting and fixing.
Make sure the binary is available in the system path, or set
ale_proto_protolint_executable.
Note that the binary with v0.22.0 or above is supported.

g:ale_proto_protolint_executable *g:ale_proto_protolint_executable*

Type: |String|
Default: 'protolint'

This variable can be changed to modify the executable used for protolint.

g:ale_proto_protolint_config *g:ale_proto_protolint_config*

Type: |String|
Default: `''`

A path to a protolint configuration file.

The path to the configuration file can be an absolute path or a relative
path. ALE will search for the relative path in parent directories.

===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ Notes:
* `swipl`
* proto
* `protoc-gen-lint`
* `protolint`
* Pug
* `pug-lint`
* Puppet
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2487,6 +2487,7 @@ documented in additional help files.
swipl.................................|ale-prolog-swipl|
proto...................................|ale-proto-options|
protoc-gen-lint.......................|ale-proto-protoc-gen-lint|
protolint.............................|ale-proto-protolint|
pug.....................................|ale-pug-options|
puglint...............................|ale-pug-puglint|
puppet..................................|ale-puppet-options|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ formatting.
* [swipl](https://github.com/SWI-Prolog/swipl-devel)
* proto
* [protoc-gen-lint](https://github.com/ckaznocha/protoc-gen-lint)
* [protolint](https://github.com/yoheimuta/protolint)
* Pug
* [pug-lint](https://github.com/pugjs/pug-lint)
* Puppet
Expand Down
24 changes: 24 additions & 0 deletions test/command_callback/test_protolint_command_callback.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Before:
call ale#assert#SetUpLinterTest('proto', 'protolint')
call ale#test#SetFilename('test.proto')

After:
call ale#assert#TearDownLinterTest()

Execute(The default command should be correct):
AssertLinter 'protolint',
\ ale#Escape('protolint')
\ . ' lint'
\ . ' -reporter=unix'
\ . ' %s'

Execute(The callback should include any additional options):
let b:ale_proto_protolint_executable = '/tmp/protolint'
let b:ale_proto_protolint_config = '/tmp/protolint.yaml'

AssertLinter '/tmp/protolint',
\ ale#Escape('/tmp/protolint')
\ . ' lint'
\ . ' -config_path=' . ale#Escape('/tmp/protolint.yaml')
\ . ' -reporter=unix'
\ . ' %s'
28 changes: 28 additions & 0 deletions test/fixers/test_protolint_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Before:
call ale#assert#SetUpFixerTest('proto', 'protolint')
call ale#test#SetFilename('test.proto')

After:
call ale#assert#TearDownFixerTest()

Execute(The default command should be correct):
AssertFixer
\ {
\ 'command': ale#Escape('protolint')
\ . ' -fix'
\ . ' %t',
\ 'read_temporary_file': 1,
\ }

Execute(The callback should include any additional options):
let b:ale_proto_protolint_executable = '/tmp/protolint'
let b:ale_proto_protolint_config = '/tmp/protolint.yaml'

AssertFixer
\ {
\ 'command': ale#Escape('/tmp/protolint')
\ . ' -config_path=' . ale#Escape('/tmp/protolint.yaml')
\ . ' -fix'
\ . ' %t',
\ 'read_temporary_file': 1,
\ }