summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2017-09-16 17:28:00 +0100
committerGitHub <noreply@github.com>2017-09-16 17:28:00 +0100
commit8bc66cff39f166562aa1060f4f50e478ebe4dd9b (patch)
tree2bee605e0ef8e9d856b004acb8b6a7472d706d0d
parenta59d1ddbf39fac6463c3b8748faf2651c9f9130d (diff)
parent6ebd8f355c974cb6b7c5d5aff20603c8c4b38feb (diff)
downloadale-8bc66cff39f166562aa1060f4f50e478ebe4dd9b.zip
Merge pull request #903 from doits/slimlint_directory
Pass the rubocop configuration file to slim-lint.
-rw-r--r--ale_linters/slim/slimlint.vim24
-rw-r--r--test/command_callback/test_slimlint_command_callback.vader35
-rw-r--r--test/slimlint-test-files/.rubocop.yml0
-rw-r--r--test/slimlint-test-files/subdir/file.slim0
4 files changed, 57 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'
\})
diff --git a/test/command_callback/test_slimlint_command_callback.vader b/test/command_callback/test_slimlint_command_callback.vader
new file mode 100644
index 00000000..1bff4288
--- /dev/null
+++ b/test/command_callback/test_slimlint_command_callback.vader
@@ -0,0 +1,35 @@
+Before:
+ runtime ale_linters/slim/slimlint.vim
+
+ let g:default_command = 'slim-lint %t'
+
+ call ale#test#SetDirectory('/testplugin/test/command_callback')
+
+After:
+ Restore
+
+ unlet! g:default_command
+
+ let g:ale_has_override = {}
+
+ call ale#linter#Reset()
+ call ale#test#RestoreDirectory()
+
+Execute(The default command should be correct):
+ AssertEqual g:default_command, ale_linters#slim#slimlint#GetCommand(bufnr(''))
+
+Execute(The command should have the .rubocop.yml prepended as an env var if one exists):
+ call ale#test#SetFilename('../slimlint-test-files/subdir/file.slim')
+
+ AssertEqual
+ \ 'SLIM_LINT_RUBUCOP_CONF=''/testplugin/test/slimlint-test-files/.rubocop.yml'' ' . g:default_command,
+ \ ale_linters#slim#slimlint#GetCommand(bufnr(''))
+
+Execute(The command should have the .rubocop.yml prepended as an env var if one exists on win32):
+ call ale#test#SetFilename('../slimlint-test-files/subdir/file.slim')
+
+ let g:ale_has_override['win32'] = 1
+
+ AssertEqual
+ \ 'set SLIM_LINT_RUBUCOP_CONF=''/testplugin/test/slimlint-test-files/.rubocop.yml'' && ' . g:default_command,
+ \ ale_linters#slim#slimlint#GetCommand(bufnr(''))
diff --git a/test/slimlint-test-files/.rubocop.yml b/test/slimlint-test-files/.rubocop.yml
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/slimlint-test-files/.rubocop.yml
diff --git a/test/slimlint-test-files/subdir/file.slim b/test/slimlint-test-files/subdir/file.slim
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/slimlint-test-files/subdir/file.slim