Skip to content

Styling resulted in code that isn't parsable. #1070

@balthasars

Description

@balthasars

Hi there!

Thank you for your ongoing work on this great package!

Dealing with legacy code, I encountered code like this:

styler::style_text(
'whatever <- function(x) {
    if (is.vector(x)){
        {if(is.Date(x)){ mbspalte <- 1}
            }  #Label "seit dd.mm.yyyy"
    }
}
'
)
#> Error in `value[[3L]]()`:
#> ! Styling resulted in code that isn't parsable. This should not happen. Please file a bug report on GitHub (https://github.com/r-lib/styler/issues) using a reprex.

#> Backtrace:
#>      ▆
#>   1. ├─styler::style_text("whatever <- function(x) {\n    if (is.vector(x)){\n        {if(is.Date(x)){ mbspalte <- 1}\n            }  #Label \"seit dd.mm.yyyy\"\n    }\n}\n")
#>   2. │ └─styler (local) transformer(text)
#>   3. │   └─... %>% ...
#>   4. ├─purrr::when(...)
#>   5. └─styler:::parse_transform_serialize_r(...)
#>   6.   └─styler:::verify_roundtrip(text, text_out, parsable_only = !parse_tree_must_be_identical(transformers))
#>   7.     └─rlang::with_handlers(...)
#>   8.       └─base::tryCatch(.expr, error = `<fn>`)
#>   9.         └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>  10.           └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  11.             └─value[[3L]](cond)
#>  12.               └─rlang::abort(...)

Created on 2022-11-24 with reprex v2.0.2

Interestingly enough, removing the comment #Label "seit dd.mm.yyyy" resolves this issue.

styler::style_text(
  "whatever <- function(x) {
    if (is.vector(x)){
        {if(is.Date(x)){ mbspalte <- 1}
            }
    }
}
"
)
#> Warning: Could not use colored = TRUE, as the package prettycode is not
#> installed. Please install it if you want to see colored output or see `?
#> print.vertical` for more information.
#> whatever <- function(x) {
#>   if (is.vector(x)) {{ if (is.Date(x)) {
#>     mbspalte <- 1
#>   } }}
#> }

Created on 2022-11-24 with reprex v2.0.2

Thought this might be useful, cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions