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

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

This comment has been minimized.

Copy link
Collaborator Author

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)

lorenzwalthert added some commits Jun 30, 2019

allow curly-curly arguments to be on its own line
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.
ignore if `{` is token_after the last token in pd, because then it is…
… 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 lorenzwalthert force-pushed the lorenzwalthert:feature-curly-curly branch from 5a1c0d4 to ba2d45d Jun 30, 2019

@lorenzwalthert

This comment has been minimized.

Copy link
Collaborator Author

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

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@lorenzwalthert lorenzwalthert deleted the lorenzwalthert:feature-curly-curly branch Jun 30, 2019

@lorenzwalthert lorenzwalthert restored the lorenzwalthert:feature-curly-curly branch Aug 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.