Search code examples
rlintr

Specify linters in lintr::lint


I cannot figure out how to turn off specific linters using lintr. The documentation offers an example (for vim/syntastic, which is what I'm using), which is not very clear:

let g:syntastic_r_lintr_linters = "with_defaults(line_length_linter(120))"

Apparently all this does is change a default. Do I need to list all the linters I want to use here? Is there a way to exclude just a couple?

I assume there's something like

let g:syntastic_r_lintr_linters_nonportable_path_linter = 0

but I can't find the right syntax.

Apparently g:syntastic_r_lintr_linters is supposed to be a list of linters. But it's not clear what syntax is supposed to work.

If we forget about the vim syntax and head right to the R package lintr (which vim/syntastic calls) and the linters argument of lint then this works:

lint(file.R, linters=assignment_linter)

This doesn't (no error, but doesn't catch mistakes in code):

lint(file.R, linters=list(assignment_linter, single_quotes_linter))

Nor does this (errors out):

lint(file.R, linters=list('assignment_linter', 'single_quotes_linter'))

But this does:

lint('file.R',linters=list('assignment_linter'=assignment_linter,'single_quotes_linter'=single_quotes_linter))

So maybe it's supposed to be a named list?


Solution

  • The correct syntax to turn off specific linters is to add this (for example) to vimrc:

    let g:syntastic_r_lintr_linters = "with_defaults(single_quotes_linter=NULL)"
    

    This is not in the documentation. I had to dig through some old (closed) issues on github to find this.

    Furthermore, lintr::lint does indeed expect a named list for the linters argument, but will now accept an unnamed list (see https://github.com/jimhester/lintr/issues/224). So this should work to make a list from scratch:

    let g:syntastic_r_lintr_linters = "list(assignment_linter, single_quotes_linter")