Skip to content

Commit

Permalink
Merge branch 'main' into pipe_return
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Nov 19, 2023
2 parents e7630e4 + 9920110 commit cd74f81
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 78 deletions.
3 changes: 1 addition & 2 deletions R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ retrieve_lint <- function(cache, expr, linter, lines) {
)
if (is.na(new_line_number)) {
return(NULL)
} else {
lints[[i]]$line_number <- new_line_number
}
lints[[i]]$line_number <- new_line_number
}
cache_lint(cache, expr, linter, lints)
lints
Expand Down
20 changes: 0 additions & 20 deletions R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
#'
#' @export
lint <- function(filename, linters = NULL, ..., cache = FALSE, parse_settings = TRUE, text = NULL) {
if (has_positional_logical(list(...))) {
stop("'cache' is no longer available as a positional argument; please supply 'cache' as a named argument instead.")
}

check_dots(...names(), c("exclude", "parse_exclusions"))

needs_tempfile <- missing(filename) || re_matches(filename, rex(newline))
Expand Down Expand Up @@ -135,13 +131,6 @@ lint_dir <- function(path = ".", ...,
pattern = "(?i)[.](r|rmd|qmd|rnw|rhtml|rrst|rtex|rtxt)$",
parse_settings = TRUE,
show_progress = NULL) {
if (has_positional_logical(list(...))) {
stop(
"'relative_path' is no longer available as a positional argument; ",
"please supply 'relative_path' as a named argument instead. "
)
}

check_dots(...names(), c("lint", "exclude", "parse_exclusions"))

if (isTRUE(parse_settings)) {
Expand Down Expand Up @@ -235,15 +224,6 @@ lint_package <- function(path = ".", ...,
exclusions = list("R/RcppExports.R"),
parse_settings = TRUE,
show_progress = NULL) {
if (has_positional_logical(list(...))) {
# nocov start: dead code path
stop(
"'relative_path' is no longer available as a positional argument; ",
"please supply 'relative_path' as a named argument instead. "
)
# nocov end
}

if (length(path) > 1L) {
stop("Only linting one package at a time is supported.")
}
Expand Down
3 changes: 1 addition & 2 deletions R/settings_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ find_local_config <- function(path, config_file) {
pkg_name <- function(path = find_package()) {
if (is.null(path)) {
return(NULL)
} else {
read.dcf(file.path(path, "DESCRIPTION"), fields = "Package")[1L]
}
read.dcf(file.path(path, "DESCRIPTION"), fields = "Package")[1L]
}
24 changes: 0 additions & 24 deletions inst/example/complexity.R

This file was deleted.

35 changes: 29 additions & 6 deletions tests/testthat/test-cyclocomp_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,37 @@ test_that("returns the correct linting", {
"unexpected symbol", cc_linter_2
)

complexity <- readLines(
system.file("example/complexity.R", package = "lintr")
)
expect_lint(complexity, lint_msg, cc_linter_2)
complex_lines <- trim_some("
complexity <- function(x) {
if (x > 0.0) {
if (x > 10.0) {
if (x > 20.0) {
x <- x / 2.0
} else {
return(x)
}
} else {
return(x)
}
} else {
if (x < -10.0) {
if (x < -20.0) {
x <- x * 2.0
} else {
return(x)
}
} else {
return(x)
}
}
x
}
")
expect_lint(complex_lines, lint_msg, cc_linter_2)
expect_lint(
complexity,
complex_lines,
"should have cyclomatic complexity of less than 2, this has 10",
cc_linter_2
)
expect_lint(complexity, NULL, cyclocomp_linter(10L))
expect_lint(complex_lines, NULL, cyclocomp_linter(10L))
})
8 changes: 0 additions & 8 deletions tests/testthat/test-lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,6 @@ test_that("old compatibility usage errors", {
)
})

test_that("Deprecated positional usage of cache= errors", {
expect_error(
lint("a = 2\n", FALSE, linters = assignment_linter()),
"'cache' is no longer available as a positional argument",
fixed = TRUE
)
})

test_that("Linters throwing an error give a helpful error", {
tmp_file <- withr::local_tempfile(lines = "a <- 1")
linter <- function() Linter(function(source_expression) stop("a broken linter"))
Expand Down
10 changes: 0 additions & 10 deletions tests/testthat/test-lint_dir.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@ test_that("lint_dir works with specific linters without specifying other argumen
expect_length(lint_dir(the_dir, commented_code_linter(), parse_settings = FALSE), 0L)
})

test_that("lint_dir errors for relative_path= in 2nd positional argument", {
the_dir <- test_path("dummy_packages", "package", "vignettes")

expect_error(
lint_dir(the_dir, FALSE),
"'relative_path' is no longer available as a positional argument",
fixed = TRUE
)
})

test_that("typo in argument name gives helpful error", {
expect_error(lint_dir(litners = identity), "Found unknown arguments in [.][.][.].*[?]lint_dir ")
})
Expand Down
34 changes: 28 additions & 6 deletions tests/testthat/test-spaces_left_parentheses_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,35 @@ test_that("spaces_left_parentheses_linter blocks disallowed usages", {
})

test_that("doesn't produce a warning", {
# complexity.R contains a function with nested if-statements where the conditional includes a unary minus.
# this contains a function with nested if-statements where the conditional includes a unary minus.
# This specific constellation with another if-statement at the same nesting level on the other enclosing if-branch
# caused a warning in spaces_left_parentheses_linter (e.g. 84bc3a is broken)
complex_lines <- trim_some("
complexity <- function(x) {
if (x > 0.0) {
if (x > 10.0) {
if (x > 20.0) {
x <- x / 2.0
} else {
return(x)
}
} else {
return(x)
}
} else {
if (x < -10.0) {
if (x < -20.0) {
x <- x * 2.0
} else {
return(x)
}
} else {
return(x)
}
}
x
}
")

expect_silent(
lint(
system.file("example/complexity.R", package = "lintr")
)
)
expect_no_warning(lint(text = complex_lines, linters = spaces_left_parentheses_linter()))
})

0 comments on commit cd74f81

Please sign in to comment.