Add lint_package support to lintr

This commit is contained in:
Fenner Macrae 2018-02-04 10:57:52 -08:00
parent 33b3331b04
commit dda132c1a2
3 changed files with 33 additions and 2 deletions

View file

@ -1,13 +1,23 @@
" Author: Michel Lang <michellang@gmail.com>, w0rp <devw0rp@gmail.com>
" Author: Michel Lang <michellang@gmail.com>, w0rp <devw0rp@gmail.com>,
" Fenner Macrae <fmacrae.dev@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', 'with_defaults()')
" A reasonable alternative default:
" get(g:, 'ale_r_lintr_options', 'with_defaults(object_usage_linter = NULL)')
let g:ale_r_lintr_lint_package = get(g:, 'ale_r_lintr_lint_package', 0)
function! ale_linters#r#lintr#GetCommand(buffer) abort
if ale#Var(a:buffer, 'r_lintr_lint_package')
let l:lint_cmd = 'lint_package'
else
let l:lint_cmd = 'lint'
endif
let l:cmd_string = 'suppressPackageStartupMessages(library(lintr));'
\ . 'lint(cache = FALSE, commandArgs(TRUE),'
\ . l:lint_cmd . '(cache = FALSE, commandArgs(TRUE),'
\ . ale#Var(a:buffer, 'r_lintr_options') . ')'
return ale#path#BufferCdString(a:buffer)

View file

@ -16,5 +16,14 @@ g:ale_r_lintr_options *g:ale_r_lintr_options*
options. Consult the lintr documentation for more information.
g:ale_r_lintr_lint_package *g:ale_r_lintr_lint_package*
*b:ale_r_lintr_lint_package*
Type: |Number|
Default: `0`
When set to `1`, the file will be checked with `lintr::lint_package` instead
of `lintr::lint`. This prevents erroneous namespace warnings when linting
package files.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -34,3 +34,15 @@ Execute(The lintr options should be configurable):
\ . 'with_defaults(object_usage_linter = NULL))')
\ . ' %t',
\ ale_linters#r#lintr#GetCommand(bufnr(''))
Execute(If the lint_package flag is set, lintr::lint_package should be called):
let b:ale_r_lintr_lint_package = 1
AssertEqual
\ 'cd ' . ale#Escape(getcwd()) . ' && '
\ . 'Rscript -e '
\ . ale#Escape('suppressPackageStartupMessages(library(lintr));'
\ . 'lint_package(cache = FALSE, commandArgs(TRUE),'
\ . 'with_defaults())')
\ . ' %t',
\ ale_linters#r#lintr#GetCommand(bufnr(''))