Skip to content

if-else must be either on the same line or surrounded by braces #229

Closed

Description

@krlmlr

Currently:

styler::style_text("{\n if (TRUE) 1\nelse 2\n}")
#> {
#>   if (TRUE) {
#>     1
#>   } else 2
#> }

The braces around 1 are fine, need braces around 2 as well.

Reference: tidyverse/tibble@1b53228#commitcomment-24759540

Activity

  1. lorenzwalthert commented on Oct 4, 2017

    @lorenzwalthert
    Collaborator

    It was actually implemented with that use case in mind. The idea was to only add parenthesis if the
    expression after if or else was on a new line for strict = TRUE.

    styler::style_text("{\n if (TRUE) 1\nelse \n2\n}")
    #> {
    #>   if (TRUE) {
    #>     1
    #>   } else {
    #>     2
    #>   }
    #> }

    With strict = FALSE, we do not add parentheses.

    styler::style_text("{\n if (TRUE) 1\nelse \n2\n}", strict = FALSE)
    #> {
    #>   if (TRUE) 1
    #>   else
    #>     2
    #> }
  2. lorenzwalthert commented on Oct 4, 2017

    @lorenzwalthert
    Collaborator

    So how does the concrete desired implementation look like? Maybe we can produce the result from strict = FALSE with the current strict = TRUE solution and change strict = TRUE to what you @krlmlr suggest?

  3. krlmlr commented on Oct 23, 2017

    @krlmlr
    MemberAuthor

    strict = TRUE should add braces also for the else part, strict = FALSE doesn't need to add any braces.

  4. added 2 commits that reference this issue on Oct 25, 2017
    d521511
    3523032
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions