Merge pull request #1268 from bbannier/master

Make it possible to inject flags of protoc invocation.
This commit is contained in:
w0rp 2018-01-12 20:43:43 +00:00 committed by GitHub
commit f6af75aac4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 5 deletions

View File

@ -1,12 +1,20 @@
" Author: Jeff Willette <jrwillette88@gmail.com>
" Description: run the protoc-gen-lint plugin for the protoc binary
call ale#Set('proto_protoc_gen_lint_options', '')
function! ale_linters#proto#protoc_gen_lint#GetCommand(buffer) abort
let l:dirname = expand('#' . a:buffer . ':p:h')
return 'protoc'
\ . ' -I ' . ale#Escape(l:dirname)
\ . ' --lint_out=. ' . '%s'
let l:options = ['-I ' . ale#Escape(l:dirname)]
if !empty(ale#Var(a:buffer, 'proto_protoc_gen_lint_options'))
let l:options += [ale#Var(a:buffer, 'proto_protoc_gen_lint_options')]
endif
let l:options += ['--lint_out=. ' . '%s']
return 'protoc' . ' ' . join(l:options)
endfunction
call ale#linter#Define('proto', {

View File

@ -20,5 +20,14 @@ protoc-gen-lint *ale-proto-protoc-gen-lint*
The linter is a plugin for the `protoc` binary. As long as the binary resides
in the system path, `protoc` will find it.
g:ale_proto_protoc_gen_lint_options *g:ale_proto_protoc_gen_lint_options*
Type: |String|
Default: `''`
This variable can be changed to modify flags given to protoc. Note that the
directory of the linted file is always passed as an include path with '-I'
before any user-supplied options.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -1,14 +1,21 @@
Before:
call ale#test#SetDirectory('/testplugin/test/command_callback')
call ale#test#SetFilename('test.proto')
After:
Restore
call ale#test#RestoreDirectory()
unlet! b:ale_proto_protoc_gen_lint_options
call ale#linter#Reset()
Execute(The default command should be correct):
AssertEqual
\ 'protoc' . ' -I ' . ale#Escape(getcwd()) . ' --lint_out=. ' . '%s',
\ ale_linters#proto#protoc_gen_lint#GetCommand(bufnr(''))
Execute(The callback should include any additional options):
let b:ale_proto_protoc_gen_lint_options = '--some-option'
AssertEqual
\ 'protoc' . ' -I ' . ale#Escape(getcwd()) . ' --some-option --lint_out=. ' . '%s',
\ ale_linters#proto#protoc_gen_lint#GetCommand(bufnr(''))