Skip to content

Commit 3d9e6d7

Browse files
Remove '::' from more frequent calls from {rex}, {utils} (#2079)
* extend conjunct_test_linter for dplyr::filter() * move commented code to PR * another round of ubiquitously used functions without :: qualification * forgot to branch from main * one more vestigial * restore utils:: --------- Co-authored-by: AshesITR <[email protected]>
1 parent 0e3eb9d commit 3d9e6d7

16 files changed

+45
-46
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ importFrom(rex,rex)
155155
importFrom(stats,na.omit)
156156
importFrom(utils,capture.output)
157157
importFrom(utils,getParseData)
158+
importFrom(utils,globalVariables)
158159
importFrom(utils,head)
159160
importFrom(utils,relist)
160161
importFrom(utils,tail)

R/aaa.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ NULL
2121
# need to register rex shortcuts as globals to avoid CRAN check errors
2222
rex::register_shortcuts("lintr")
2323

24-
utils::globalVariables(
24+
globalVariables(
2525
c(
2626
"line1", "col1", "line2", "col2", # columns of parsed_content
2727
"id", "parent", "token", "terminal", "text" # ditto

R/comment_linters.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ commented_code_linter <- function() {
8484
code_candidates <- re_matches(all_comments, code_candidate_regex, global = FALSE, locations = TRUE)
8585
extracted_code <- code_candidates[, "code"]
8686
# ignore trailing ',' when testing for parsability
87-
extracted_code <- rex::re_substitutes(extracted_code, rex::rex(",", any_spaces, end), "")
88-
extracted_code <- rex::re_substitutes(extracted_code, rex::rex(start, any_spaces, ","), "")
87+
extracted_code <- re_substitutes(extracted_code, rex(",", any_spaces, end), "")
88+
extracted_code <- re_substitutes(extracted_code, rex(start, any_spaces, ","), "")
8989
is_parsable <- which(vapply(extracted_code, parsable, logical(1L)))
9090

9191
lint_list <- xml_nodes_to_lints(

R/exclude.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ parse_exclusions <- function(file, exclude = settings$exclude,
110110
return(list())
111111
}
112112

113-
start_locations <- rex::re_matches(lines, exclude_start, locations = TRUE)[, "end"] + 1L
114-
end_locations <- rex::re_matches(lines, exclude_end, locations = TRUE)[, "start"]
113+
start_locations <- re_matches(lines, exclude_start, locations = TRUE)[, "end"] + 1L
114+
end_locations <- re_matches(lines, exclude_end, locations = TRUE)[, "start"]
115115
starts <- which(!is.na(start_locations))
116116
ends <- which(!is.na(end_locations))
117117

@@ -125,20 +125,20 @@ parse_exclusions <- function(file, exclude = settings$exclude,
125125
for (i in seq_along(starts)) {
126126
excluded_lines <- seq(starts[i], ends[i])
127127
linters_string <- substring(lines[starts[i]], start_locations[starts[i]])
128-
linters_string <- rex::re_matches(linters_string, exclude_linter)[, 1L]
128+
linters_string <- re_matches(linters_string, exclude_linter)[, 1L]
129129

130130
exclusions <- add_exclusions(exclusions, excluded_lines, linters_string, exclude_linter_sep, linter_names)
131131
}
132132
}
133133

134-
nolint_locations <- rex::re_matches(lines, exclude, locations = TRUE)[, "end"] + 1L
134+
nolint_locations <- re_matches(lines, exclude, locations = TRUE)[, "end"] + 1L
135135
nolints <- which(!is.na(nolint_locations))
136136
# Disregard nolint tags if they also match nolint start / end
137137
nolints <- setdiff(nolints, c(starts, ends))
138138

139139
for (i in seq_along(nolints)) {
140140
linters_string <- substring(lines[nolints[i]], nolint_locations[nolints[i]])
141-
linters_string <- rex::re_matches(linters_string, exclude_linter)[, 1L]
141+
linters_string <- re_matches(linters_string, exclude_linter)[, 1L]
142142
exclusions <- add_exclusions(exclusions, nolints[i], linters_string, exclude_linter_sep, linter_names)
143143
}
144144

R/extract.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,16 @@ defines_knitr_engine <- function(start_lines) {
137137
engines <- names(knitr::knit_engines$get())
138138

139139
# {some_engine}, {some_engine label, ...} or {some_engine, ...}
140-
bare_engine_pattern <- rex::rex(
140+
bare_engine_pattern <- rex(
141141
"{", or(engines), one_of("}", " ", ",")
142142
)
143143
# {... engine = "some_engine" ...}
144-
explicit_engine_pattern <- rex::rex(
144+
explicit_engine_pattern <- rex(
145145
boundary, "engine", any_spaces, "="
146146
)
147147

148-
rex::re_matches(start_lines, explicit_engine_pattern) |
149-
rex::re_matches(start_lines, bare_engine_pattern)
148+
re_matches(start_lines, explicit_engine_pattern) |
149+
re_matches(start_lines, bare_engine_pattern)
150150
}
151151

152152
replace_prefix <- function(lines, prefix_pattern) {

R/get_source_expressions.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ fixup_line <- function(line) {
185185
#'
186186
#' @noRd
187187
lint_parse_error_r43 <- function(e, source_expression) {
188-
msg <- rex::re_substitutes(e$message, rex::rex(" (", except_some_of(")"), ")", end), "")
188+
msg <- re_substitutes(e$message, rex(" (", except_some_of(")"), ")", end), "")
189189
line_number <- e$lineno
190190
column <- e$colno
191191
substr(msg, 1L, 1L) <- toupper(substr(msg, 1L, 1L))
@@ -621,7 +621,7 @@ fix_eq_assigns <- function(pc) {
621621

622622
eq_assign_locs <- which(pc$token == "EQ_ASSIGN")
623623
# check whether the equal-assignment is the final entry
624-
if (length(eq_assign_locs) == 0L || utils::tail(eq_assign_locs, 1L) == nrow(pc)) {
624+
if (length(eq_assign_locs) == 0L || tail(eq_assign_locs, 1L) == nrow(pc)) {
625625
return(pc)
626626
}
627627

R/indentation_linter.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ indentation_linter <- function(indent = 2L, hanging_indent_style = c("tidy", "al
189189
({xp_or(paste0('descendant::', paren_tokens_left, '[', xp_last_on_line, ']'))})
190190
]/@line1
191191
)]"),
192-
glue::glue("({ global_nodes(infix_tokens) })[{xp_last_on_line}{infix_condition}]"),
193-
glue::glue("({ global_nodes(no_paren_keywords) })[{xp_last_on_line}]"),
194-
glue::glue("
192+
glue("({ global_nodes(infix_tokens) })[{xp_last_on_line}{infix_condition}]"),
193+
glue("({ global_nodes(no_paren_keywords) })[{xp_last_on_line}]"),
194+
glue("
195195
({ global_nodes(keyword_tokens) })
196196
/following-sibling::OP-RIGHT-PAREN[
197197
{xp_last_on_line} and
@@ -223,9 +223,9 @@ indentation_linter <- function(indent = 2L, hanging_indent_style = c("tidy", "al
223223
# + if there is no token following ( on the same line, a block indent is required until )
224224
# - binary operators where the second arguments starts on a new line
225225

226-
indent_levels <- rex::re_matches(
226+
indent_levels <- re_matches(
227227
source_expression$file_lines,
228-
rex::rex(start, any_spaces), locations = TRUE
228+
rex(start, any_spaces), locations = TRUE
229229
)[, "end"]
230230
expected_indent_levels <- integer(length(indent_levels))
231231
is_hanging <- logical(length(indent_levels))

R/lint.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ lint <- function(filename, linters = NULL, ..., cache = FALSE, parse_settings =
3939
stop("'cache' is no longer available as a positional argument; please supply 'cache' as a named argument instead.")
4040
}
4141

42-
needs_tempfile <- missing(filename) || rex::re_matches(filename, rex::rex(newline))
42+
needs_tempfile <- missing(filename) || re_matches(filename, rex(newline))
4343
inline_data <- !is.null(text) || needs_tempfile
4444
lines <- get_lines(filename, text)
4545

@@ -125,7 +125,7 @@ lint <- function(filename, linters = NULL, ..., cache = FALSE, parse_settings =
125125
lint_dir <- function(path = ".", ...,
126126
relative_path = TRUE,
127127
exclusions = list("renv", "packrat"),
128-
pattern = rex::rex(".", one_of("Rr"), or("", "html", "md", "nw", "rst", "tex", "txt"), end),
128+
pattern = rex(".", one_of("Rr"), or("", "html", "md", "nw", "rst", "tex", "txt"), end),
129129
parse_settings = TRUE) {
130130
if (has_positional_logical(list(...))) {
131131
stop(
@@ -738,7 +738,7 @@ maybe_append_error_lint <- function(lints, error, lint_cache, filename) {
738738
get_lines <- function(filename, text) {
739739
if (!is.null(text)) {
740740
strsplit(paste(text, collapse = "\n"), "\n", fixed = TRUE)[[1L]]
741-
} else if (rex::re_matches(filename, rex::rex(newline))) {
741+
} else if (re_matches(filename, rex(newline))) {
742742
strsplit(gsub("\n$", "", filename), "\n", fixed = TRUE)[[1L]]
743743
} else {
744744
read_lines(filename)

R/lintr-package.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
"_PACKAGE"
99

1010
## lintr namespace: start
11+
#' @importFrom cyclocomp cyclocomp
1112
#' @importFrom glue glue glue_collapse
1213
#' @importFrom rex rex regex re_matches re_substitutes character_class
1314
#' @importFrom stats na.omit
14-
#' @importFrom utils capture.output head getParseData relist
15+
#' @importFrom utils capture.output getParseData globalVariables head relist tail
1516
#' @importFrom xml2 xml_attr xml_find_all xml_find_chr xml_find_num xml_find_first xml_name xml_text as_list
16-
#' @importFrom cyclocomp cyclocomp
17-
#' @importFrom utils tail
1817
#' @rawNamespace
1918
#' if (getRversion() >= "4.0.0") {
2019
#' importFrom(tools, R_user_dir)

R/methods.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ trim_output <- function(x, max = 65535L) {
121121
# otherwise trim x to the max, then search for the lint starts
122122
x <- substr(x, 1L, max)
123123

124-
re <- rex::rex(
124+
re <- rex(
125125
"[", except_some_of(":"), ":", numbers, ":", numbers, ":", "]",
126126
"(", except_some_of(")"), ")",
127127
space,
@@ -133,7 +133,7 @@ trim_output <- function(x, max = 65535L) {
133133
except_some_of("\r\n"), newline
134134
)
135135

136-
lint_starts <- rex::re_matches(x, re, global = TRUE, locations = TRUE)[[1L]]
136+
lint_starts <- re_matches(x, re, global = TRUE, locations = TRUE)[[1L]]
137137

138138
# if at least one lint ends before the cutoff, cutoff there, else just use
139139
# the cutoff

R/object_usage_linter.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ object_usage_linter <- function(interpret_glue = TRUE, skip_with = TRUE) {
5959

6060
pkg_name <- pkg_name(find_package(dirname(source_expression$filename)))
6161

62-
declared_globals <- try_silently(utils::globalVariables(package = pkg_name %||% globalenv()))
62+
declared_globals <- try_silently(globalVariables(package = pkg_name %||% globalenv()))
6363

6464
xml <- source_expression$full_xml_parsed_content
6565

@@ -93,7 +93,7 @@ object_usage_linter <- function(interpret_glue = TRUE, skip_with = TRUE) {
9393

9494
# TODO handle assignment functions properly
9595
# e.g. `not_existing<-`(a, b)
96-
res$name <- rex::re_substitutes(res$name, rex::rex("<-"), "")
96+
res$name <- re_substitutes(res$name, rex("<-"), "")
9797

9898
lintable_symbols <- xml_find_all(fun_assignment, xpath_culprit_symbol)
9999

R/shared_constants.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
rx_non_active_char <- rex::rex(none_of("^${(.*+?|[\\"))
1+
rx_non_active_char <- rex(none_of("^${(.*+?|[\\"))
22
rx_static_escape <- local({
3-
rx_char_escape <- rex::rex(or(
3+
rx_char_escape <- rex(or(
44
group("\\", none_of(alnum)),
55
group("\\x", between(xdigit, 1L, 2L)),
66
group("\\", between("0":"7", 1L, 3L)),
@@ -9,7 +9,7 @@ rx_static_escape <- local({
99
group("\\U{", between(xdigit, 1L, 8L), "}"),
1010
group("\\U", between(xdigit, 1L, 8L))
1111
))
12-
rx_trivial_char_group <- rex::rex(
12+
rx_trivial_char_group <- rex(
1313
"[",
1414
or(
1515
any,
@@ -18,21 +18,21 @@ rx_static_escape <- local({
1818
),
1919
"]"
2020
)
21-
rex::rex(or(
21+
rex(or(
2222
capture(rx_char_escape, name = "char_escape"),
2323
capture(rx_trivial_char_group, name = "trivial_char_group")
2424
))
2525
})
2626

2727
rx_static_token <- local({
28-
rex::rex(or(
28+
rex(or(
2929
rx_non_active_char,
3030
rx_static_escape
3131
))
3232
})
3333

34-
rx_static_regex <- paste0("(?s)", rex::rex(start, zero_or_more(rx_static_token), end))
35-
rx_first_static_token <- paste0("(?s)", rex::rex(start, zero_or_more(rx_non_active_char), rx_static_escape))
34+
rx_static_regex <- paste0("(?s)", rex(start, zero_or_more(rx_static_token), end))
35+
rx_first_static_token <- paste0("(?s)", rex(start, zero_or_more(rx_non_active_char), rx_static_escape))
3636

3737
#' Determine whether a regex pattern actually uses regex patterns
3838
#'
@@ -98,7 +98,7 @@ get_token_replacement <- function(token_content, token_type) {
9898
token_content
9999
}
100100
} else { # char_escape token
101-
if (rex::re_matches(token_content, rex::rex("\\", one_of("^${}().*+?|[]\\<>=:;/_-!@#%&,~")))) {
101+
if (re_matches(token_content, rex("\\", one_of("^${}().*+?|[]\\<>=:;/_-!@#%&,~")))) {
102102
substr(token_content, start = 2L, stop = nchar(token_content))
103103
} else {
104104
eval(parse(text = paste0('"', token_content, '"')))

R/unreachable_code_linter.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ unreachable_code_linter <- function() {
5454
bad_expr <- xml_find_all(xml, xpath)
5555

5656
is_nolint_end_comment <- xml2::xml_name(bad_expr) == "COMMENT" &
57-
rex::re_matches(xml_text(bad_expr), settings$exclude_end)
57+
re_matches(xml_text(bad_expr), settings$exclude_end)
5858

5959
xml_nodes_to_lints(
6060
bad_expr[!is_nolint_end_comment],

R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ linter_auto_name <- function(which = -3L) {
5757
if (re_matches(nm, regex)) {
5858
match <- re_matches(nm, regex, locations = TRUE)
5959
nm <- substr(nm, start = 1L, stop = match[1L, "end"])
60-
nm <- re_substitutes(nm, rex::rex(start, alnums, "::"), "")
60+
nm <- re_substitutes(nm, rex(start, alnums, "::"), "")
6161
}
6262
nm
6363
}

R/zzz.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,18 @@ settings <- NULL
298298
default_settings <<- list(
299299
linters = default_linters,
300300
encoding = "UTF-8",
301-
exclude = rex::rex("#", any_spaces, "nolint"),
302-
exclude_start = rex::rex("#", any_spaces, "nolint start"),
303-
exclude_end = rex::rex("#", any_spaces, "nolint end"),
304-
exclude_linter = rex::rex(
301+
exclude = rex("#", any_spaces, "nolint"),
302+
exclude_start = rex("#", any_spaces, "nolint start"),
303+
exclude_end = rex("#", any_spaces, "nolint end"),
304+
exclude_linter = rex(
305305
start, any_spaces, ":", any_spaces,
306306
capture(
307307
name = "linters",
308308
zero_or_more(one_or_more(none_of(",.")), any_spaces, ",", any_spaces),
309309
one_or_more(none_of(",."))
310310
), "."
311311
),
312-
exclude_linter_sep = rex::rex(any_spaces, ",", any_spaces),
312+
exclude_linter_sep = rex(any_spaces, ",", any_spaces),
313313
exclusions = list(),
314314
cache_directory = R_user_dir("lintr", "cache"),
315315
comment_token = Sys.getenv("GITHUB_TOKEN", unset = NA) %||% rot(

man/lint.Rd

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)