diff options
-rw-r--r-- | ale_linters/r/lintr.vim | 7 | ||||
-rw-r--r-- | doc/ale-r.txt | 20 | ||||
-rw-r--r-- | doc/ale.txt | 2 | ||||
-rw-r--r-- | test/command_callback/test_lintr_command_callback.vader | 34 |
4 files changed, 62 insertions, 1 deletions
diff --git a/ale_linters/r/lintr.vim b/ale_linters/r/lintr.vim index 9375b8a5..86b591c2 100644 --- a/ale_linters/r/lintr.vim +++ b/ale_linters/r/lintr.vim @@ -1,9 +1,14 @@ " Author: Michel Lang <michellang@gmail.com>, w0rp <devw0rp@gmail.com> " Description: This file adds support for checking R code with lintr. +let g:ale_r_lintr_options = +\ get(g:, 'ale_r_lintr_options', 'lintr::with_defaults()') +" A reasonable alternative default: +" \ get(g:, 'ale_r_lintr_options', 'lintr::with_defaults(object_usage_linter = NULL)') + function! ale_linters#r#lintr#GetCommand(buffer) abort return ale#path#BufferCdString(a:buffer) - \ . 'Rscript -e ' . ale#Escape('lintr::lint(commandArgs(TRUE))') . ' %t' + \ . 'Rscript -e ' . ale#Escape('lintr::lint(commandArgs(TRUE)[1], eval(parse(text = commandArgs(TRUE)[2])))') . ' %t' . ' ' . ale#Escape(ale#Var(a:buffer, 'r_lintr_options')) endfunction call ale#linter#Define('r', { diff --git a/doc/ale-r.txt b/doc/ale-r.txt new file mode 100644 index 00000000..6372f80d --- /dev/null +++ b/doc/ale-r.txt @@ -0,0 +1,20 @@ +=============================================================================== +ALE R Integration *ale-r-options* + + +=============================================================================== +lintr *ale-r-lintr* + +g:ale_r_lintr_options *g:ale_r_lintr_options* + *b:ale_r_lintr_options* + Type: |String| + Default: `'lintr::with_defaults()'` + + This option can be configured to change the options for lintr. + + The value of this option will be run with `eval` for the `lintr::lint` + options. Consult the lintr documentation for more information. + + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 70f90cc3..899e8c80 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -101,6 +101,8 @@ CONTENTS *ale-contents* pycodestyle.........................|ale-python-pycodestyle| pylint..............................|ale-python-pylint| yapf................................|ale-python-yapf| + r.....................................|ale-r-options| + lintr...............................|ale-r-lintr| ruby..................................|ale-ruby-options| brakeman............................|ale-ruby-brakeman| rails_best_practices................|ale-ruby-rails_best_practices| diff --git a/test/command_callback/test_lintr_command_callback.vader b/test/command_callback/test_lintr_command_callback.vader new file mode 100644 index 00000000..3199b498 --- /dev/null +++ b/test/command_callback/test_lintr_command_callback.vader @@ -0,0 +1,34 @@ +Before: + Save g:ale_r_lintr_options + + unlet! g:ale_r_lintr_options + unlet! b:ale_r_lintr_options + + runtime ale_linters/r/lintr.vim + +After: + Restore + + unlet! b:ale_r_lintr_options + + call ale#linter#Reset() + +Execute(The default lintr command should be correct): + AssertEqual + \ 'cd ' . ale#Escape(getcwd()) . ' && ' + \ . 'Rscript -e ' + \ . ale#Escape('lintr::lint(commandArgs(TRUE)[1], eval(parse(text = commandArgs(TRUE)[2])))') + \ . ' %t ' + \ . ale#Escape('lintr::with_defaults()'), + \ ale_linters#r#lintr#GetCommand(bufnr('')) + +Execute(The lintr options should be configurable): + let b:ale_r_lintr_options = 'lintr::with_defaults(object_usage_linter = NULL)' + + AssertEqual + \ 'cd ' . ale#Escape(getcwd()) . ' && ' + \ . 'Rscript -e ' + \ . ale#Escape('lintr::lint(commandArgs(TRUE)[1], eval(parse(text = commandArgs(TRUE)[2])))') + \ . ' %t ' + \ . ale#Escape('lintr::with_defaults(object_usage_linter = NULL)'), + \ ale_linters#r#lintr#GetCommand(bufnr('')) |