Skip to content

Commit

Permalink
Format with devel-{styler} (#2692)
Browse files Browse the repository at this point in the history
* Format with devel-`{styler}`

* Update indentation_linter.R
  • Loading branch information
IndrajeetPatil authored Dec 4, 2024
1 parent 13c7682 commit 0de1d6d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 27 deletions.
3 changes: 3 additions & 0 deletions R/indentation_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,12 @@ indentation_linter <- function(indent = 2L, hanging_indent_style = c("tidy", "al
}

# Only lint non-empty lines if the indentation level doesn't match.
# TODO: remove styler ignore directives once tidyverse/style/issues/197 is resolved
# styler: off
bad_lines <- which(indent_levels != expected_indent_levels &
nzchar(trimws(source_expression$file_lines)) &
!in_str_const)
# styler: on
if (length(bad_lines) > 0L) {
# Suppress consecutive lints with the same indentation difference, to not generate an excessive number of lints
is_consecutive_lint <- c(FALSE, diff(bad_lines) == 1L)
Expand Down
9 changes: 6 additions & 3 deletions R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
#' @return An object of class `c("lints", "list")`, each element of which is a `"list"` object.
#'
#' @examples
#' # linting inline-code
#' lint("a = 123\n")
#' lint(text = "a = 123")
#'
#' # linting a file
#' f <- tempfile()
#' writeLines("a=1", f)
#' lint(f) # linting a file
#' lint("a = 123\n") # linting inline-code
#' lint(text = "a = 123") # linting inline-code
#' lint(f)
#' unlink(f)
#'
#' @export
Expand Down
5 changes: 3 additions & 2 deletions R/nested_pipe_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@
#' @seealso [linters] for a complete list of linters available in lintr.
#' @export
nested_pipe_linter <- function(
allow_inline = TRUE,
allow_outer_calls = c("try", "tryCatch", "withCallingHandlers")) {
allow_inline = TRUE,
allow_outer_calls = c("try", "tryCatch", "withCallingHandlers")
) {
multiline_and <- if (allow_inline) "@line1 != @line2 and" else ""
xpath <- glue("
(//PIPE | //SPECIAL[{ xp_text_in_table(magrittr_pipes) }])
Expand Down
5 changes: 3 additions & 2 deletions R/object_overwrite_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
#' - <https://style.tidyverse.org/syntax.html#object-names>
#' @export
object_overwrite_linter <- function(
packages = c("base", "stats", "utils", "tools", "methods", "graphics", "grDevices"),
allow_names = character()) {
packages = c("base", "stats", "utils", "tools", "methods", "graphics", "grDevices"),
allow_names = character()
) {
for (package in packages) {
if (!requireNamespace(package, quietly = TRUE)) {
cli_abort("Package {.pkg {package}} is required, but not available.")
Expand Down
11 changes: 6 additions & 5 deletions R/return_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@
#' - <https://style.tidyverse.org/functions.html?q=return#return>
#' @export
return_linter <- function(
return_style = c("implicit", "explicit"),
allow_implicit_else = TRUE,
return_functions = NULL,
except = NULL,
except_regex = NULL) {
return_style = c("implicit", "explicit"),
allow_implicit_else = TRUE,
return_functions = NULL,
except = NULL,
except_regex = NULL
) {
return_style <- match.arg(return_style)

check_except <- !allow_implicit_else || return_style == "explicit"
Expand Down
21 changes: 11 additions & 10 deletions R/unnecessary_nesting_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,17 @@
#' - [linters] for a complete list of linters available in lintr.
#' @export
unnecessary_nesting_linter <- function(
allow_assignment = TRUE,
allow_functions = c(
"switch",
"try", "tryCatch", "withCallingHandlers",
"quote", "expression", "bquote", "substitute",
"with_parameters_test_that",
"reactive", "observe", "observeEvent",
"renderCachedPlot", "renderDataTable", "renderImage", "renderPlot",
"renderPrint", "renderTable", "renderText", "renderUI"
)) {
allow_assignment = TRUE,
allow_functions = c(
"switch",
"try", "tryCatch", "withCallingHandlers",
"quote", "expression", "bquote", "substitute",
"with_parameters_test_that",
"reactive", "observe", "observeEvent",
"renderCachedPlot", "renderDataTable", "renderImage", "renderPlot",
"renderPrint", "renderTable", "renderText", "renderUI"
)
) {
exit_calls <- c("stop", "return", "abort", "quit", "q")
exit_call_expr <- glue("
expr[SYMBOL_FUNCTION_CALL[{xp_text_in_table(exit_calls)}]]
Expand Down
3 changes: 1 addition & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ read_lines <- function(file, encoding = settings$encoding, ...) {

# nocov start
# support for usethis::use_release_issue(). Make sure to use devtools::load_all() beforehand!
release_bullets <- function() {
}
release_bullets <- function() {}
# nocov end

# see issue #923, PR #2455 -- some locales ignore _ when running sort(), others don't.
Expand Down
9 changes: 6 additions & 3 deletions man/lint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0de1d6d

Please sign in to comment.