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

Do not break method chains until first method #3290

Closed
orlp opened this issue Jan 18, 2019 · 6 comments
Closed

Do not break method chains until first method #3290

orlp opened this issue Jan 18, 2019 · 6 comments

Comments

@orlp
Copy link

orlp commented Jan 18, 2019

Perhaps I'm alone in this, but I'm often peeved by the way this gets formatted:

let left_hand_sides = self
    .rules
    .iter()
    .map(|rule| rule[0])
    .collect();

Would it be possible either by default, or with an configurable option to not start a method chain until the first actual method, assuming it fits on one line? That is the above would be:

let left_hand_sides = self.rules
    .iter()
    .map(|rule| rule[0])
    .collect();

Or with multiple dots before the first method:

let left_hand_sides = self.grammar.rules
    .iter()
    .map(|rule| rule[0])
    .collect();

Of course if the line would become too long the break should still happen:

let left_hand_sides = self
    .grammars
    .grammar_for_rust_language
    .rules_found_in_this_grammar
    .iter()
    .map(|rule| rule[0])
    .collect();
@nrc
Copy link
Member

nrc commented Jan 18, 2019

Given we're at 1.0 and therefore this would be a backwards incompatible change, we're unlikely to implement, sorry (it was also decided upon during the formatting RFC process and this formatting was not very controversial).

@nrc nrc closed this as completed Jan 18, 2019
@orlp
Copy link
Author

orlp commented Jan 18, 2019

@nrc I understand that it can't be default behavior, but making it an configurable option would be possible, no?

@nrc
Copy link
Member

nrc commented Jan 18, 2019

I think the extra code complexity to do this for the fairly niche payoff would mean that it is not worth supporting this as an option, sorry

@orlp
Copy link
Author

orlp commented Jan 18, 2019

@nrc Alright. I did notice an inconsistency though where if the first identifier is shorter than the indent, the first method is not properly put on it's own line. For example see how this toy code is formatted by rustfmt, making .chars() misaligned:

fn strip_whitespace(s: String) -> String {
    s.chars()
        .filter(|c| *c != ' ')
        .filter(|c| *c != '\n')
        .collect()
}

vs

fn strip_whitespace(string: String) -> String {
    string
        .chars()
        .filter(|c| *c != ' ')
        .filter(|c| *c != '\n')
        .collect()
}

Should I made a new issue for that? Or is that intended?

@nrc
Copy link
Member

nrc commented Jan 22, 2019

Should I made a new issue for that? Or is that intended?

It is intended, in order to avoid an ugly 'orphan line, e.g.,

s
    .chars()  // :-(

@orlp
Copy link
Author

orlp commented Jan 23, 2019

Alright then.

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