feat: Add protolint as linter and fixer (#2911)

This commit is contained in:
yohei yoshimuta 2021-04-09 22:16:23 +09:00 committed by GitHub
parent f0887d3e61
commit cec9954d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 142 additions and 5 deletions

View File

@ -0,0 +1,24 @@
" Author: Yohei Yoshimuta <yoheimuta@gmail.com>
" 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',
\})

View File

@ -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'],

View File

@ -0,0 +1,26 @@
" Author: Yohei Yoshimuta <yoheimuta@gmail.com>
" 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

View File

@ -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:

View File

@ -385,6 +385,7 @@ Notes:
* `swipl`
* proto
* `protoc-gen-lint`
* `protolint`
* Pug
* `pug-lint`
* Puppet

View File

@ -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|

View File

@ -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

View File

@ -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'

View File

@ -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,
\ }