mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-16 01:07:06 +08:00
Add a linter for Apache Thrift IDL files
This linter works by invoking the `thrift` compiler with the buffer contents and reporting any parser and code generation issues. The handler rolls its own output-matching loop because we have the (unfortunate) requirement of handling error output that spans multiple lines. Unit tests cover both the command callback and handler, and there is initial documentation for all of the option variables.
This commit is contained in:
61
test/command_callback/test_thrift_command_callback.vader
Normal file
61
test/command_callback/test_thrift_command_callback.vader
Normal file
@@ -0,0 +1,61 @@
|
||||
Before:
|
||||
Save g:ale_thrift_thrift_executable
|
||||
Save g:ale_thrift_thrift_generators
|
||||
Save g:ale_thrift_thrift_includes
|
||||
Save g:ale_thrift_thrift_options
|
||||
|
||||
unlet! b:ale_thrift_thrift_executable
|
||||
unlet! b:ale_thrift_thrift_generators
|
||||
unlet! b:ale_thrift_thrift_includes
|
||||
unlet! b:ale_thrift_thrift_options
|
||||
|
||||
function! GetCommand(buffer) abort
|
||||
call ale#engine#InitBufferInfo(a:buffer)
|
||||
let l:result = ale_linters#thrift#thrift#GetCommand(a:buffer)
|
||||
call ale#engine#Cleanup(a:buffer)
|
||||
return l:result
|
||||
endfunction
|
||||
|
||||
runtime ale_linters/thrift/thrift.vim
|
||||
|
||||
After:
|
||||
Restore
|
||||
delfunction GetCommand
|
||||
unlet! b:ale_thrift_thrift_executable
|
||||
unlet! b:ale_thrift_thrift_generators
|
||||
unlet! b:ale_thrift_thrift_includes
|
||||
unlet! b:ale_thrift_thrift_options
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The executable should be configurable):
|
||||
AssertEqual 'thrift', ale_linters#thrift#thrift#GetExecutable(bufnr(''))
|
||||
|
||||
let b:ale_thrift_thrift_executable = 'foobar'
|
||||
AssertEqual 'foobar', ale_linters#thrift#thrift#GetExecutable(bufnr(''))
|
||||
|
||||
Execute(The executable should be used in the command):
|
||||
Assert GetCommand(bufnr('%')) =~# "^'thrift'"
|
||||
|
||||
let b:ale_thrift_thrift_executable = 'foobar'
|
||||
Assert GetCommand(bufnr('%')) =~# "^'foobar'"
|
||||
|
||||
Execute(The list of generators should be configurable):
|
||||
Assert GetCommand(bufnr('%')) =~# '--gen cpp'
|
||||
|
||||
let b:ale_thrift_thrift_generators = ['java', 'py:dynamic']
|
||||
Assert GetCommand(bufnr('%')) =~# '--gen java --gen py:dynamic'
|
||||
|
||||
let b:ale_thrift_thrift_generators = []
|
||||
Assert GetCommand(bufnr('%')) =~# '--gen cpp'
|
||||
|
||||
Execute(The list of include paths should be configurable):
|
||||
Assert GetCommand(bufnr('%')) !~# '-I'
|
||||
|
||||
let b:ale_thrift_thrift_includes = ['included/path']
|
||||
Assert GetCommand(bufnr('%')) =~# '-I included/path'
|
||||
|
||||
Execute(The string of compiler options should be configurable):
|
||||
Assert GetCommand(bufnr('%')) =~# '-strict'
|
||||
|
||||
let b:ale_thrift_thrift_options = '-strict --allow-64bit-consts'
|
||||
Assert GetCommand(bufnr('%')) =~# '-strict --allow-64bit-consts'
|
||||
63
test/handler/test_thrift_handler.vader
Normal file
63
test/handler/test_thrift_handler.vader
Normal file
@@ -0,0 +1,63 @@
|
||||
Before:
|
||||
runtime ale_linters/thrift/thrift.vim
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The thrift handler should handle basic warnings and errors):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 17,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'W',
|
||||
\ 'text': 'The "byte" type is a compatibility alias for "i8". Use i8" to emphasize the signedness of this type.',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 20,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'W',
|
||||
\ 'text': 'Could not find include file include.thrift',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 83,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Enum FOO is already defined!',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#thrift#thrift#Handle(1, [
|
||||
\ '[WARNING:/path/filename.thrift:17] The "byte" type is a compatibility alias for "i8". Use i8" to emphasize the signedness of this type.',
|
||||
\ '[WARNING:/path/filename.thrift:20] Could not find include file include.thrift',
|
||||
\ '[FAILURE:/path/filename.thrift:83] Enum FOO is already defined!',
|
||||
\ ])
|
||||
|
||||
Execute(The thrift handler should handle multiline errors):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 75,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'This integer is too big: "11111111114213213453243"',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 76,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Implicit field keys are deprecated and not allowed with -strict',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 77,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'E',
|
||||
\ 'text': "Unknown error (last token was ';')",
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#thrift#thrift#Handle(1, [
|
||||
\ "[ERROR:/path/filename.thrift:75] (last token was '11111111114213213453243')",
|
||||
\ 'This integer is too big: "11111111114213213453243"',
|
||||
\ "[ERROR:/path/filename.thrift:76] (last token was ';')",
|
||||
\ 'Implicit field keys are deprecated and not allowed with -strict',
|
||||
\ "[ERROR:/path/filename.thrift:77] (last token was ';')",
|
||||
\ ])
|
||||
Reference in New Issue
Block a user