From bb095df25e7fb6e3090061572bf9b1c472ac550f Mon Sep 17 00:00:00 2001 From: Michael Quinn Date: Mon, 29 Jan 2018 20:18:14 -0800 Subject: [PATCH 1/2] Call lintr library before linting This solves namespace issues related to the objects used to set linting options. --- ale_linters/r/lintr.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ale_linters/r/lintr.vim b/ale_linters/r/lintr.vim index 86b591c..9db63c7 100644 --- a/ale_linters/r/lintr.vim +++ b/ale_linters/r/lintr.vim @@ -1,14 +1,17 @@ " Author: Michel Lang , w0rp " 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()') +let g:ale_r_lintr_options = get(g:, 'ale_r_lintr_options', 'with_defaults()') " A reasonable alternative default: -" \ get(g:, 'ale_r_lintr_options', 'lintr::with_defaults(object_usage_linter = NULL)') +" get(g:, 'ale_r_lintr_options', 'with_defaults(object_usage_linter = NULL)') function! ale_linters#r#lintr#GetCommand(buffer) abort + let l:cmd_string = 'suppressPackageStartupMessages(library(lintr));' + \ . 'lint(cache = FALSE, commandArgs(TRUE),' + \ . ale#Var(a:buffer, 'r_lintr_options') . ')' return ale#path#BufferCdString(a:buffer) - \ . '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')) + \ . 'Rscript -e ' + \ . ale#Escape(l:cmd_string) . ' %t' endfunction call ale#linter#Define('r', { @@ -18,3 +21,4 @@ call ale#linter#Define('r', { \ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \ 'output_stream': 'both', \}) + From b13f290390ba62180f731fef6cea58d6fef8bc3e Mon Sep 17 00:00:00 2001 From: Michael Quinn Date: Wed, 31 Jan 2018 18:06:35 -0800 Subject: [PATCH 2/2] Update formatting and tests. --- ale_linters/r/lintr.vim | 6 +++--- .../test_lintr_command_callback.vader | 16 +++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ale_linters/r/lintr.vim b/ale_linters/r/lintr.vim index 9db63c7..e163905 100644 --- a/ale_linters/r/lintr.vim +++ b/ale_linters/r/lintr.vim @@ -7,8 +7,9 @@ let g:ale_r_lintr_options = get(g:, 'ale_r_lintr_options', 'with_defaults()') function! ale_linters#r#lintr#GetCommand(buffer) abort let l:cmd_string = 'suppressPackageStartupMessages(library(lintr));' - \ . 'lint(cache = FALSE, commandArgs(TRUE),' - \ . ale#Var(a:buffer, 'r_lintr_options') . ')' + \ . 'lint(cache = FALSE, commandArgs(TRUE),' + \ . ale#Var(a:buffer, 'r_lintr_options') . ')' + return ale#path#BufferCdString(a:buffer) \ . 'Rscript -e ' \ . ale#Escape(l:cmd_string) . ' %t' @@ -21,4 +22,3 @@ call ale#linter#Define('r', { \ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \ 'output_stream': 'both', \}) - diff --git a/test/command_callback/test_lintr_command_callback.vader b/test/command_callback/test_lintr_command_callback.vader index 3199b49..256618c 100644 --- a/test/command_callback/test_lintr_command_callback.vader +++ b/test/command_callback/test_lintr_command_callback.vader @@ -17,18 +17,20 @@ 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#Escape('suppressPackageStartupMessages(library(lintr));' + \ . 'lint(cache = FALSE, commandArgs(TRUE),' + \ . 'with_defaults())') + \ . ' %t', \ 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)' + let b:ale_r_lintr_options = '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#Escape('suppressPackageStartupMessages(library(lintr));' + \ . 'lint(cache = FALSE, commandArgs(TRUE),' + \ . 'with_defaults(object_usage_linter = NULL))') + \ . ' %t', \ ale_linters#r#lintr#GetCommand(bufnr(''))