Skip to content

Line broken again after first named argument #342

Closed

Description

@lorenzwalthert

The below code should not be modified by styler.

styler::style_text(
"call(
  a, b = 3
)")
#> call(
#>   a,
#>   b = 3
#> )

Created on 2018-02-05 by the reprex package (v0.1.1.9000).

It seems as this undesired behaviour was introduced with #318.

Activity

  1. lorenzwalthert commented on Feb 5, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Similarly here, there is no reason to put a line break before the first named argument

    styler::style_text(
    "call(
      a, b, c, d, e = 3
    )")
    #> call(
    #>   a, b, c, d,
    #>   e = 3
    #> )

    Created on 2018-02-05 by the reprex package (v0.1.1.9000).

  2. lorenzwalthert commented on Feb 5, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Ok, maybe that needs to depend on the strict option.

  3. lorenzwalthert commented on Feb 26, 2018

    @lorenzwalthert
    CollaboratorAuthor

    In fact, solving this issue properly also needs #357, because a line break after the opening brace / or before the first unnamed argument also required an up-to-date multi-line attribute for a line break transformer.

  4. lorenzwalthert commented on Feb 26, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Reference: #357

  5. krlmlr commented on Feb 26, 2018

    @krlmlr
    Member

    I rather like this particular behavior, even if it was introduced by accident ;-)

    Everything seems to work right for single-line argument lists:

    styler::style_text(
    "call(a, b, c, d, e = 3
    )")
    #> call(a, b, c, d, e = 3)

    Created on 2018-02-26 by the reprex package (v0.2.0).

  6. lorenzwalthert commented on Feb 26, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Haha ok. Even the example you just created was not indented 😊. However, I think the current behaviour does not reflect the tidyverse style guide. In particular, see tidyverse/style#39.

  7. krlmlr commented on Feb 28, 2018

    @krlmlr
    Member

    I don't understand, can you please rephrase? I don't see the conflict with the style guide yet.

  8. lorenzwalthert commented on Feb 28, 2018

    @lorenzwalthert
    CollaboratorAuthor

    I mean it's not really a conflict, but in tidyverse/style#39, the idea was to keep the first few unnamed arguments on the same line as the opening parenthesis. Like

    map(x, f, 
      another_arg = 3
    )

    So far so good. However, if the code looks like this

    call(
      a, b = 3
    )

    styler should probably just leave it as is or move the a one line up, but it adds a line break after a, without removing the one before a.

    call(
      a,
      b = 3
    )

    So here, it's not the case that the first few unnamed arguments are on the same line as the opening brace.

  9. lorenzwalthert commented on Feb 28, 2018

    @lorenzwalthert
    CollaboratorAuthor

    I mean if you think that's fine, we can leave it, but I think the preferred behaviour would be to leave the code unchanged (best option in my eyes) or move the first argument one line up, but not add a line break after a without removing it before it.

  10. lorenzwalthert commented on Feb 28, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Blocked by #357.

  11. krlmlr commented on Mar 1, 2018

    @krlmlr
    Member

    I thought the preferred styling would be

    call(
      a,
      b = 3
    )

    and we use

    call(a,
      b = 3
    )

    only in exceptional situations?

  12. lorenzwalthert commented on Mar 1, 2018

    @lorenzwalthert
    CollaboratorAuthor

    It depends on the initial formatting.

    call(
      a,
      b = 3
    )

    should be returned unchanged. Also,

    call(a,
      b = 3
    )

    So should

    call(
      a, b = 3
    )

    But

    call(a, b = 3, 
      c = 3
    )

    should be turned into

    all(
      a, b = 3
    )

    And

    call(
      a, b = 3
    )

    should be left untouched and not turned into

    call(
      a, 
      b = 3
    )

    That's my understanding of tidyverse/style#39.

  13. krlmlr commented on Mar 2, 2018

    @krlmlr
    Member

    I don't mind the added newline when styling

    call(
      a, b = 3
    )

    because it's consistent with having named arguments on a separate line, similarly for the other example. But I think

    call(
      a, b =
        3
    )

    needs a line break before the b.

  14. lorenzwalthert commented on Mar 3, 2018

    @lorenzwalthert
    CollaboratorAuthor

    I agree with the last example. The first one seems debatable to me. But with current HEAD, we at least don't change

    call(a, 
      b = 3
    )

    Conclusion: Since the tidyverse style guide is not very clear on it and I just looked at it from a different angle than you, I think we can leave it for now.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions