jsonrsublimetext3sublime-text-pluginsublimelinter

Configure the behaviour of R linters in Sublime 3


I am using lintr in Sublime 3 via SublimeLinter 3 and the SublimeLinter-contrib-lintr plugin. On the lintr README.md file there is a short mention on how to configure what linters should be used:

{
  "user": {
    "linters": {
      "r": {
        "linters": "with_defaults(line_length_linter(120))"
      }
    }
  }
}

However, I am using it in conjunction with SublimeLinter-contrib-lintr and I can't get it to work. My SublimeLinter.sublime-settings file looks like this:

{
    "user": {
        "debug": true,
        "delay": 0.25,
        "error_color": "D02000",
        "gutter_theme": "Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme",
        "gutter_theme_excludes": [],
        "lint_mode": "background",
        "linters": {
            "lintr": {
                "@disable": false,
                "args": [],
                "cache": "TRUE",
                "excludes": [],
                "linters": "default_linters"
            }
        },
        "mark_style": "outline",
        "no_column_highlights_line": false,
        "passive_warnings": false,
        "paths": {
            "linux": [],
            "osx": [],
            "windows": [
                "C:/Program Files/R/R-3.3.3/bin/x64"
            ]
        },
        "python_paths": {
            "linux": [],
            "osx": [],
            "windows": []
        },
        "rc_search_limit": 3,
        "shell_timeout": 10,
        "show_errors_on_save": false,
        "show_marks_in_minimap": true,
        "syntax_map": {
            "r extended": "r"
        },
        "warning_color": "DDB700",
        "wrap_find": true
    }
}

The lintr package has a bunch of linters (see this link). What I would live to achieve is to discard some of them (i.e., not use, for instance, assignment_linter). Do you have any idea how to achieve this? It should be possible, right?


Edit 1:

I noticed that by changing "linters": "default_linters" to "linters": "assignment_linter", only the errors falling under assignment_linter will be picked. I tried to expand it using an array, but it doesn't work:

...
"lintr": {
    "@disable": false,
    "args": [],
    "cache": "TRUE",
    "excludes": [],
    "linters": [
        "assignment_linter",
        "object_name_linter"
    ]
}
...

Inside the Sublime 3 console, the message error message with this attempt is: Error: unexpected '[' in "lint(cache = TRUE, commandArgs(TRUE), [".


Edit 2: possible solution

Looking at with_defaults inside the lintr package I found two ways of choosing only the linters I am interested in. Assuming that I only want assignment_linter and no_tab_linter, the configuration is:

It works, but are there other less error-prone approaches? With this approach if I want to discard just one linter I have to list all the others.


Solution

  • Regarding your question for "Edit 2", you can discard a single linter as follows:

    {
      "user": {
        "linters": {
          "r": {
            "linters": "with_defaults(some_default_linter = NULL)"
          }
        }
      }
    }
    

    ... where some_default_linter is the name of a linter from the list lintr::default_linters.