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

Line breaks with $ operators #163

Open
gadenbuie opened this issue Jan 15, 2025 · 3 comments
Open

Line breaks with $ operators #163

gadenbuie opened this issue Jan 15, 2025 · 3 comments

Comments

@gadenbuie
Copy link
Contributor

gadenbuie commented Jan 15, 2025

Niche, but with R6 classes method chaining is common. We have the following line in bslib

tq$find(".accordion-button")$removeClass("collapsed")$removeAttrs("aria-expanded")$addAttrs("aria-expanded" = "true")

that air (0.1.2) reformats as

tq$find(".accordion-button")$removeClass("collapsed")$removeAttrs(
  "aria-expanded"
)$addAttrs("aria-expanded" = "true")

I personally would have rewritten this as

tq$
  find(".accordion-button")$
  removeClass("collapsed")$
  removeAttrs("aria-expanded")$
  addAttrs("aria-expanded" = "true")

Maybe the line break at the first $ could be magical, since most people would probably want to opt into this style.

@lionel-
Copy link
Collaborator

lionel- commented Jan 17, 2025

Agreed, we should support anything that can be chained in the same way for consistency and usability.

@DavisVaughan
Copy link
Collaborator

I don't think this will work exactly the same as binary expressions though, because you probably want a_data_frame$a_really_long_name to always be "sticky" with no newlines on the RHS even if the expression exceeds the line length. So we will have to find something that balances that with the ability to chain.

@lionel-
Copy link
Collaborator

lionel- commented Jan 21, 2025

you probably want a_data_frame$a_really_long_name to always be "sticky" with no newlines on the RHS

This idea is consistent with #183 (comment)

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

No branches or pull requests

3 participants