Skip to content
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

Support for curly-curly syntactic sugar #528

Merged
merged 7 commits into from Jun 30, 2019

Conversation

lorenzwalthert
Copy link
Collaborator

@lorenzwalthert lorenzwalthert commented Jun 29, 2019

Closes #526. Affecting both line break rules and spacing rules. Preserve testing of previous code (mostly focussed on indention) related to using two curly braces in a sequence was preserved, as we need this to work independently of the rule for {{. This is implemented using a version of the tidyverse style guide that turns off the rule for curly-curly.

@lorenzwalthert
Copy link
Collaborator Author

@lorenzwalthert lorenzwalthert commented Jun 29, 2019

The problem with this PR is that it does not allow {{ to be on a separate line in a function call:

# this is bad when the function call name + indention is so long that we simply want the 
# first argument on a new line.
styler::style_text(
  "call(
  {{x}}
)"
)
#> call({{ x }})

# or less common
styler::style_text(
  "call(1, 2, 3, 4,
  4, 5,
  {{x}}, 
  5
)"
)
#> call(
#>   1, 2, 3, 4,
#>   4, 5, {{ x }},
#>   5
#> )

Created on 2019-06-29 by the reprex package (v0.2.1)

E.g. call({{\nx }}\n) should be left as is. Because we can't look into the future 2 steps (token_after), we need to compute the token ad-hoc, check if it is {, and if yes, we know it is a curly-curly expression. Leaves the minor edge case of an expression starting with `{{` but not being a curly-curly expression (e.g. `call(\n{{1} + 2})`) treated inconsistently beause we assume here it is a curly curly expression (as we only check for `{{` in the beginning. Result, first `{` is moved to the new line.
… not a child of pd and rules setting line breaks before that token is not within the scope of this function (plus you get an error with .rm_break_idx + 1L.
@lorenzwalthert
Copy link
Collaborator Author

@lorenzwalthert lorenzwalthert commented Jun 30, 2019

Problem from above resolved with ba2d45d:

styler::style_text(
  "call(
  {{x}}
)"
)
#> call(
#>   {{ x }}
#> )
# or less common
styler::style_text(
  "call(1, 2, 3, 4,
  4, 5,
  {{x}}, 
  5
)"
)
#> call(
#>   1, 2, 3, 4,
#>   4, 5,
#>   {{ x }},
#>   5
#> )

Created on 2019-06-30 by the reprex package (v0.2.1)

@lorenzwalthert lorenzwalthert merged commit c3bb1ce into r-lib:master Jun 30, 2019
2 checks passed
@lorenzwalthert lorenzwalthert deleted the feature-curly-curly branch Jun 30, 2019
@lorenzwalthert lorenzwalthert restored the feature-curly-curly branch Aug 5, 2019
@lorenzwalthert lorenzwalthert deleted the feature-curly-curly branch Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant