Add linter for Inko
This adds a linter for Inko (https://inko-lang.org/). The linter makes use of Inko's own compiler, and a newly introduced --check flag to only check for errors; instead of also compiling source code.
This commit is contained in:
parent
557a1ed5da
commit
8375ee2766
11 changed files with 174 additions and 0 deletions
33
ale_linters/inko/inko.vim
Normal file
33
ale_linters/inko/inko.vim
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
" Author: Yorick Peterse <yorick@yorickpeterse.com>
|
||||||
|
" Description: linting of Inko source code using the Inko compiler
|
||||||
|
|
||||||
|
call ale#Set('inko_inko_executable', 'inko')
|
||||||
|
|
||||||
|
function! ale_linters#inko#inko#GetCommand(buffer) abort
|
||||||
|
let l:include = ''
|
||||||
|
|
||||||
|
" Include the tests source directory, but only for test files.
|
||||||
|
if expand('#' . a:buffer . ':p') =~? '\vtests[/\\]test[/\\]'
|
||||||
|
let l:test_dir = ale#path#FindNearestDirectory(a:buffer, 'tests')
|
||||||
|
|
||||||
|
if isdirectory(l:test_dir)
|
||||||
|
let l:include = '--include ' . ale#Escape(l:test_dir)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
" We use %s instead of %t so the compiler determines the correct module
|
||||||
|
" names for the file being edited. Not doing so may lead to errors in
|
||||||
|
" certain cases.
|
||||||
|
return '%e build --check --format=json'
|
||||||
|
\ . ale#Pad(l:include)
|
||||||
|
\ . ' %s'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call ale#linter#Define('inko', {
|
||||||
|
\ 'name': 'inko',
|
||||||
|
\ 'executable': {b -> ale#Var(b, 'inko_inko_executable')},
|
||||||
|
\ 'command': function('ale_linters#inko#inko#GetCommand'),
|
||||||
|
\ 'callback': 'ale#handlers#inko#Handle',
|
||||||
|
\ 'output_stream': 'stderr',
|
||||||
|
\ 'lint_file': 1
|
||||||
|
\})
|
37
autoload/ale/handlers/inko.vim
Normal file
37
autoload/ale/handlers/inko.vim
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
" Author: Yorick Peterse <yorick@yorickpeterse.com>
|
||||||
|
" Description: output handlers for the Inko JSON format
|
||||||
|
|
||||||
|
function! ale#handlers#inko#GetType(severity) abort
|
||||||
|
if a:severity is? 'warning'
|
||||||
|
return 'W'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return 'E'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale#handlers#inko#Handle(buffer, lines) abort
|
||||||
|
try
|
||||||
|
let l:errors = json_decode(join(a:lines, ''))
|
||||||
|
catch
|
||||||
|
return []
|
||||||
|
endtry
|
||||||
|
|
||||||
|
if empty(l:errors)
|
||||||
|
return []
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:output = []
|
||||||
|
let l:dir = expand('#' . a:buffer . ':p:h')
|
||||||
|
|
||||||
|
for l:error in l:errors
|
||||||
|
call add(l:output, {
|
||||||
|
\ 'filename': ale#path#GetAbsPath(l:dir, l:error['file']),
|
||||||
|
\ 'lnum': l:error['line'],
|
||||||
|
\ 'col': l:error['column'],
|
||||||
|
\ 'text': l:error['message'],
|
||||||
|
\ 'type': ale#handlers#inko#GetType(l:error['level']),
|
||||||
|
\})
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return l:output
|
||||||
|
endfunction
|
|
@ -43,6 +43,7 @@ let s:default_ale_linters = {
|
||||||
\ 'go': ['gofmt', 'golint', 'go vet'],
|
\ 'go': ['gofmt', 'golint', 'go vet'],
|
||||||
\ 'hack': ['hack'],
|
\ 'hack': ['hack'],
|
||||||
\ 'help': [],
|
\ 'help': [],
|
||||||
|
\ 'inko': ['inko'],
|
||||||
\ 'perl': ['perlcritic'],
|
\ 'perl': ['perlcritic'],
|
||||||
\ 'perl6': [],
|
\ 'perl6': [],
|
||||||
\ 'python': ['flake8', 'mypy', 'pylint', 'pyright'],
|
\ 'python': ['flake8', 'mypy', 'pylint', 'pyright'],
|
||||||
|
|
22
doc/ale-inko.txt
Normal file
22
doc/ale-inko.txt
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
===============================================================================
|
||||||
|
ALE Inko Integration *ale-inko-options*
|
||||||
|
*ale-integration-inko*
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
Integration Information
|
||||||
|
|
||||||
|
Currently, the only supported linter for Inko is the Inko compiler itself.
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
inko *ale-inko-inko*
|
||||||
|
|
||||||
|
g:ale_inko_inko_executable *g:ale_inko_inko_executable*
|
||||||
|
*b:ale_inko_inko_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'inko'`
|
||||||
|
|
||||||
|
This variable can be modified to change the executable path for `inko`.
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
|
@ -213,6 +213,8 @@ Notes:
|
||||||
* `idris`
|
* `idris`
|
||||||
* Ink
|
* Ink
|
||||||
* `ink-language-server`
|
* `ink-language-server`
|
||||||
|
* Inko
|
||||||
|
* `inko` !!
|
||||||
* ISPC
|
* ISPC
|
||||||
* `ispc`!!
|
* `ispc`!!
|
||||||
* Java
|
* Java
|
||||||
|
|
|
@ -1502,6 +1502,7 @@ g:ale_linters *g:ale_linters*
|
||||||
\ 'go': ['gofmt', 'golint', 'go vet'],
|
\ 'go': ['gofmt', 'golint', 'go vet'],
|
||||||
\ 'hack': ['hack'],
|
\ 'hack': ['hack'],
|
||||||
\ 'help': [],
|
\ 'help': [],
|
||||||
|
\ 'inko': ['inko'],
|
||||||
\ 'perl': ['perlcritic'],
|
\ 'perl': ['perlcritic'],
|
||||||
\ 'perl6': [],
|
\ 'perl6': [],
|
||||||
\ 'python': ['flake8', 'mypy', 'pylint', 'pyright'],
|
\ 'python': ['flake8', 'mypy', 'pylint', 'pyright'],
|
||||||
|
@ -2656,6 +2657,8 @@ documented in additional help files.
|
||||||
idris.................................|ale-idris-idris|
|
idris.................................|ale-idris-idris|
|
||||||
ink.....................................|ale-ink-options|
|
ink.....................................|ale-ink-options|
|
||||||
ink-language-server...................|ale-ink-language-server|
|
ink-language-server...................|ale-ink-language-server|
|
||||||
|
inko....................................|ale-inko-options|
|
||||||
|
inko..................................|ale-inko-inko|
|
||||||
ispc....................................|ale-ispc-options|
|
ispc....................................|ale-ispc-options|
|
||||||
ispc..................................|ale-ispc-ispc|
|
ispc..................................|ale-ispc-ispc|
|
||||||
java....................................|ale-java-options|
|
java....................................|ale-java-options|
|
||||||
|
|
|
@ -222,6 +222,8 @@ formatting.
|
||||||
* [idris](http://www.idris-lang.org/)
|
* [idris](http://www.idris-lang.org/)
|
||||||
* Ink
|
* Ink
|
||||||
* [ink-language-server](https://github.com/ephread/ink-language-server)
|
* [ink-language-server](https://github.com/ephread/ink-language-server)
|
||||||
|
* Inko
|
||||||
|
* [inko](https://inko-lang.org/) :floppy_disk:
|
||||||
* ISPC
|
* ISPC
|
||||||
* [ispc](https://ispc.github.io/) :floppy_disk:
|
* [ispc](https://ispc.github.io/) :floppy_disk:
|
||||||
* Java
|
* Java
|
||||||
|
|
0
test/command_callback/inko_paths/test.inko
Normal file
0
test/command_callback/inko_paths/test.inko
Normal file
20
test/command_callback/test_inko_inko_callbacks.vader
Normal file
20
test/command_callback/test_inko_inko_callbacks.vader
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
Before:
|
||||||
|
call ale#assert#SetUpLinterTest('inko', 'inko')
|
||||||
|
call ale#test#SetFilename('inko_paths/test.inko')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
|
Execute(The default executable path should be correct):
|
||||||
|
AssertLinter 'inko', ale#Escape('inko') . ' build --check --format=json %s'
|
||||||
|
|
||||||
|
Execute(The inko callback should include tests/ for test paths):
|
||||||
|
call ale#engine#Cleanup(bufnr(''))
|
||||||
|
noautocmd e! inko_paths/tests/test/test_foo.inko
|
||||||
|
call ale#engine#InitBufferInfo(bufnr(''))
|
||||||
|
|
||||||
|
AssertLinter 'inko',
|
||||||
|
\ ale#Escape('inko')
|
||||||
|
\ . ' build --check --format=json --include '
|
||||||
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/inko_paths/tests/'))
|
||||||
|
\ . ' %s'
|
54
test/handler/test_inko_handler.vader
Normal file
54
test/handler/test_inko_handler.vader
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
Before:
|
||||||
|
runtime ale_linters/inko/inko.vim
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#linter#Reset()
|
||||||
|
|
||||||
|
Execute(The inko handler should parse errors correctly):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'filename': ale#path#Simplify('/tmp/foo.inko'),
|
||||||
|
\ 'lnum': 4,
|
||||||
|
\ 'col': 5,
|
||||||
|
\ 'text': 'this is an error',
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ }
|
||||||
|
\ ],
|
||||||
|
\ ale#handlers#inko#Handle(bufnr(''), [
|
||||||
|
\ '[',
|
||||||
|
\ ' {',
|
||||||
|
\ ' "file": "/tmp/foo.inko",',
|
||||||
|
\ ' "line": 4,',
|
||||||
|
\ ' "column": 5,',
|
||||||
|
\ ' "message": "this is an error",',
|
||||||
|
\ ' "level": "error"',
|
||||||
|
\ ' }',
|
||||||
|
\ ']'
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
Execute(The inko handler should parse warnings correctly):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'filename': ale#path#Simplify('/tmp/foo.inko'),
|
||||||
|
\ 'lnum': 4,
|
||||||
|
\ 'col': 5,
|
||||||
|
\ 'text': 'this is a warning',
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ }
|
||||||
|
\ ],
|
||||||
|
\ ale#handlers#inko#Handle(bufnr(''), [
|
||||||
|
\ '[',
|
||||||
|
\ ' {',
|
||||||
|
\ ' "file": "/tmp/foo.inko",',
|
||||||
|
\ ' "line": 4,',
|
||||||
|
\ ' "column": 5,',
|
||||||
|
\ ' "message": "this is a warning",',
|
||||||
|
\ ' "level": "warning"',
|
||||||
|
\ ' }',
|
||||||
|
\ ']'
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
Execute(The inko handler should handle empty output):
|
||||||
|
AssertEqual [], ale#handlers#inko#Handle(bufnr(''), [])
|
Reference in a new issue