Add Elm linting via elm-make (#213)
* Add support for Elm linting * Adding documentation for Elm * Adjusting spacing * Addressing concerns listed in pull request Removed the s:FindRootDirectory function as it does not make much sense in this context. Adjusted the rest of the code to handle the removal of that function, including using the ale#util function to find the nearest file. Ensured that when an empty filepath is found, the code does not attempt to change directories. Ensured that the linter would take from stdin using the wrapper.
This commit is contained in:
parent
25f6445c50
commit
70e379cc46
@ -59,6 +59,7 @@ name. That seems to be the fairest way to arrange this table.
|
|||||||
| Cython (pyrex filetype) | [cython](http://cython.org/) |
|
| Cython (pyrex filetype) | [cython](http://cython.org/) |
|
||||||
| D | [dmd](https://dlang.org/dmd-linux.html)^ |
|
| D | [dmd](https://dlang.org/dmd-linux.html)^ |
|
||||||
| Elixir | [credo](https://github.com/rrrene/credo) |
|
| Elixir | [credo](https://github.com/rrrene/credo) |
|
||||||
|
| Elm | [elm-make](https://github.com/elm-lang/elm-make) |
|
||||||
| Fortran | [gcc](https://gcc.gnu.org/) |
|
| Fortran | [gcc](https://gcc.gnu.org/) |
|
||||||
| Go | [gofmt -e](https://golang.org/cmd/gofmt/), [go vet](https://golang.org/cmd/vet/), [golint](https://godoc.org/github.com/golang/lint) |
|
| Go | [gofmt -e](https://golang.org/cmd/gofmt/), [go vet](https://golang.org/cmd/vet/), [golint](https://godoc.org/github.com/golang/lint) |
|
||||||
| Haskell | [ghc](https://www.haskell.org/ghc/), [hlint](https://hackage.haskell.org/package/hlint) |
|
| Haskell | [ghc](https://www.haskell.org/ghc/), [hlint](https://hackage.haskell.org/package/hlint) |
|
||||||
|
51
ale_linters/elm/make.vim
Normal file
51
ale_linters/elm/make.vim
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
" Author: buffalocoder - https://github.com/buffalocoder
|
||||||
|
" Description: Elm linting in Ale. Closely follows the Syntastic checker in https://github.com/ElmCast/elm-vim.
|
||||||
|
|
||||||
|
function! ale_linters#elm#make#Handle(buffer, lines)
|
||||||
|
let l:output = []
|
||||||
|
for l:line in a:lines
|
||||||
|
if l:line[0] ==# '['
|
||||||
|
let l:errors = json_decode(l:line)
|
||||||
|
|
||||||
|
for l:error in l:errors
|
||||||
|
call add(l:output, {
|
||||||
|
\ 'bufnr': a:buffer,
|
||||||
|
\ 'lnum': l:error.region.start.line,
|
||||||
|
\ 'vcol': 0,
|
||||||
|
\ 'col': l:error.region.start.column,
|
||||||
|
\ 'type': (l:error.type ==? 'error') ? 'E' : 'W',
|
||||||
|
\ 'text': l:error.overview,
|
||||||
|
\ 'nr': -1,
|
||||||
|
\})
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return l:output
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Return the command to execute the linter in the projects directory.
|
||||||
|
" If it doesn't, then this will fail when imports are needed.
|
||||||
|
function! ale_linters#elm#make#GetCommand(buffer) abort
|
||||||
|
let l:elm_package = ale#util#FindNearestFile(a:buffer, 'elm-package.json')
|
||||||
|
if empty(l:elm_package)
|
||||||
|
let l:dir_set_cmd = ''
|
||||||
|
else
|
||||||
|
let l:root_dir = fnamemodify(l:elm_package, ':p:h')
|
||||||
|
let l:dir_set_cmd = 'cd ' . fnameescape(l:root_dir) . '; '
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:elm_cmd = 'elm-make --report=json --output='.shellescape(g:ale#util#nul_file)
|
||||||
|
let l:stdin_wrapper = g:ale#util#stdin_wrapper . ' .elm'
|
||||||
|
|
||||||
|
return l:dir_set_cmd . ' ' . l:stdin_wrapper . ' ' . l:elm_cmd
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call ale#linter#Define('elm', {
|
||||||
|
\ 'name': 'make',
|
||||||
|
\ 'executable': 'elm-make',
|
||||||
|
\ 'output_stream': 'both',
|
||||||
|
\ 'command_callback': 'ale_linters#elm#make#GetCommand',
|
||||||
|
\ 'callback': 'ale_linters#elm#make#Handle'
|
||||||
|
\})
|
||||||
|
|
@ -71,6 +71,7 @@ The following languages and tools are supported.
|
|||||||
* Cython (pyrex filetype): 'cython'
|
* Cython (pyrex filetype): 'cython'
|
||||||
* D: 'dmd'
|
* D: 'dmd'
|
||||||
* Elixir: 'credo'
|
* Elixir: 'credo'
|
||||||
|
* Elm: 'elm-make'
|
||||||
* Fortran: 'gcc'
|
* Fortran: 'gcc'
|
||||||
* Go: 'gofmt -e', 'go vet', 'golint'
|
* Go: 'gofmt -e', 'go vet', 'golint'
|
||||||
* Haskell: 'ghc', 'hlint'
|
* Haskell: 'ghc', 'hlint'
|
||||||
|
Loading…
Reference in New Issue
Block a user