summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/r/lintr.vim14
-rw-r--r--doc/ale-r.txt9
-rw-r--r--test/command_callback/test_lintr_command_callback.vader12
3 files changed, 33 insertions, 2 deletions
diff --git a/ale_linters/r/lintr.vim b/ale_linters/r/lintr.vim
index e1639051..006bf47c 100644
--- a/ale_linters/r/lintr.vim
+++ b/ale_linters/r/lintr.vim
@@ -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)
diff --git a/doc/ale-r.txt b/doc/ale-r.txt
index 6372f80d..f85f48fd 100644
--- a/doc/ale-r.txt
+++ b/doc/ale-r.txt
@@ -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:
diff --git a/test/command_callback/test_lintr_command_callback.vader b/test/command_callback/test_lintr_command_callback.vader
index 256618cf..33259e05 100644
--- a/test/command_callback/test_lintr_command_callback.vader
+++ b/test/command_callback/test_lintr_command_callback.vader
@@ -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(''))