From 854066e8499344a6461fef8fd0ee4b3f8eaebeeb Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 6 Jul 2017 22:58:14 +0100 Subject: #732 - Use the configuration files when fixing files with rubocop --- autoload/ale/fixers/rubocop.vim | 2 ++ .../ruby_paths/with_config/.rubocop.yml | 0 test/fixers/test_rubocop_fixer_callback.vader | 22 ++++++++++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/command_callback/ruby_paths/with_config/.rubocop.yml diff --git a/autoload/ale/fixers/rubocop.vim b/autoload/ale/fixers/rubocop.vim index 3f92055f..88dc1c43 100644 --- a/autoload/ale/fixers/rubocop.vim +++ b/autoload/ale/fixers/rubocop.vim @@ -3,8 +3,10 @@ function! ale#fixers#rubocop#GetCommand(buffer) abort let l:exec_args = l:executable =~? 'bundle$' \ ? ' exec rubocop' \ : '' + let l:config = ale#path#FindNearestFile(a:buffer, '.rubocop.yml') return ale#Escape(l:executable) . l:exec_args + \ . (!empty(l:config) ? ' --config ' . ale#Escape(l:config) : '') \ . ' --auto-correct %t' endfunction diff --git a/test/command_callback/ruby_paths/with_config/.rubocop.yml b/test/command_callback/ruby_paths/with_config/.rubocop.yml new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/test_rubocop_fixer_callback.vader b/test/fixers/test_rubocop_fixer_callback.vader index e9352e73..74160c73 100644 --- a/test/fixers/test_rubocop_fixer_callback.vader +++ b/test/fixers/test_rubocop_fixer_callback.vader @@ -19,10 +19,24 @@ After: unlet! g:dir Execute(The rubocop callback should return the correct default values): - silent execute 'file ' . fnameescape(g:dir . '/ruby_paths/dummy.rb') + call ale#test#SetFilename('ruby_paths/dummy.rb') AssertEqual - \ {'read_temporary_file': 1, - \ 'command': "'" . g:ale_ruby_rubocop_executable . "' " - \ . '--auto-correct %t' }, + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_ruby_rubocop_executable) + \ . ' --auto-correct %t', + \ }, + \ ale#fixers#rubocop#Fix(bufnr('')) + +Execute(The rubocop callback should include configuration files): + call ale#test#SetFilename('ruby_paths/with_config/dummy.rb') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_ruby_rubocop_executable) + \ . ' --config ' . ale#Escape(g:dir . '/ruby_paths/with_config/.rubocop.yml') + \ . ' --auto-correct %t', + \ }, \ ale#fixers#rubocop#Fix(bufnr('')) -- cgit v1.2.3