Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.lintr defaults are not respected #235

Closed
pat-s opened this issue Mar 19, 2020 · 12 comments · Fixed by #236 or #284
Closed

.lintr defaults are not respected #235

pat-s opened this issue Mar 19, 2020 · 12 comments · Fixed by #236 or #284

Comments

@pat-s
Copy link

pat-s commented Mar 19, 2020

I have a .lintr file in my repo root and running lintr::lint_package() works fine.

However, the disabled linters are not honored from languageserver and still appear in the problems pane.

.lintr

linters: with_defaults(assignment_linter = NULL, object_name_linter = NULL)
@randy3k
Copy link
Member

randy3k commented Mar 19, 2020

What editor was it?

@pat-s
Copy link
Author

pat-s commented Mar 20, 2020

Ups sorry, forgot that you do editor-agnostic work here -> vscode.

@randy3k
Copy link
Member

randy3k commented Mar 20, 2020

By any chance, did you ever specified languageserver.default_linters in .Rprofile? That setting is now deprecated.

@renkun-ken
Copy link
Member

I could reproduce this.

It's actually a bug on our side. Since we use lintr::lint(text) at https://github.com/REditorSupport/languageserver/blob/master/R/diagnostics.R#L94, it writes the content to a temp file and no longer finds the .lintr config as the original file.

Since there's no exported functions for us to get the linters specified in the right config file, fixing it would be a little tricky. Any good idea, @randy3k?

@randy3k
Copy link
Member

randy3k commented Mar 20, 2020

@renkun-ken
Copy link
Member

renkun-ken commented Mar 20, 2020

It looks we could safely specify options(lintr.linter_file) in diagnose_file since it is run in a background process that does not affect the main process.

@renkun-ken
Copy link
Member

I test with setting options(lintr.linter_file) in diagnose_file as implemented in #236 and it works nicely.

@pat-s
Copy link
Author

pat-s commented Mar 20, 2020

Thanks for taking this on so quickly.

Unfortunately, linting is now completely broken for me (with latest dev).
I get

Failed to run diagnostics

in the "Problems" pane.

I had to roll back to b5ce3a8.

@renkun-ken renkun-ken reopened this Mar 20, 2020
@renkun-ken
Copy link
Member

@pat-s Would you like to turn on the R lsp debug and see the output of the languageserver. For example, if I put a .lintr that is not ended with a newline, then the diagnostics could fail with the following log:

[2020-03-20 19:33:58.370] diagnostics_task: <callr_status_error: callr subprocess failed: Malformed config file, ensure it ends in a newline
  zero-length inputs cannot be mixed with those of non-zero length>
 in process 
-->
<callr_remote_error: Malformed config file, ensure it ends in a newline
  zero-length inputs cannot be mixed with those of non-zero length>
 in process 48797 

To ensure your .lintr actually work, please check if your .lintr works with your file:

lintr::lint("path/to/your_file.R")

@renkun-ken
Copy link
Member

Looks like we should write the error message as the diagnostics message to make it easier to debug.

@renkun-ken
Copy link
Member

renkun-ken commented Mar 20, 2020

d6dba1b shows the diagnostics error. Please try it and let us know the error shown in the diagnostics.

For example, if the .lintr if malformed, then the message will show like

Failed to run diagnostics: callr subprocess failed: <text>:2:0: unexpected end of input
1: with_defaults(assignment_linter = NULL, object_name_linter = NULL
   ^

@pat-s
Copy link
Author

pat-s commented Mar 20, 2020

Thanks @renkun-ken for helping.

With latest dev, the diagnostic message I get is unfortunately not that much informative:

Failed to run diagnostics: callr subprocess failed: attempt to apply non-function

With languageserver diagnostics I get

<callr_remote_error in linters[[linter]](expr):
 attempt to apply non-function>
 in process 92379

Seems like something is wrong within the R script as I get

lintr::lint("~/git/mlr3learners/mlr3learners.fnn/R/LearnerClassifFNN.R")                                                    
Error in linters[[linter]](expr) : attempt to apply non-function

File

The call works with default linters, i.e. linters: with_defaults() in .lintr.

This is also fine linters: with_defaults(assignment_linter = NULL)

And the following causes the issue: linters: with_defaults(object_name_linter = c("snake_case", "CamelCase"))


I think it is an {lintr} issue: r-lib/lintr#471

Nevertheless the latest changes should help users tracking down issues in the future! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants