|
27 | 27 | #' This function overwrites files (if styling results in a change of the
|
28 | 28 | #' code to be formatted). It is strongly suggested to only style files
|
29 | 29 | #' that are under version control or to create a backup copy.
|
| 30 | +#' |
| 31 | +#' We suggest to first style with `scope < "tokens"` and inspect and commit |
| 32 | +#' changes, because these changes are guaranteed to leave the abstract syntax |
| 33 | +#' tree (AST) unchanged. See section 'Roundtrip Validation' for details. |
| 34 | +#' |
| 35 | +#' Then, we suggest to style with `scope = "tokens"` (if desired) and carefully |
| 36 | +#' inspect the changes to make sure the AST is not changed in an unexpected way |
| 37 | +#' that invalidates code. |
| 38 | +#' @section Roundtrip Validation: |
| 39 | +#' The following section describes when and how styling is guaranteed to |
| 40 | +#' yield correct code. |
| 41 | +#' |
| 42 | +#' If the style guide has `scope < "tokens"`, no tokens are changed and the |
| 43 | +#' abstract syntax tree (AST) should not change. |
| 44 | +#' Hence, it is possible to validate the styling by comparing whether the parsed |
| 45 | +#' expression before and after styling have the same AST. |
| 46 | +#' This comparison omits comments. styler compares |
| 47 | +#' error if the AST has changed through styling. |
| 48 | +#' |
| 49 | +#' Note that with `scope = "tokens"` such a comparison is not conducted because |
| 50 | +#' the AST might well change and such a change is intended. There is no way |
| 51 | +#' styler can validate styling, that is why we inform the user to carefully |
| 52 | +#' inspect the changes. |
| 53 | +#' |
| 54 | +#' See section 'Warning' for a good strategy to apply styling safely. |
30 | 55 | #' @inheritSection transform_files Value
|
31 | 56 | #' @family stylers
|
32 | 57 | #' @examples
|
@@ -112,6 +137,7 @@ style_text <- function(text,
|
112 | 137 | #' @inheritParams style_pkg
|
113 | 138 | #' @inheritSection transform_files Value
|
114 | 139 | #' @inheritSection style_pkg Warning
|
| 140 | +#' @inheritSection style_pkg Roundtrip Validation |
115 | 141 | #' @family stylers
|
116 | 142 | #' @examples
|
117 | 143 | #' \dontrun{
|
@@ -154,6 +180,7 @@ prettify_any <- function(transformers, filetype, recursive, exclude_files) {
|
154 | 180 | #' @inheritParams style_pkg
|
155 | 181 | #' @inheritSection transform_files Value
|
156 | 182 | #' @inheritSection style_pkg Warning
|
| 183 | +#' @inheritSection style_pkg Roundtrip Validation |
157 | 184 | #' @examples
|
158 | 185 | #' # the following is identical but the former is more convenient:
|
159 | 186 | #' file <- tempfile("styler", fileext = ".R")
|
|
0 commit comments