ale icon indicating copy to clipboard operation
ale copied to clipboard

ALE not linting `.r` files with `lintr` (but working with other filetypes)

Open mikekaminsky opened this issue 5 years ago • 15 comments

Information

VIM version

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 27 2020 12:11:13) macOS version

Operating System: MacOS Catalina 10.15.3

What went wrong

I can't get ALE + lintr to lint my .r files. I have confirmed that ALE works with other files (e.g., my .vimrc file with vint).

When I run :ALEInfo I can see issues appearing, but they don't appear in my vim editor at all.

I'm running a minimal .vimrc with just ALE installed via vim-plug and the problem persists.

I've installed new versions of vim, ALE, and lintr.

I've looked through the issues both this repository and in the lintr repository and haven't seen anything relevant.

Reproducing the bug

  1. Install ALE
  2. Install lintr in R via install.packages('lintr')
  3. Open up a test.r file
  4. Observe that the file is not linted.

I assume that these steps won't actually reproduce this since other people aren't experiencing this issue, but this works consistently on my machine.

If this is a dumb issue in my configuration I'm very sorry in advance.

:ALEInfo

 Current Filetype: r
Available Linters: ['lintr']
  Enabled Linters: ['lintr']
 Suggested Fixers: 
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'styler' - Fix R files with styler.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
 Linter Variables:

let g:ale_r_lintr_lint_package = 0
let g:ale_r_lintr_options = 'with_defaults()'
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let g:ale_linters_explicit = 0
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_lsp_root = {}
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

(executable check - success) Rscript
(finished - exit code 0) ['/bin/bash', '-c', 'cd ''/Users/michaelkaminsky'' && Rscript --vanilla -e ''suppressPackageStartupMessages(library(lintr));lint(cache = FALSE, commandArgs(TRUE), with_defaults())'' ''/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vOW3kfS/1/scratch.r''']

<<<OUTPUT STARTS>>>
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vOW3kfS/1/scratch.r:4:30: style: There should be a space between right parenthesis and an opening curly brace.
write_f <- function(path, obj){
                             ^~
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vOW3kfS/1/scratch.r:10:31: style: There should be a space between right parenthesis and an opening curly brace.
write_f2 <- function(path, obj){
                              ^~
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vOW3kfS/1/scratch.r:11:3: warning: local variable ‘name’ assigned but may not be used
  name <- deparse(substitute(obj))
  ^~~~
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vOW3kfS/1/scratch.r:12:3: warning: no visible global function definition for ‘log_info’
  log_info("Writing {name} to {path}")
  ^~~~~~~~
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vOW3kfS/1/scratch.r:16:10: style: Only use double-quotes.
write_f2('~/Desktop', x)
         ^~~~~~~~~~~
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vOW3kfS/1/scratch.r:18:27: style: There should be a space between right parenthesis and an opening curly brace.
other_func <- function(obj){
                          ^~
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vOW3kfS/1/scratch.r:19:12: style: Only use double-quotes.
  write_f2('~/Downloads', obj)
           ^~~~~~~~~~~~~
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vOW3kfS/1/scratch.r:26:26: style: There should be a space between right parenthesis and an opening curly brace.
wrapper_func <- function(){
                         ^~
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vOW3kfS/1/scratch.r:40:1: style: Trailing blank lines are superfluous.

^
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vOW3kfS/1/scratch.r:41:1: style: Trailing blank lines are superfluous.

^
<<<OUTPUT ENDS>>>

mikekaminsky avatar Apr 01 '20 23:04 mikekaminsky

Maybe only .R is supported?

lorenzwalthert avatar Apr 02 '20 06:04 lorenzwalthert

@lorenzwalthert interesting theory, but repeated with .R and I see the same issue.

Also in the ALEInfo this line makes me think that it's picking up the filetype correctly:

 Current Filetype: r
Available Linters: ['lintr']

mikekaminsky avatar Apr 02 '20 14:04 mikekaminsky

I'm getting similar behavior. Neither .r nor .R files receive lintr messages within Vim. Yet, :Viminfo reports all of the linting messages. In addition, the other linters seem to work, such as the linters for Python, so this seems specific to R. I'd love to help fix, but I have minimal vim experience.

I'm also on macOS Catalina, using iTerm2. I perused a lot of the previous issues and couldn't find anything too helpful.

One major difference between :VIMInfo outputs for R and Python files that I notice is that R files have many linting messages between <<<OUTPUT STARTS>>> and <<<OUTPUT ENDS>>>, as seen above, but in Python files they are broken up by each individual lint.

prncevince avatar Apr 07 '20 00:04 prncevince

@prncevince I'm glad I'm not the only one, and the <<<OUTPUT STARTS>>> thing is a good lead!

I'm happy to try to take a crack at this, though my vimscripting experience is (fairly) limited as well. I can take a closer look this weekend, but if someone with more knowledge but less time can at least point me in the right direction that would be super helpful.

mikekaminsky avatar Apr 07 '20 00:04 mikekaminsky

If it helps ... I disabled all of my plugins except ALE and it still doesn't work. Also using Vim 8.2

prncevince avatar Apr 07 '20 02:04 prncevince

Okay, some more information here.

It seems that the release of lintr 2.0.0 caused the ale integration to break. I was able to get linting working by installing the previous version of lintr with devtools::install_version("lintr", version = "1.0.3", repos = "http://cran.us.r-project.org")

Looking at ALEInfo gives some additional clues. Here's what it looks like for the working version:

  Command History:
(executable check - success) Rscript
(finished - exit code 0) ['/bin/bash', '-c', 'cd ''/Users/michaelkaminsky/workspace/dotfiles'' && Rscript --vanilla -e ''suppressPackageStartupMessages(library(lintr));lint(cache = FALSE, commandArgs(TRUE), with_defaults())'
' ''/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vCaMPzx/1/test.r''']
<<<OUTPUT STARTS>>>
/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vCaMPzx/1/test.r:1:7: style: Use <-, not =, for assignment.
hello = "howdy"
      ^
<<<OUTPUT ENDS>>>

And here's what it looks like for the non-working version:

  Command History:
(executable check - success) Rscript
(finished - exit code 0) ['/bin/bash', '-c', 'cd ''/Users/michaelkaminsky/workspace/dotfiles'' && Rscript --vani lla -e ''suppressPackageStartupMessages(library(lintr));lint(cache = FALSE, commandArgs(TRUE), with_defaults())'
' ''/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vW6TbBN/1/test.r''']
<<<OUTPUT STARTS>>>
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vW6TbBN/1/test.r:1:7: style: Use <-, not =, for assignm ent.
hello = "howdy"
      ^
<<<OUTPUT ENDS>>>

The only difference I see here is in the filepath -- both of them are linting the file in the /var/ directory (which I assume is the lintr cache[?]) but in the second, broken version, lintr is returning a different path in the /private/ directory.

My hypothesis is that this difference is what's causing Ale not to show the lints. I'm ... not sure at all how to fix this. I'm going to open an issue on the lintr repo as well to see if they have any ideas.

mikekaminsky avatar Apr 11 '20 18:04 mikekaminsky

The answer may lye within the lintr::lint() git diff between releases (append this anchor #diff-b116713df8a4d8ebc7fbf94ca1e11721 to the URL after the page loads) and how the function ultimately gets applied in ALE's lintr.vim

prncevince avatar Apr 11 '20 19:04 prncevince

I suspect you're right, but I've been browsing the code for a few hours right now and don't see anything that's jumping out me. I attempted to identify the commit that caused the issue through bisection but I can't replicate the issue when using devtools::install_github('jimhester/lintr',ref='a0939956d28761482d47b812945e871e4ad6f71e') probably because the dependencies are different.

mikekaminsky avatar Apr 11 '20 19:04 mikekaminsky

The string ' %t' on line 26 of the vimscript is what provides to lintr::lint() its filename argument. But as you've pointed out, is this the wrong filepath?

prncevince avatar Apr 11 '20 20:04 prncevince

My guess is that it's the right file path b/c ALEInfo is still spitting lintr::lintr() lints, so I need to gather some more info on the internals of ALE to make progress with this.

prncevince avatar Apr 11 '20 21:04 prncevince

Yeah -- I think it's definitely the right file because it's linting -- my guess is that since this part:

(finished - exit code 0) ['/bin/bash', '-c', 'cd ''/Users/michaelkaminsky/workspace/dotfiles'' && Rscript --vani lla -e ''suppressPackageStartupMessages(library(lintr));lint(cache = FALSE, commandArgs(TRUE), with_defaults())'
' ''/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vW6TbBN/1/test.r''']

doesn't match this part:

<<<OUTPUT STARTS>>>
/private/var/folders/gb/1v70s2y97b9f42rs9jfpqrxw0000gn/T/vW6TbBN/1/test.r:1:7: style: Use <-, not =, for assignm ent.

It might be causing issues. But that's a real shot in the dark -- let me know if you make progress and I can help :)

mikekaminsky avatar Apr 11 '20 21:04 mikekaminsky

i have exactly the same problem, but just in macOS it works well in ubuntu

(executable check - success) Rscript (finished - exit code 0) ['/bin/zsh', '-c', 'cd ''/home/zhihuai1982/.dotfiles'' && Rscript --vanilla -e ''suppressP ackageStartupMessages(library(lintr));lint(cache = FALSE, commandArgs(TRUE), with_defaults(line_length_linter(120)) )'' ''/tmp/nvimbIyg1I/2/test.R'''] <<<OUTPUT STARTS>>> /tmp/nvimbIyg1I/2/test.R:1:6: style: Only use double-quotes. a <- 'djin' ^~~~~~ /tmp/nvimbIyg1I/2/test.R:5:1: style: Trailing blank lines are superfluous. ^ <<<OUTPUT ENDS>>> this is from vim@ubuntu, the lint works well

zhihuai1982 avatar Jun 07 '20 11:06 zhihuai1982

I also have the same problem. Any update about this issue?

R version 4.0.2 (2020-06-22) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Catalina 10.15.6

Matrix products: default BLAS: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] lintr_2.0.1

loaded via a namespace (and not attached): [1] ps_1.3.3 crayon_1.3.4 withr_2.2.0 rprojroot_1.3-2 [5] assertthat_0.2.1 R6_2.4.1 backports_1.1.8 lazyeval_0.2.2 [9] remotes_2.2.0 callr_3.4.3 rex_1.2.0 xml2_1.3.2 [13] cyclocomp_1.1.0 desc_1.2.0 tools_4.0.2 compiler_4.0.2 [17] processx_3.4.3

I also have vim 8.2.1300 installed and Plug 'dense-analysis/ale' installed. When I open *.R file and input :ALEInfo, I can see lintr has checked the format of my file. However, I cannot see any warnings symbols in the editor. I also use yamllint for *.yaml and pylint for *.py, and the editor can show the warning symbols.

AlfredSAM avatar Jul 31 '20 14:07 AlfredSAM

I did a bit of hacking in ale to force those strings to match and it does not seem to have remedied the problem, though I may have done it in the wrong place. I made a few additions around the following lines to get the strings to match:

    let l:command = substitute(l:command, '/var', '/private/var', '')

https://github.com/dense-analysis/ale/blob/b91c6c2edd20794ad5637b561ed4c678647a76e5/autoload/ale/command.vim#L205-L211

    let l:temporary_file = substitute(l:temporary_file, '/var', '/private/var', '')

As well as tossing in an additional sub of temporary_file after line 209.

Didn't get what I wanted, but here's the :ALEInfo

(finished - exit code 0) ['/usr/local/bin/bash', '-c', 'cd ''/Users/kyle.chesney/projects/lintr/inst/example'' && Rscript --vanilla -e ''suppressPackageStartupMessages(library(lintr));lint(cache = FALSE, commandArgs(TRUE), with_defaults(line_length_linter(120)))'' ''/private/var/folders/0b/xf237__15dd662_s3sh1dpgc0000gn/T/vBGcNan/1/bad.R''']
<<<OUTPUT STARTS>>>
/private/var/folders/0b/xf237__15dd662_s3sh1dpgc0000gn/T/vBGcNan/1/bad.R:1:5: style: Use <-, not =, for assignment.

It's not lintr, but I checked out PR #3370 and it's working fine if anyone else needs an alternative.

ChemiKyle avatar Oct 09 '20 18:10 ChemiKyle

same issue here

christianrickert avatar Nov 24 '23 18:11 christianrickert