Skip to content

Deprecate use_tidy_style() #2138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If you’ve found a bug, please file an issue that illustrates the bug with a mi
### Code style

* New code should follow the tidyverse [style guide](https://style.tidyverse.org).
You can use the [styler](https://CRAN.R-project.org/package=styler) package to apply these styles, but please don't restyle code that has nothing to do with your PR.
You can use [Air](https://posit-dev.github.io/air/) to apply this style, but please don't restyle code that has nothing to do with your PR.

* We use [roxygen2](https://cran.r-project.org/package=roxygen2), with [Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/rd-formatting.html), for documentation.

Expand Down
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Suggests:
rmarkdown,
roxygen2 (>= 7.1.2),
spelling (>= 1.2),
styler (>= 1.2.0),
testthat (>= 3.1.8)
Config/Needs/website: r-lib/asciicast, tidyverse/tidytemplate, xml2
Config/testthat/edition: 3
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* `use_air()` is a new function to configure a project to use
[Air](https://posit-dev.github.io/air), an extremely fast R code formatter.

* `use_tidy_style()` is deprecated, in favor of using Air for any new, explicit
formatting efforts (#2110).

* `use_package(min_version = FALSE)` is treated the same as when `min_version`
is not specified (#2117, @salim-b).

Expand Down
44 changes: 0 additions & 44 deletions R/tidyverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@
#' * `use_tidy_logo()` calls `use_logo()` on the appropriate hex sticker PNG
#' file at <https://github.com/rstudio/hex-stickers>.
#'
#' @section `use_tidy_style()`:
#' Uses the [styler package](https://styler.r-lib.org) package to style all code
#' in a package, project, or directory, according to the [tidyverse style
#' guide](https://style.tidyverse.org).
#'
#' **Warning:** This function will overwrite files! It is strongly suggested to
#' only style files that are under version control or to first create a backup
#' copy.
#'
#' Invisibly returns a data frame with one row per file, that indicates whether
#' styling caused a change.
#'
#' @param strict Boolean indicating whether or not a strict version of styling
#' should be applied. See [styler::tidyverse_style()] for details.
#'
#' @name tidyverse
NULL

Expand Down Expand Up @@ -216,35 +201,6 @@ use_dot_github <- function(ignore = TRUE) {
use_git_ignore("*.html", directory = ".github")
}

#' @export
#' @rdname tidyverse
use_tidy_style <- function(strict = TRUE) {
check_installed("styler")
challenge_uncommitted_changes(
msg = "
There are uncommitted changes and it is highly recommended to get into a \\
clean Git state before restyling your project's code"
)
if (is_package()) {
styled <- styler::style_pkg(
proj_get(),
style = styler::tidyverse_style,
strict = strict
)
} else {
styled <- styler::style_dir(
proj_get(),
style = styler::tidyverse_style,
strict = strict
)
}
ui_bullets(c(
" " = "",
"v" = "Styled project according to the tidyverse style guide."
))
invisible(styled)
}

#' Identify contributors via GitHub activity
#'
#' Derives a list of GitHub usernames, based on who has opened issues or pull
Expand Down
23 changes: 23 additions & 0 deletions R/usethis-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ use_rscloud_badge <- function(url) {
#' systematically import and re-export a large number of functions in order
#' to use tidy evaluation. Instead, use [use_import_from()] to tactically
#' import functions as you need them.
#' * `use_tidy_style()` is deprecated because tidyverse packages are moving
#' towards the use of [Air](https://posit-dev.github.io/air/) for formatting.
#' See [use_air()] for how to start using Air. To continue using the styler
#' package, see `styler::style_pkg()` and `styler::style_dir()`.
#'
#' @keywords internal
#' @name tidy-deprecated
NULL

#' @export
#' @rdname tidy-deprecated
use_tidy_eval <- function() {
lifecycle::deprecate_stop(
"2.2.0",
Expand All @@ -56,6 +65,20 @@ use_tidy_eval <- function() {
)
}

#' @export
#' @rdname tidy-deprecated
use_tidy_style <- function(strict = TRUE) {
lifecycle::deprecate_warn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lifecycle::deprecate_warn(
lifecycle::deprecate_stop(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. In theory I'm on board with deprecate_stop(). But it felt like going from 0 to 60.

If anyone's got use_tidy_style() in teaching materials or personal workflow scripts or similar, it feels like an error versus warning might make a big difference. I went with deprecate_warning() since it feels like a state we should pass through.

Do you feel strongly that we go straight to deprecate_stop()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on a GitHub search, I do think we should at least pass through a deprecate_warn() phase.

when = "3.2.0",
what = "use_tidy_style()",
with = "use_air()",
details = glue(
"
To continue using the styler package, call `styler::style_pkg()` or `styler::style_dir()` directly."
)
)
}

# GitHub actions --------------------------------------------------------------

#' Deprecated GitHub Actions functions
Expand Down
3 changes: 1 addition & 2 deletions inst/templates/tidy-contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ See our guide on [how to create a great issue](https://code-review.tidyverse.org
### Code style

* New code should follow the tidyverse [style guide](https://style.tidyverse.org).
You can use the [styler](https://CRAN.R-project.org/package=styler) package to apply these styles, but please don't restyle code that has nothing to do with your PR.
You can use [Air](https://posit-dev.github.io/air/) to apply this style, but please don't restyle code that has nothing to do with your PR.

* We use [roxygen2](https://cran.r-project.org/package=roxygen2), with [Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/rd-formatting.html), for documentation.

Expand All @@ -45,4 +45,3 @@ See our guide on [how to create a great issue](https://code-review.tidyverse.org
Please note that the {{{ Package }}} project is released with a
[Contributor Code of Conduct](CODE_OF_CONDUCT.md). By contributing to this
project you agree to abide by its terms.

10 changes: 9 additions & 1 deletion man/use_tidy_eval.Rd → man/tidy-deprecated.Rd

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

19 changes: 0 additions & 19 deletions man/tidyverse.Rd

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

10 changes: 10 additions & 0 deletions tests/testthat/_snaps/usethis-deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@
i Instead import functions as needed, with e.g.:
i usethis::use_import_from("rlang", c(".data", ".env"))

# use_tidy_style() is deprecated

Code
use_tidy_style()
Condition
Warning:
`use_tidy_style()` was deprecated in usethis 3.2.0.
i Please use `use_air()` instead.
i To continue using the styler package, call `styler::style_pkg()` or `styler::style_dir()` directly.

27 changes: 0 additions & 27 deletions tests/testthat/test-tidyverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,3 @@ test_that("use_tidy_github() adds and Rbuildignores files", {
expect_proj_file(".github/CODE_OF_CONDUCT.md")
expect_true(is_build_ignored("^\\.github$"))
})

test_that("styling the package works", {
skip_if_no_git_user()
skip_if_not_installed("styler")

pkg <- create_local_package()
use_r("bad_style")
path_to_bad_style <- proj_path("R/bad_style.R")
write_utf8(path_to_bad_style, "a++2\n")
capture_output(use_tidy_style())
expect_identical(read_utf8(path_to_bad_style), "a + +2")
file_delete(path_to_bad_style)
})


test_that("styling of non-packages works", {
skip_if_no_git_user()
skip_if_not_installed("styler")

proj <- create_local_project()
path_to_bad_style <- proj_path("R/bad_style.R")
use_r("bad_style")
write_utf8(path_to_bad_style, "a++22\n")
capture_output(use_tidy_style())
expect_identical(read_utf8(path_to_bad_style), "a + +22")
file_delete(path_to_bad_style)
})
4 changes: 4 additions & 0 deletions tests/testthat/test-usethis-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ test_that("use_tidy_eval() is deprecated", {
pkg <- create_local_package()
expect_snapshot(use_tidy_eval(), error = TRUE)
})

test_that("use_tidy_style() is deprecated", {
expect_snapshot(use_tidy_style())
})
Loading