Skip to content

.lintr defaults are not respected #235

Closed

Description

@pat-s

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)

Activity

  1. randy3k commented on Mar 19, 2020

    @randy3k
    Member

    What editor was it?

  2. pat-s commented on Mar 20, 2020

    @pat-s
    Author

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

  3. randy3k commented on Mar 20, 2020

    @randy3k
    Member

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

  4. renkun-ken commented on Mar 20, 2020

    @renkun-ken
    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?

  5. randy3k commented on Mar 20, 2020

    @randy3k
    Member
  6. renkun-ken commented on Mar 20, 2020

    @renkun-ken
    Member

    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.

  7. renkun-ken commented on Mar 20, 2020

    @renkun-ken
    Member

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

  8. pat-s commented on Mar 20, 2020

    @pat-s
    Author

    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.

  9. renkun-ken commented on Mar 20, 2020

    @renkun-ken
    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")
    
  10. renkun-ken commented on Mar 20, 2020

    @renkun-ken
    Member

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

  11. renkun-ken commented on Mar 20, 2020

    @renkun-ken
    Member

    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
       ^
    
  12. pat-s commented on Mar 20, 2020

    @pat-s
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions