File: absolute_path_linter.R

package info (click to toggle)
r-cran-lintr 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,396 kB
  • sloc: sh: 13; xml: 10; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#' Absolute path linter
#'
#' Check that no absolute paths are used (e.g. "/var", "C:\\System", "~/docs").
#'
#' @param lax Less stringent linting, leading to fewer false positives.
#' If `TRUE`, only lint path strings, which
#'
#' * contain at least two path elements, with one having at least two characters and
#' * contain only alphanumeric chars (including UTF-8), spaces, and win32-allowed punctuation
#'
#' @examples
#' # will produce lints
#' lint(
#'   text = 'R"--[/blah/file.txt]--"',
#'   linters = absolute_path_linter()
#' )
#'
#' # okay
#' lint(
#'   text = 'R"(./blah)"',
#'   linters = absolute_path_linter()
#' )
#'
#' @evalRd rd_tags("absolute_path_linter")
#' @seealso
#' - [linters] for a complete list of linters available in lintr.
#' - [nonportable_path_linter()]
#' @export
absolute_path_linter <- function(lax = TRUE) {
  path_linter_factory(
    path_function = function(path) {
      is_absolute_path(path) && is_valid_long_path(path, lax)
    },
    message = "Do not use absolute paths."
  )
}