2018-02-04 13:57:52 -05:00
|
|
|
" Author: Michel Lang <michellang@gmail.com>, w0rp <devw0rp@gmail.com>,
|
|
|
|
" Fenner Macrae <fmacrae.dev@gmail.com>
|
2017-07-03 17:34:22 -04:00
|
|
|
" Description: This file adds support for checking R code with lintr.
|
|
|
|
|
2018-01-29 23:18:14 -05:00
|
|
|
let g:ale_r_lintr_options = get(g:, 'ale_r_lintr_options', 'with_defaults()')
|
2017-08-15 14:37:38 -04:00
|
|
|
" A reasonable alternative default:
|
2018-01-29 23:18:14 -05:00
|
|
|
" get(g:, 'ale_r_lintr_options', 'with_defaults(object_usage_linter = NULL)')
|
2017-08-15 14:37:38 -04:00
|
|
|
|
2018-02-04 13:57:52 -05:00
|
|
|
|
|
|
|
let g:ale_r_lintr_lint_package = get(g:, 'ale_r_lintr_lint_package', 0)
|
|
|
|
|
2017-07-03 17:34:22 -04:00
|
|
|
function! ale_linters#r#lintr#GetCommand(buffer) abort
|
2018-02-04 13:57:52 -05:00
|
|
|
if ale#Var(a:buffer, 'r_lintr_lint_package')
|
2018-02-05 14:33:23 -05:00
|
|
|
let l:lint_cmd = 'lint_package(cache = FALSE, linters = '
|
2018-02-05 12:54:15 -05:00
|
|
|
\ . ale#Var(a:buffer, 'r_lintr_options') . ')'
|
2018-02-04 13:57:52 -05:00
|
|
|
else
|
2018-02-05 12:54:15 -05:00
|
|
|
let l:lint_cmd = 'lint(cache = FALSE, commandArgs(TRUE), '
|
|
|
|
\ . ale#Var(a:buffer, 'r_lintr_options') . ')'
|
2018-02-04 13:57:52 -05:00
|
|
|
endif
|
|
|
|
|
2018-01-29 23:18:14 -05:00
|
|
|
let l:cmd_string = 'suppressPackageStartupMessages(library(lintr));'
|
2018-02-05 14:33:23 -05:00
|
|
|
\ . l:lint_cmd
|
2018-01-31 21:06:35 -05:00
|
|
|
|
2017-07-03 17:34:22 -04:00
|
|
|
return ale#path#BufferCdString(a:buffer)
|
2018-06-07 09:06:09 -04:00
|
|
|
\ . 'Rscript --vanilla -e '
|
2018-01-29 23:18:14 -05:00
|
|
|
\ . ale#Escape(l:cmd_string) . ' %t'
|
2017-07-03 17:34:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('r', {
|
|
|
|
\ 'name': 'lintr',
|
|
|
|
\ 'executable': 'Rscript',
|
2019-02-22 13:05:04 -05:00
|
|
|
\ 'command': function('ale_linters#r#lintr#GetCommand'),
|
2017-07-03 17:34:22 -04:00
|
|
|
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
|
|
|
\ 'output_stream': 'both',
|
|
|
|
\})
|