diff options
author | Markus Doits <markus.doits@stellenticket.de> | 2017-09-02 16:48:00 +0200 |
---|---|---|
committer | Markus Doits <markus.doits@stellenticket.de> | 2017-09-15 18:56:59 +0200 |
commit | 6ebd8f355c974cb6b7c5d5aff20603c8c4b38feb (patch) | |
tree | 2bee605e0ef8e9d856b004acb8b6a7472d706d0d /ale_linters/slim | |
parent | a59d1ddbf39fac6463c3b8748faf2651c9f9130d (diff) | |
download | ale-6ebd8f355c974cb6b7c5d5aff20603c8c4b38feb.zip |
slimlint: Search for .rubocop.yml and use it
This fixes slim-lint not honoring a `.rubocop.yml` in the file's or
parent directory. Due to the way slim-lint calls rubocop, it requires
the special `SLIM_LINT_RUBUCOP_CONF` env var to pick up the
`.rubocop.yml` if it is not run on the real file (which is the case
here).
See https://github.com/sds/slim-lint/blob/master/lib/slim_lint/linter/README.md#rubocop
Diffstat (limited to 'ale_linters/slim')
-rw-r--r-- | ale_linters/slim/slimlint.vim | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/ale_linters/slim/slimlint.vim b/ale_linters/slim/slimlint.vim index 74796b2b..0a98a52d 100644 --- a/ale_linters/slim/slimlint.vim +++ b/ale_linters/slim/slimlint.vim @@ -1,5 +1,25 @@ " Author: Markus Doits - https://github.com/doits -" Description: slim-lint for Slim files, based on hamllint.vim +" Description: slim-lint for Slim files + +function! ale_linters#slim#slimlint#GetCommand(buffer) abort + let l:command = 'slim-lint %t' + + let l:rubocop_config = ale#path#FindNearestFile(a:buffer, '.rubocop.yml') + + " Set SLIM_LINT_RUBUCOP_CONF variable as it is needed for slim-lint to + " pick up the rubocop config. + " + " See https://github.com/sds/slim-lint/blob/master/lib/slim_lint/linter/README.md#rubocop + if !empty(l:rubocop_config) + if ale#Has('win32') + let l:command = 'set SLIM_LINT_RUBUCOP_CONF=' . ale#Escape(l:rubocop_config) . ' && ' . l:command + else + let l:command = 'SLIM_LINT_RUBUCOP_CONF=' . ale#Escape(l:rubocop_config) . ' ' . l:command + endif + endif + + return l:command +endfunction function! ale_linters#slim#slimlint#Handle(buffer, lines) abort " Matches patterns like the following: @@ -21,6 +41,6 @@ endfunction call ale#linter#Define('slim', { \ 'name': 'slimlint', \ 'executable': 'slim-lint', -\ 'command': 'slim-lint %t', +\ 'command_callback': 'ale_linters#slim#slimlint#GetCommand', \ 'callback': 'ale_linters#slim#slimlint#Handle' \}) |