summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/proto/buf_lint.vim23
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/buf_format.vim12
-rw-r--r--doc/ale-proto.txt42
-rw-r--r--doc/ale-supported-languages-and-tools.txt2
-rw-r--r--doc/ale.txt2
-rw-r--r--supported-tools.md2
-rw-r--r--test/fixers/test_buf_format_fixer_callback.vader21
-rw-r--r--test/linter/test_buf_lint.vader22
-rw-r--r--test/test-files/proto/testfile.proto0
10 files changed, 129 insertions, 2 deletions
diff --git a/ale_linters/proto/buf_lint.vim b/ale_linters/proto/buf_lint.vim
new file mode 100644
index 00000000..e68494a7
--- /dev/null
+++ b/ale_linters/proto/buf_lint.vim
@@ -0,0 +1,23 @@
+" Author: Alex McKinney <alexmckinney01@gmail.com>
+" Description: Run buf lint.
+
+call ale#Set('proto_buf_lint_executable', 'buf')
+call ale#Set('proto_buf_lint_config', '')
+
+function! ale_linters#proto#buf_lint#GetCommand(buffer) abort
+ let l:config = ale#Var(a:buffer, 'proto_buf_lint_config')
+
+ return '%e lint'
+ \ . (!empty(l:config) ? ' --config=' . ale#Escape(l:config) : '')
+ \ . ' %s#include_package_files=true'
+endfunction
+
+call ale#linter#Define('proto', {
+\ 'name': 'buf_lint',
+\ 'aliases': ['buf-lint'],
+\ 'lint_file': 1,
+\ 'output_stream': 'stdout',
+\ 'executable': {b -> ale#Var(b, 'proto_buf_lint_executable')},
+\ 'command': function('ale_linters#proto#buf_lint#GetCommand'),
+\ 'callback': 'ale#handlers#unix#HandleAsError',
+\})
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index f9b94843..6ac617d8 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -37,6 +37,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['python'],
\ 'description': 'Fix PEP8 issues with black.',
\ },
+\ 'buf-format': {
+\ 'function': 'ale#fixers#buf_format#Fix',
+\ 'suggested_filetypes': ['proto'],
+\ 'description': 'Fix .proto files with buf format.',
+\ },
\ 'buildifier': {
\ 'function': 'ale#fixers#buildifier#Fix',
\ 'suggested_filetypes': ['bzl'],
diff --git a/autoload/ale/fixers/buf_format.vim b/autoload/ale/fixers/buf_format.vim
new file mode 100644
index 00000000..c2c156b7
--- /dev/null
+++ b/autoload/ale/fixers/buf_format.vim
@@ -0,0 +1,12 @@
+" Author: Alex McKinney <alexmckinney01@gmail.com>
+" Description: Run buf format.
+
+call ale#Set('proto_buf_format_executable', 'buf')
+
+function! ale#fixers#buf_format#Fix(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'proto_buf_format_executable')
+
+ return {
+ \ 'command': ale#Escape(l:executable) . ' format %t',
+ \}
+endfunction
diff --git a/doc/ale-proto.txt b/doc/ale-proto.txt
index 8ab56a14..a1bf1303 100644
--- a/doc/ale-proto.txt
+++ b/doc/ale-proto.txt
@@ -8,14 +8,52 @@ Integration Information
To enable `.proto` file linting, update |g:ale_linters| as appropriate:
>
" Enable linter for .proto files
- let g:ale_linters = {'proto': ['protoc-gen-lint', 'protolint']}
+ let g:ale_linters = {'proto': ['buf-lint', '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']}
+ let b:ale_fixers = {'proto': ['buf-format', 'protolint']}
<
===============================================================================
+buf-format *ale-proto-buf-format*
+
+ The formatter uses `buf`, a fully-featured Protobuf compiler that doesn't depend
+ on `protoc`. Make sure the `buf` binary is available in the system path, or
+ set ale_proto_buf_format_executable.
+
+g:ale_proto_buf_format_executable *g:ale_proto_buf_format_executable*
+
+ Type: |String|
+ Default: 'buf'
+
+ This variable can be changed to modify the executable used for buf.
+
+===============================================================================
+buf-lint *ale-proto-buf-lint*
+
+ The linter uses `buf`, a fully-featured Protobuf compiler that doesn't depend
+ on `protoc`. Make sure the `buf` binary is available in the system path, or
+ set ale_proto_buf_lint_executable.
+
+g:ale_proto_buf_lint_executable *g:ale_proto_buf_lint_executable*
+
+ Type: |String|
+ Default: 'buf'
+
+ This variable can be changed to modify the executable used for buf.
+
+g:ale_proto_buf_lint_config *g:ale_proto_buf_lint_config*
+
+ Type: |String|
+ Default: `''`
+
+ A path to a buf 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.
+
+===============================================================================
protoc-gen-lint *ale-proto-protoc-gen-lint*
The linter is a plugin for the `protoc` binary. As long as the binary resides
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 67efc6ec..f0ff29a7 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -430,6 +430,8 @@ Notes:
* Prolog
* `swipl`
* proto
+ * `buf-format`!!
+ * `buf-lint`!!
* `protoc-gen-lint`!!
* `protolint`!!
* Pug
diff --git a/doc/ale.txt b/doc/ale.txt
index 0250637c..96ecd5b8 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -3060,6 +3060,8 @@ documented in additional help files.
prolog..................................|ale-prolog-options|
swipl.................................|ale-prolog-swipl|
proto...................................|ale-proto-options|
+ buf-format............................|ale-proto-buf-format|
+ buf-lint..............................|ale-proto-buf-lint|
protoc-gen-lint.......................|ale-proto-protoc-gen-lint|
protolint.............................|ale-proto-protolint|
pug.....................................|ale-pug-options|
diff --git a/supported-tools.md b/supported-tools.md
index 491e7b96..3e9bc2f8 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -439,6 +439,8 @@ formatting.
* Prolog
* [swipl](https://github.com/SWI-Prolog/swipl-devel)
* proto
+ * [buf-format](https://github.com/bufbuild/buf) :floppy_disk:
+ * [buf-lint](https://github.com/bufbuild/buf) :floppy_disk:
* [protoc-gen-lint](https://github.com/ckaznocha/protoc-gen-lint) :floppy_disk:
* [protolint](https://github.com/yoheimuta/protolint) :floppy_disk:
* Pug
diff --git a/test/fixers/test_buf_format_fixer_callback.vader b/test/fixers/test_buf_format_fixer_callback.vader
new file mode 100644
index 00000000..ee484820
--- /dev/null
+++ b/test/fixers/test_buf_format_fixer_callback.vader
@@ -0,0 +1,21 @@
+Before:
+ Save g:ale_proto_buf_format_executable
+
+ " Use an invalid global executable, so we don't match it.
+ let g:ale_proto_buf_format_executable = 'xxxinvalid'
+
+ call ale#test#SetDirectory('/testplugin/test/fixers')
+
+After:
+ Restore
+
+ call ale#test#RestoreDirectory()
+
+Execute(The buf-format callback should return the correct default values):
+ call ale#test#SetFilename('../test-files/proto/testfile.proto')
+
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape('xxxinvalid') . ' format %t',
+ \ },
+ \ ale#fixers#buf_format#Fix(bufnr(''))
diff --git a/test/linter/test_buf_lint.vader b/test/linter/test_buf_lint.vader
new file mode 100644
index 00000000..7b8bb52c
--- /dev/null
+++ b/test/linter/test_buf_lint.vader
@@ -0,0 +1,22 @@
+Before:
+ call ale#assert#SetUpLinterTest('proto', 'buf_lint')
+ call ale#test#SetFilename('test.proto')
+
+After:
+ call ale#assert#TearDownLinterTest()
+
+Execute(The default command should be correct):
+ AssertLinter 'buf',
+ \ ale#Escape('buf')
+ \ . ' lint'
+ \ . ' %s#include_package_files=true'
+
+Execute(The callback should include any additional options):
+ let b:ale_proto_buf_lint_executable = '/tmp/buf'
+ let b:ale_proto_buf_lint_config = '/tmp/buf.yaml'
+
+ AssertLinter '/tmp/buf',
+ \ ale#Escape('/tmp/buf')
+ \ . ' lint'
+ \ . ' --config=' . ale#Escape('/tmp/buf.yaml')
+ \ . ' %s#include_package_files=true'
diff --git a/test/test-files/proto/testfile.proto b/test/test-files/proto/testfile.proto
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/test-files/proto/testfile.proto