diff options
author | jiangzhi.xie <xiejiangzhi@gmail.com> | 2018-01-08 23:19:17 +0800 |
---|---|---|
committer | jiangzhi.xie <xiejiangzhi@gmail.com> | 2018-01-08 23:32:02 +0800 |
commit | 112fcf7dd57a077f70ae39bb03d192f5c832aa2e (patch) | |
tree | 7f869ba3afaec822893b7e0a2856877a05153158 | |
parent | f1747901cc00abb7becb64c02bfccad46b66ed21 (diff) | |
download | ale-112fcf7dd57a077f70ae39bb03d192f5c832aa2e.zip |
Add a luac linter for Lua
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | ale_linters/lua/luac.vim | 40 | ||||
-rw-r--r-- | doc/ale-lua.txt | 9 | ||||
-rw-r--r-- | doc/ale.txt | 3 | ||||
-rw-r--r-- | test/command_callback/test_luac_command_callback.vader | 16 | ||||
-rw-r--r-- | test/handler/test_luac_handler.vader | 36 | ||||
-rw-r--r-- | test/handler/test_luacheck_handler.vader (renamed from test/handler/test_lua_handler.vader) | 0 |
7 files changed, 104 insertions, 2 deletions
@@ -118,7 +118,7 @@ formatting. | LaTeX | [alex](https://github.com/wooorm/alex) !!, [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | | Less | [lessc](https://www.npmjs.com/package/less), [prettier](https://github.com/prettier/prettier), [stylelint](https://github.com/stylelint/stylelint) | | LLVM | [llc](https://llvm.org/docs/CommandGuide/llc.html) | -| Lua | [luacheck](https://github.com/mpeterv/luacheck) | +| Lua | [luac](https://www.lua.org/manual/5.1/luac.html), [luacheck](https://github.com/mpeterv/luacheck) | | Mail | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) | | Make | [checkmake](https://github.com/mrtazz/checkmake) | | Markdown | [alex](https://github.com/wooorm/alex) !!, [mdl](https://github.com/mivok/markdownlint), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [remark-lint](https://github.com/wooorm/remark-lint) !!, [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | diff --git a/ale_linters/lua/luac.vim b/ale_linters/lua/luac.vim new file mode 100644 index 00000000..4a6bb403 --- /dev/null +++ b/ale_linters/lua/luac.vim @@ -0,0 +1,40 @@ +" Author: Jon Xie https://github.com/xiejiangzhi +" Description: luac linter for lua files + +call ale#Set('lua_luac_executable', 'luac') + +function! ale_linters#lua#luac#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'lua_luac_executable') +endfunction + +function! ale_linters#lua#luac#GetCommand(buffer) abort + let l:executable = ale_linters#lua#luac#GetExecutable(a:buffer) + return ale#Escape(l:executable) . ' -p - ' +endfunction + +function! ale_linters#lua#luac#Handle(buffer, lines) abort + " Matches patterns line the following: + " + " luac: stdin:5: '=' expected near ')' + " luac: stdin:8: ')' expected (to close '(' at line 6) near '123' + let l:pattern = '\v^.*:(\d+): (.+)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'lnum': l:match[1] + 0, + \ 'type': 'E', + \ 'text': l:match[2], + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('lua', { +\ 'name': 'luac', +\ 'executable_callback': 'ale_linters#lua#luac#GetExecutable', +\ 'command_callback': 'ale_linters#lua#luac#GetCommand', +\ 'output_stream': 'stderr', +\ 'callback': 'ale_linters#lua#luac#Handle', +\}) diff --git a/doc/ale-lua.txt b/doc/ale-lua.txt index 74d6b94a..b6fab379 100644 --- a/doc/ale-lua.txt +++ b/doc/ale-lua.txt @@ -1,6 +1,15 @@ =============================================================================== ALE Lua Integration *ale-lua-options* +=============================================================================== +luac *ale-lua-luac* + +g:ale_lua_luac_executable *g:ale_lua_luac_executable* + *b:ale_lua_luac_executable* + Type: |String| + Default: `'luac'` + + This variable can be changed to change the path to luac. =============================================================================== luacheck *ale-lua-luacheck* diff --git a/doc/ale.txt b/doc/ale.txt index 25c1abe0..6cebbce6 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -125,6 +125,7 @@ CONTENTS *ale-contents* llvm..................................|ale-llvm-options| llc.................................|ale-llvm-llc| lua...................................|ale-lua-options| + luac................................|ale-lua-luac| luacheck............................|ale-lua-luacheck| markdown..............................|ale-markdown-options| write-good..........................|ale-markdown-write-good| @@ -323,7 +324,7 @@ Notes: * LaTeX (tex): `alex`!!, `chktex`, `lacheck`, `proselint`, `redpen`, `vale`, `write-good` * Less: `lessc`, `prettier`, `stylelint` * LLVM: `llc` -* Lua: `luacheck` +* Lua: `luac`, `luacheck` * Mail: `alex`!!, `proselint`, `vale` * Make: `checkmake` * Markdown: `alex`!!, `mdl`, `proselint`, `redpen`, `remark-lint`, `vale`, `write-good` diff --git a/test/command_callback/test_luac_command_callback.vader b/test/command_callback/test_luac_command_callback.vader new file mode 100644 index 00000000..f9eb4d3f --- /dev/null +++ b/test/command_callback/test_luac_command_callback.vader @@ -0,0 +1,16 @@ +Before: + runtime ale_linters/lua/luac.vim + +After: + call ale#linter#Reset() + +Execute(The default command should be correct): + AssertEqual ale#Escape('luac') . ' -p -', + \ join(split(ale_linters#lua#luac#GetCommand(1))) + +Execute(The luac executable should be configurable): + let g:ale_lua_luac_executable = 'luac.sh' + + AssertEqual 'luac.sh', ale_linters#lua#luac#GetExecutable(1) + AssertEqual ale#Escape('luac.sh') . ' -p -', + \ join(split(ale_linters#lua#luac#GetCommand(1))) diff --git a/test/handler/test_luac_handler.vader b/test/handler/test_luac_handler.vader new file mode 100644 index 00000000..3a2e769c --- /dev/null +++ b/test/handler/test_luac_handler.vader @@ -0,0 +1,36 @@ +Before: + Save g:ale_warn_about_trailing_whitespace + + let g:ale_warn_about_trailing_whitespace = 1 + + runtime ale_linters/lua/luac.vim + +After: + Restore + call ale#linter#Reset() + +Execute(The luac handler should parse lines correctly): + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'text': 'line contains trailing whitespace', + \ 'type': 'E', + \ }, + \ { + \ 'lnum': 3, + \ 'text': 'unexpected symbol near ''-''', + \ 'type': 'E', + \ }, + \ { + \ 'lnum': 5, + \ 'text': '''='' expected near '')''', + \ 'type': 'E', + \ }, + \ ], + \ ale_linters#lua#luac#Handle(347, [ + \ 'luac /file/path/here.lua:1: line contains trailing whitespace', + \ 'luac /file/path/here.lua:3: unexpected symbol near ''-''', + \ 'luac /file/path/here.lua:5: ''='' expected near '')''', + \ ]) + diff --git a/test/handler/test_lua_handler.vader b/test/handler/test_luacheck_handler.vader index 7cebb017..7cebb017 100644 --- a/test/handler/test_lua_handler.vader +++ b/test/handler/test_luacheck_handler.vader |