Skip to contents

Make a new list based on lintr's default linters. The result of this function is meant to be passed to the linters argument of lint(), or to be put in your configuration file.

Usage

linters_with_defaults(..., defaults = default_linters)

with_defaults(..., default = default_linters)

Arguments

...

Arguments of elements to change. If unnamed, the argument is automatically named. If the named argument already exists in the list of linters, it is replaced by the new element. If it does not exist, it is added. If the value is NULL, the linter is removed.

defaults, default

Default list of linters to modify. Must be named.

See also

  • linters_with_tags for basing off tags attached to linters, possibly across multiple packages.

  • all_linters for basing off all available linters in lintr.

  • available_linters to get a data frame of available linters.

  • linters for a complete list of linters available in lintr.

Examples

# When using interactively you will usually pass the result onto `lint` or `lint_package()`
f <- withr::local_tempfile(lines = "my_slightly_long_variable_name <- 2.3", fileext = "R")
lint(f, linters = linters_with_defaults(line_length_linter = line_length_linter(120)))
#> Warning: cannot open file '/tmp/RtmpAx0Ma8/file1813766547caR': No such file or directory
#> Error in file(con, "r"): cannot open the connection

# the default linter list with a different line length cutoff
my_linters <- linters_with_defaults(line_length_linter = line_length_linter(120))

# omit the argument name if you are just using different arguments
my_linters <- linters_with_defaults(defaults = my_linters, object_name_linter("camelCase"))

# remove assignment checks (with NULL), add absolute path checks
my_linters <- linters_with_defaults(
  defaults = my_linters,
  assignment_linter = NULL,
  absolute_path_linter()
)

# checking the included linters
names(my_linters)
#>  [1] "absolute_path_linter"             "brace_linter"                    
#>  [3] "commas_linter"                    "commented_code_linter"           
#>  [5] "cyclocomp_linter"                 "equals_na_linter"                
#>  [7] "function_left_parentheses_linter" "indentation_linter"              
#>  [9] "infix_spaces_linter"              "line_length_linter"              
#> [11] "object_length_linter"             "object_name_linter"              
#> [13] "object_usage_linter"              "paren_body_linter"               
#> [15] "pipe_continuation_linter"         "quotes_linter"                   
#> [17] "semicolon_linter"                 "seq_linter"                      
#> [19] "spaces_inside_linter"             "spaces_left_parentheses_linter"  
#> [21] "T_and_F_symbol_linter"            "trailing_blank_lines_linter"     
#> [23] "trailing_whitespace_linter"       "vector_logic_linter"             
#> [25] "whitespace_linter"