Skip to content

restart linting if .lintr file is created or modified #354

Closed

Description

@alex-gable

Is your feature request related to a problem? Please describe.
mildly annoying that I have to restart vscode as I modify linting rules

Describe the solution you'd like
vscode-R would restart the linting process or lsp if the .lintr file is modified with a change

Describe alternatives you've considered
expose the ability to restart the lsp/lintr process manually

Activity

  1. renkun-ken commented on Jun 7, 2020

    @renkun-ken
    Member

    linting is called by languageserver. You could always save your file to trigger linting if .lintr is changed. It will always use the latest rules defined in the .lintr.

  2. alex-gable commented on Jun 14, 2020

    @alex-gable
    ContributorAuthor

    @renkun-ken appreciate the feedback! Any idea where I can configure the “re-lint on .lintr save” setting?

    Also, appears that languageserver isn’t honoring the exclusions in my .lintr file. Not sure how to repro that behavior in a way that’s helpful, but wondering how I could debug that?

  3. renkun-ken commented on Jun 15, 2020

    @renkun-ken
    Member

    Any idea where I can configure the “re-lint on .lintr save” setting?

    Maybe I'm not saying it clearly. There's no "re-lint on .lintr save" but "re-lint on file save with latest .lintr. If you change your .lintr, you could always save your file being edited to trigger the linting and it will use the latest .lintr without having to restart.

    appears that languageserver isn’t honoring the exclusions in my .lintr file.

    languageserver calls lintr::lint_text in a separate process to perform the diagnostics and languageserver does not read your .lintr file but passes the file path to lintr and only the lintr package will read it.

    Looks like your .lintr is not written correctly. You may use lintr::lint_file("path/to/your/script.R") and see if the linting is producing expected results.

    A correct .lintr file to exclude some linters looks like the following:

    linters: with_defaults(assignment_linter = NULL, line_length_linter(120))
    
    
  4. alex-gable commented on Jun 20, 2020

    @alex-gable
    ContributorAuthor

    okay, so did some more playing around here with respect to diagnostics honoring the exclusions property in .lintr.

    I was able to confirm that find_config("path/to/my/script") does find and recognize that the project .lintr file. Furthermore, with a opening of the project, it appears language-server does honor the exclusions in .lintr, which I've left below for reference.

    linters: with_defaults(line_length_linter(88), object_usage_linter = NULL, commented_code_linter = NULL, seq_linter = NULL)
    exclusions: list("path/to/my/script.R")

    once I open the file, however, it begins linting the file, even though it's in the exclusions list that language-server formerly honored.

    That all being said, it:

    1. is likely not related to this package, but languageserver
    2. I believe is related to Exclusions read from .lintr are depedent of the current working directory r-lib/lintr#438

    Not sure if you want to leave this issue open to add the "on-save" feature still, seems like it'd be a hook on the workspace onDidSaveTextDocument event or potentially the onDidSaveConfiguration event.

  5. renkun-ken commented on Jun 20, 2020

    @renkun-ken
    Member

    Thanks for your testing.

    The exclusions not working is caused by languageserver trying to lint a temporary file (with user edits saved) rather than the real file in user workspace folder. The path in exclusions applies to the workspace folder but not the temp folder.

    To resolve this more easily, we filed an issue r-lib/lintr#475 but no action is taken yet. And this is indeed another issue of languageserver. Would you mind posting an issue about not respecting exclusions property in .lintr on langugeserver side and link back to this one?

  6. renkun-ken commented on Jun 27, 2021

    @renkun-ken
    Member

    Closing as resolved.

  7. raffaelemancuso commented on Jul 24, 2025

    @raffaelemancuso

    linting is called by languageserver. You could always save your file to trigger linting if .lintr is changed. It will always use the latest rules defined in the .lintr.

    I'm saving the file but the old linting rules are still applied

  8. raffaelemancuso commented on Jul 25, 2025

    @raffaelemancuso

    I'm saving the file but the old linting rules are still applied

    Found the solution.

    You have to reload the window with ctrl+shift+P -> Developer: Reload Window.

    See https://stackoverflow.com/a/79625871/1719931.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions