-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move path linters to their own files (#1723)
* Move path linters to their own files To have a one-to-one correspondence between linter and its test file * redocument * Update collate * address review comments
- Loading branch information
1 parent
49e935b
commit dd11338
Showing
6 changed files
with
60 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#' 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 | ||
#' | ||
#' @examplesIf getRversion() >= "4.0" | ||
#' # Following examples use raw character constant syntax introduced in R 4.0. | ||
#' | ||
#' # 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. \cr | ||
#' [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." | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#' Non-portable path linter | ||
#' | ||
#' Check that [file.path()] is used to construct safe and portable paths. | ||
#' | ||
#' @inheritParams absolute_path_linter | ||
#' @evalRd rd_tags("nonportable_path_linter") | ||
#' @seealso [linters] for a complete list of linters available in lintr. \cr | ||
#' [absolute_path_linter()] | ||
#' @export | ||
nonportable_path_linter <- function(lax = TRUE) { | ||
path_linter_factory( | ||
path_function = function(path) { | ||
is_path(path) && is_valid_long_path(path, lax) && path != "/" && | ||
re_matches(path, rex(one_of("/", "\\"))) | ||
}, | ||
message = "Use file.path() to construct portable file paths." | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.