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

Try to break long lines at assignment first before breaking within RHS #183

Open
gadenbuie opened this issue Jan 17, 2025 · 2 comments
Open

Comments

@gadenbuie
Copy link
Contributor

In chromote, we had this line

private$event_callback_counts[[domain]] <- private$event_callback_counts[[domain]] - 1

which, when wrapped to 80 characters with air 1.0.0 becomes

private$event_callback_counts[[domain]] <- private$event_callback_counts[[
        domain
      ]] -
        1

but I'd much rather this break at the <- (without me having to introduce that break manually)

private$event_callback_counts[[domain]] <- 
  private$event_callback_counts[[domain]] - 1
@DavisVaughan
Copy link
Collaborator

That's tough because you definitely want this to break within the RHS first

foo <- this %>% that() %>% this_other_long_thing() %>% and_this_one_too_as_well()

I agree the current situation isn't great but I'm not sure what the best situation is yet without diving in a bit more.

The line break right after the <- is currently an opt-in feature (through a persistent line break). It won't ever generate one of those line breaks automatically. I don't really love seeing those kinds of line breaks just appear as soon as you hit the line limit, because I greatly prefer the lhs and rhs to at least start on the same line.

@gadenbuie
Copy link
Contributor Author

gadenbuie commented Jan 17, 2025

One way of expressing my preference is that I prefer line-wrapping strategies that minimize line breaks, with exceptions.

In my original example, I'd much prefer breaking around an entire expression over introducing several breaks. Once internal breaks are required, then I like consistent breaks.

Personally, I'd be okay with your over-long pipe chain example becoming this

foo <- 
  this %>% that() %>% this_other_long_thing() %>% and_this_one_too_as_well()

if you're only 6 characters over the line width constraint. Very often the second line will still not be under, in which case you'd move to an "internal break" on the RHS

foo <- this_is_too_long %>%
  that() %>%
  this_other_long_thing() %>%
  and_this_one_too_as_well()

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

2 participants