Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Dec 5, 2023
1 parent c1c83ee commit 9c99491
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion R/fixed_regex_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fixed_regex_linter <- function(allow_unescaped = FALSE) {
call_name <- xml_find_chr(patterns, "string(preceding-sibling::expr[last()]/SYMBOL_FUNCTION_CALL)")

is_stringr <- startsWith(call_name, "str_")
replace_suggestion <- ifelse(
replacement_suggestion <- ifelse(
is_stringr,
sprintf("stringr::fixed(%s) as the pattern", fixed_equivalent),
sprintf("%s with fixed = TRUE", fixed_equivalent)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-class_equals_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_that("class_equals_linter skips allowed usages", {

test_that("class_equals_linter blocks simple disallowed usages", {
linter <- class_equals_linter()
lint_msg <- rex::rex("Use inherits(x, 'class-name') or is.<class> or is(x, 'class')")
lint_msg <- rex::rex("Use inherits(x, 'class-name'), is.<class> or is(x, 'class')")

expect_lint("if (class(x) == 'character') stop('no')", lint_msg, linter)
expect_lint("is_regression <- class(x) == 'lm'", lint_msg, linter)
Expand All @@ -20,7 +20,7 @@ test_that("class_equals_linter blocks simple disallowed usages", {

test_that("class_equals_linter blocks usage of %in% for checking class", {
linter <- class_equals_linter()
lint_msg <- rex::rex("Use inherits(x, 'class-name') or is.<class> or is(x, 'class')")
lint_msg <- rex::rex("Use inherits(x, 'class-name'), is.<class> or is(x, 'class')")

expect_lint("if ('character' %in% class(x)) stop('no')", lint_msg, linter)
expect_lint("if (class(x) %in% 'character') stop('no')", lint_msg, linter)
Expand All @@ -29,7 +29,7 @@ test_that("class_equals_linter blocks usage of %in% for checking class", {
test_that("class_equals_linter blocks class(x) != 'klass'", {
expect_lint(
"if (class(x) != 'character') TRUE",
rex::rex("Use inherits(x, 'class-name') or is.<class> or is(x, 'class')"),
rex::rex("Use inherits(x, 'class-name'), is.<class> or is(x, 'class')"),
class_equals_linter()
)
})
Expand All @@ -43,7 +43,7 @@ test_that("class_equals_linter skips usage for subsetting", {
# but not further nesting
expect_lint(
"x[if (class(x) == 'foo') 1 else 2]",
rex::rex("Use inherits(x, 'class-name') or is.<class> or is(x, 'class')"),
rex::rex("Use inherits(x, 'class-name'), is.<class> or is(x, 'class')"),
linter
)
})
6 changes: 3 additions & 3 deletions tests/testthat/test-is_numeric_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test_that("is_numeric_linter skips allowed usages involving %in%", {

test_that("is_numeric_linter blocks disallowed usages involving ||", {
linter <- is_numeric_linter()
lint_msg <- rex::rex("Use `is.numeric(x)` instead of equivalent `is.numeric(x) || is.integer(x)`.")
lint_msg <- rex::rex("Use `is.numeric(x)` instead of the equivalent `is.numeric(x) || is.integer(x)`.")

expect_lint("is.numeric(x) || is.integer(x)", lint_msg, linter)

Expand Down Expand Up @@ -48,7 +48,7 @@ test_that("is_numeric_linter blocks disallowed usages involving ||", {

test_that("is_numeric_linter blocks disallowed usages involving %in%", {
linter <- is_numeric_linter()
lint_msg <- rex::rex('Use is.numeric(x) instead of equivalent class(x) %in% c("integer", "numeric")')
lint_msg <- rex::rex('Use is.numeric(x) instead of the equivalent class(x) %in% c("integer", "numeric")')

expect_lint("class(x) %in% c('integer', 'numeric')", lint_msg, linter)
expect_lint('class(x) %in% c("numeric", "integer")', lint_msg, linter)
Expand All @@ -58,7 +58,7 @@ test_that("raw strings are handled properly when testing in class", {
skip_if_not_r_version("4.0.0")

linter <- is_numeric_linter()
lint_msg <- rex::rex('Use is.numeric(x) instead of equivalent class(x) %in% c("integer", "numeric")')
lint_msg <- rex::rex('Use is.numeric(x) instead of the equivalent class(x) %in% c("integer", "numeric")')

expect_lint("class(x) %in% c(R'(numeric)', 'integer', 'factor')", NULL, linter)
expect_lint("class(x) %in% c('numeric', R'--(integer)--', y)", NULL, linter)
Expand Down

0 comments on commit 9c99491

Please sign in to comment.