diff --git a/ale_linters/proto/protolint.vim b/ale_linters/proto/protolint.vim new file mode 100644 index 00000000..2754c7b6 --- /dev/null +++ b/ale_linters/proto/protolint.vim @@ -0,0 +1,24 @@ +" Author: Yohei Yoshimuta +" 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', +\}) + diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index c26d4da3..efc9ebe0 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -346,6 +346,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'], diff --git a/autoload/ale/fixers/protolint.vim b/autoload/ale/fixers/protolint.vim new file mode 100644 index 00000000..9b8e72f1 --- /dev/null +++ b/autoload/ale/fixers/protolint.vim @@ -0,0 +1,26 @@ +" Author: Yohei Yoshimuta +" 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 + + diff --git a/doc/ale-proto.txt b/doc/ale-proto.txt index 734e23d5..8ab56a14 100644 --- a/doc/ale-proto.txt +++ b/doc/ale-proto.txt @@ -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* @@ -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: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index e0e0a6a3..67dc971c 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -385,6 +385,7 @@ Notes: * `swipl` * proto * `protoc-gen-lint` + * `protolint` * Pug * `pug-lint` * Puppet diff --git a/doc/ale.txt b/doc/ale.txt index 682db80d..96069d5a 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2918,6 +2918,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| diff --git a/supported-tools.md b/supported-tools.md index da0222d1..ce408936 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -394,6 +394,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 diff --git a/test/command_callback/test_protolint_command_callback.vader b/test/command_callback/test_protolint_command_callback.vader new file mode 100644 index 00000000..4463b629 --- /dev/null +++ b/test/command_callback/test_protolint_command_callback.vader @@ -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' diff --git a/test/fixers/test_protolint_fixer_callback.vader b/test/fixers/test_protolint_fixer_callback.vader new file mode 100644 index 00000000..5a6931d7 --- /dev/null +++ b/test/fixers/test_protolint_fixer_callback.vader @@ -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, + \ }