mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-08 13:34:46 +08:00
feat: Add protolint as linter and fixer (#2911)
This commit is contained in:
24
ale_linters/proto/protolint.vim
Normal file
24
ale_linters/proto/protolint.vim
Normal 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',
|
||||||
|
\})
|
||||||
|
|
||||||
@@ -346,6 +346,11 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['json'],
|
\ 'suggested_filetypes': ['json'],
|
||||||
\ 'description': 'Fix JSON files with jq.',
|
\ 'description': 'Fix JSON files with jq.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'protolint': {
|
||||||
|
\ 'function': 'ale#fixers#protolint#Fix',
|
||||||
|
\ 'suggested_filetypes': ['proto'],
|
||||||
|
\ 'description': 'Fix Protocol Buffer files with protolint.',
|
||||||
|
\ },
|
||||||
\ 'perltidy': {
|
\ 'perltidy': {
|
||||||
\ 'function': 'ale#fixers#perltidy#Fix',
|
\ 'function': 'ale#fixers#perltidy#Fix',
|
||||||
\ 'suggested_filetypes': ['perl'],
|
\ 'suggested_filetypes': ['perl'],
|
||||||
|
|||||||
26
autoload/ale/fixers/protolint.vim
Normal file
26
autoload/ale/fixers/protolint.vim
Normal 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
|
||||||
|
|
||||||
|
|
||||||
@@ -5,14 +5,15 @@ ALE Proto Integration *ale-proto-options
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
Integration Information
|
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:
|
To enable `.proto` file linting, update |g:ale_linters| as appropriate:
|
||||||
>
|
>
|
||||||
" Enable linter for .proto files
|
" 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*
|
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'
|
directory of the linted file is always passed as an include path with '-I'
|
||||||
before any user-supplied options.
|
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:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
|||||||
@@ -385,6 +385,7 @@ Notes:
|
|||||||
* `swipl`
|
* `swipl`
|
||||||
* proto
|
* proto
|
||||||
* `protoc-gen-lint`
|
* `protoc-gen-lint`
|
||||||
|
* `protolint`
|
||||||
* Pug
|
* Pug
|
||||||
* `pug-lint`
|
* `pug-lint`
|
||||||
* Puppet
|
* Puppet
|
||||||
|
|||||||
@@ -2918,6 +2918,7 @@ documented in additional help files.
|
|||||||
swipl.................................|ale-prolog-swipl|
|
swipl.................................|ale-prolog-swipl|
|
||||||
proto...................................|ale-proto-options|
|
proto...................................|ale-proto-options|
|
||||||
protoc-gen-lint.......................|ale-proto-protoc-gen-lint|
|
protoc-gen-lint.......................|ale-proto-protoc-gen-lint|
|
||||||
|
protolint.............................|ale-proto-protolint|
|
||||||
pug.....................................|ale-pug-options|
|
pug.....................................|ale-pug-options|
|
||||||
puglint...............................|ale-pug-puglint|
|
puglint...............................|ale-pug-puglint|
|
||||||
puppet..................................|ale-puppet-options|
|
puppet..................................|ale-puppet-options|
|
||||||
|
|||||||
@@ -394,6 +394,7 @@ formatting.
|
|||||||
* [swipl](https://github.com/SWI-Prolog/swipl-devel)
|
* [swipl](https://github.com/SWI-Prolog/swipl-devel)
|
||||||
* proto
|
* proto
|
||||||
* [protoc-gen-lint](https://github.com/ckaznocha/protoc-gen-lint)
|
* [protoc-gen-lint](https://github.com/ckaznocha/protoc-gen-lint)
|
||||||
|
* [protolint](https://github.com/yoheimuta/protolint)
|
||||||
* Pug
|
* Pug
|
||||||
* [pug-lint](https://github.com/pugjs/pug-lint)
|
* [pug-lint](https://github.com/pugjs/pug-lint)
|
||||||
* Puppet
|
* Puppet
|
||||||
|
|||||||
24
test/command_callback/test_protolint_command_callback.vader
Normal file
24
test/command_callback/test_protolint_command_callback.vader
Normal 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'
|
||||||
28
test/fixers/test_protolint_fixer_callback.vader
Normal file
28
test/fixers/test_protolint_fixer_callback.vader
Normal 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,
|
||||||
|
\ }
|
||||||
Reference in New Issue
Block a user