diff --git a/README.md b/README.md index 4919564e..e90fa28c 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ formatting. | Dart | [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) | | Dockerfile | [hadolint](https://github.com/lukasmartinelli/hadolint) | | Elixir | [credo](https://github.com/rrrene/credo), [dogma](https://github.com/lpil/dogma) !! | -| Elm | [elm-make](https://github.com/elm-lang/elm-make), [elm-format](https://github.com/avh4/elm-format) | +| Elm | [elm-format](https://github.com/avh4/elm-format), [elm-make](https://github.com/elm-lang/elm-make) | | Erb | [erb](https://github.com/jeremyevans/erubi), [erubis](https://github.com/kwatch/erubis) | | Erlang | [erlc](http://erlang.org/doc/man/erlc.html), [SyntaxErl](https://github.com/ten0s/syntaxerl) | | Fortran | [gcc](https://gcc.gnu.org/) | diff --git a/ale_linters/elm/make.vim b/ale_linters/elm/make.vim index 04563a4d..4038e3b4 100644 --- a/ale_linters/elm/make.vim +++ b/ale_linters/elm/make.vim @@ -1,6 +1,15 @@ -" Author: buffalocoder - https://github.com/buffalocoder +" Author: buffalocoder - https://github.com/buffalocoder, soywod - https://github.com/soywod " Description: Elm linting in Ale. Closely follows the Syntastic checker in https://github.com/ElmCast/elm-vim. +call ale#Set('elm_make_executable', 'elm-make') +call ale#Set('elm_make_use_global', 0) + +function! ale_linters#elm#make#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'elm_make', [ + \ 'node_modules/.bin/elm-make', + \]) +endfunction + function! ale_linters#elm#make#Handle(buffer, lines) abort let l:output = [] let l:is_windows = has('win32') @@ -52,6 +61,7 @@ endfunction " 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#path#FindNearestFile(a:buffer, 'elm-package.json') + let l:elm_exe = ale_linters#elm#make#GetExecutable(a:buffer) if empty(l:elm_package) let l:dir_set_cmd = '' else @@ -63,14 +73,16 @@ function! ale_linters#elm#make#GetCommand(buffer) abort " a sort of flag to tell the compiler not to generate an output file, " which is why this is hard coded here. " Source: https://github.com/elm-lang/elm-make/blob/master/src/Flags.hs - let l:elm_cmd = 'elm-make --report=json --output='.ale#Escape('/dev/null') + let l:elm_cmd = ale#Escape(l:elm_exe) + \ . ' --report=json' + \ . ' --output=' . ale#Escape(g:ale#util#nul_file) return l:dir_set_cmd . ' ' . l:elm_cmd . ' %t' endfunction call ale#linter#Define('elm', { \ 'name': 'make', -\ 'executable': 'elm-make', +\ 'executable_callback': 'ale_linters#elm#make#GetExecutable', \ 'output_stream': 'both', \ 'command_callback': 'ale_linters#elm#make#GetCommand', \ 'callback': 'ale_linters#elm#make#Handle' diff --git a/doc/ale-elm.txt b/doc/ale-elm.txt index 9331575b..dff781cf 100644 --- a/doc/ale-elm.txt +++ b/doc/ale-elm.txt @@ -28,5 +28,23 @@ g:ale_elm_format_options *g:ale_elm_format_options* This variable can be set to pass additional options to elm-format. +=============================================================================== +elm-make *ale-elm-make* + +g:ale_elm_make_executable *g:ale_elm_make_executable* + *b:ale_elm_make_executable* + Type: |String| + Default: `'elm-make'` + + See |ale-integrations-local-executables| + + +g:ale_elm_make_use_global *g:ale_elm_make_use_global* + *b:ale_elm_make_use_global* + Type: |Number| + Default: `0` + + See |ale-integrations-local-executables| + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index ff02f7a6..a061f012 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -217,7 +217,7 @@ Notes: * Dart: `dartanalyzer` * Dockerfile: `hadolint` * Elixir: `credo`, `dogma`!! -* Elm: `elm-make, elm-format` +* Elm: `elm-format, elm-make` * Erb: `erb`, `erubis` * Erlang: `erlc`, `SyntaxErl` * Fortran: `gcc` diff --git a/test/elm-test-files/app/filetest.elm b/test/elm-test-files/app/filetest.elm new file mode 100644 index 00000000..e69de29b diff --git a/test/elm-test-files/app/node_modules/.bin/elm-make b/test/elm-test-files/app/node_modules/.bin/elm-make new file mode 100644 index 00000000..e69de29b diff --git a/test/test_elm_executable_detection.vader b/test/test_elm_executable_detection.vader new file mode 100644 index 00000000..7b758fc2 --- /dev/null +++ b/test/test_elm_executable_detection.vader @@ -0,0 +1,36 @@ +Before: + call ale#test#SetDirectory('/testplugin/test') + runtime ale_linters/elm/make.vim + +After: + unlet! g:ale_elm_make_use_global + unlet! g:ale_elm_make_executable + + call ale#test#RestoreDirectory() + +Execute(should get valid executable with default params): + call ale#test#SetFilename('elm-test-files/app/testfile.elm') + + AssertEqual + \ g:dir . '/elm-test-files/app/node_modules/.bin/elm-make', + \ ale_linters#elm#make#GetExecutable(bufnr('')) + +Execute(should get valid executable with 'use_global' params): + let g:ale_elm_make_use_global = 1 + + call ale#test#SetFilename('elm-test-files/app/testfile.elm') + + AssertEqual + \ 'elm-make', + \ ale_linters#elm#make#GetExecutable(bufnr('')) + +Execute(should get valid executable with 'use_global' and 'executable' params): + let g:ale_elm_make_executable = 'other-elm-make' + let g:ale_elm_make_use_global = 1 + + call ale#test#SetFilename('elm-test-files/app/testfile.elm') + + AssertEqual + \ 'other-elm-make', + \ ale_linters#elm#make#GetExecutable(bufnr('')) +