module RuboCop::Cop::CheckLineBreakable

This mixin detects collections that are safe to “break” by inserting new lines. This is useful for breaking up long lines.

Let’s look at hashes as an example:

We know hash keys are safe to break across lines. We can add linebreaks into hashes on lines longer than the specified maximum. Then in further passes cops can clean up the multi-line hash. For example, say the maximum line length is as indicated below:

|
v

{foo: “0000000000”, bar: “0000000000”, baz: “0000000000”}

In a LineLength autocorrection pass, a line is added before the first key that exceeds the column limit:

{foo: “0000000000”, bar: “0000000000”, baz: “0000000000”}

In a MultilineHashKeyLineBreaks pass, lines are inserted before all keys:

{foo: “0000000000”, bar: “0000000000”, baz: “0000000000”}

Then in future passes FirstHashElementLineBreak, MultilineHashBraceLayout, and TrailingCommaInHashLiteral will manipulate as well until we get:

{

foo: "0000000000",
bar: "0000000000",
baz: "0000000000",

}

(Note: Passes may not happen exactly in this sequence.)