vscode-R icon indicating copy to clipboard operation
vscode-R copied to clipboard

Less aggressive linting

Open grantmcdermott opened this issue 2 years ago • 14 comments

Is your feature request related to a problem? Please describe.

The default linter (based on the tiydverse style guide IIRC) is too aggressive IMO. Users get low-key scolded for simple and acceptable actions like using = for assignment or the use of single quotation marks.

While users can edit their ~/.lintr files to change these settings locally, I do think we can be less aggressive out of the gate. ~I see some linter settings have already been disabled here.~ Correction: As @eitsupi correctly points out, the linked .lintr file is just relevant for this repo itself (i.e., the dev experience) and does not affect the end-user’s linting behaviour when running the extension.

Describe the solution you'd like

Here's what my own .lintr file looks like:

linters: linters_with_defaults(
   line_length_linter    = NULL, # note: vscode-R default is 120
   cyclocomp_linter      = NULL, # same as vscode-R
   object_name_linter    = NULL, # same as vscode-R
   object_usage_linter   = NULL, # same as vscode-R
   commented_code_linter = NULL,
   assignment_linter     = NULL,
   seq_linter.           = NULL,
   no_tab_linter.        = NULL,
   semicolon_linter      = NULL,
   single_quotes_linter  = NULL
)

I don't want to suggest that all of my choices should become the default, but I do think some are probably a good idea (e.g., the aforementioned assignment_linter and single_quotes_linter).

Describe alternatives you've considered

Add a wiki page on linting. (Can still do in conjunction, but again I think we should permit certain behaviour out of the gate.)

grantmcdermott avatar Aug 07 '23 18:08 grantmcdermott

While users can edit their ~/.lintr files to change these settings locally, I do think we can be less aggressive out of the gate. I see some linter settings have already been disabled here.

Aren't these settings for R files in this repository and irrelevant to extension users?

eitsupi avatar Aug 07 '23 23:08 eitsupi

@eitsupi I think @grantmcdermott is referring to the defaulting linting options set by the extension, which lives in <vscode directory>/extensions/reditorsupport.r-2.8.2/R/.lintr and is used when no lintr file exists in the user or project directory.

mkoohafkan avatar Dec 21 '23 16:12 mkoohafkan

@mkoohafkan My understanding is that that file is never used for users. I think this is just a configuration file used for linting in this repository.

eitsupi avatar Dec 22 '23 15:12 eitsupi

Ah you're right, my mistake. Where does the extension get its default linting settings then? I can't find any other lint files in the VSCode directory (except for the Python extension, but that's unrelated).

mkoohafkan avatar Dec 22 '23 16:12 mkoohafkan

Please check https://lintr.r-lib.org/

eitsupi avatar Dec 22 '23 16:12 eitsupi

In other words, there is nothing peculiar to this extension. This is the default configuration for the lintr package

eitsupi avatar Dec 22 '23 16:12 eitsupi

@eitsupi VSCode is linting automatically though, users don't have the choice to "opt in" to linting (or opt out). Is the lintr package installed through language server or some other mechanism? To be clear, I never chose to install the lintr package---the extension does linting without any user input.

mkoohafkan avatar Dec 22 '23 16:12 mkoohafkan

@mkoohafkan I think it's more reliable to search within the documentation than to ask me. https://lintr.r-lib.org/articles/editors.html#visual-studio-code

eitsupi avatar Dec 22 '23 16:12 eitsupi

@eitsupi ok so the answer is yes, languageserver adds linting automatically and just uses the defaults from the lintr package. This is confusing to users because they have no way of controlling the linting rules through the extension or even toggling R linting on/off via VSCode.

Perhaps the solution here is to have an option in settings to enable/disable linting. Users would then have the option to:

  1. Enable/Disable R linting globally via user settings
  2. Enable/Disable R linting per project via project settings
  3. Customize linting by learning about the {lintr} package and creating their own .lintr files.

mkoohafkan avatar Dec 22 '23 17:12 mkoohafkan

Just spending 30 minutes trying to turn off the annoying lining message after installing this extension.

For people who are also trying to figure it out, the .lintr setting showed in this issue doesn't work for me. This works:

linters: linters_with_defaults(
   line_length_linter    = NULL, # note: vscode-R default is 120
   cyclocomp_linter      = NULL, # same as vscode-R
   object_name_linter    = NULL, # same as vscode-R
   object_usage_linter   = NULL, # same as vscode-R
   commented_code_linter = NULL,
   assignment_linter     = NULL,
   seq_linter           = NULL,
   semicolon_linter      = NULL)

albert-ying avatar May 19 '24 09:05 albert-ying

@eitsupi

In other words, there is nothing peculiar to this extension. This is the default configuration for the lintr package


Barring that, it looks like a VScode issue -- as noted they already ship a non-default `line_length_linter()`, so they should be willing to ship non-defaults for other linters too. It looks like that default config is here:

https://github.com/REditorSupport/vscode-R/blob/b196c7d8257a04509de68a3bfe7acf9c1f2fba85/R/.lintr#L2

Originally posted by @MichaelChirico in https://github.com/r-lib/lintr/issues/2592#issuecomment-2151000539


If there are already edits to the default lintr package settings there should be no problem with editing the default behavior in the vscode R package extension.

Jacinto27 avatar Jun 05 '24 22:06 Jacinto27

Hello. Just to add that I've tried many, many times, and no configuration in the .lintr file on <vscode directory>/extensions/reditorsupport.r-2.8.2/R/.lintr or ~\.lintr seems to work. Unfortunately, after many hours, I had to disable lsp.r.enabled. Frustrating. Please, fix this.

castellco avatar Jul 04 '24 00:07 castellco

I knowwww 😭 the documentation isn't very explicit, in my pr I've made sure to point out that it is in your home directory that you need to add the .lintr file, but I'm sure working with folders/workspaces is still vague and counterintuitive, once the PR is approved I'm thinking on making a more detailed guide on how to configure the extension for different workspaces.

Jacinto27 avatar Jul 04 '24 01:07 Jacinto27