Please do not change the line length automatically.
Linelength is a metric, not a style. Styles can often be exchanged, such as double or single quotes, using hash hat against the new hash syntax introduced in ruby ββ2, etc. The choice of style usually depends on the taste and has little (if any) impact on the program itself. That's why there are automatic adjustments for styles: changing them does not change the semantics.
Metrics include line length, classlength and size ABC and others. Validating metrics using static code analysis is something completely different than styling. For example, if you set the maximum length of the line, it is not a matter of taste, you prefer to use it to provide a certain programming style. The programmer should avoid long variable names and deep nesting to keep the line length under the limit.
Metrics can also indicate problems in the code. For example, an ABC size too high indicates that the method can do too much.
In addition, it would be very difficult, if not impossible, to automatically reduce all lines of code, since ruby ββis a very complex language.
Instead of automatically decreasing the line length, there are several alternatives:
- see if you can reduce the number of violations by enabling the AllowHeredoc and AllowURI options. Read about them here https://rubocop.readthedocs.io/en/latest/cops_metrics/#metricslinelength .
- run
rubocop --only LineLength --auto-gen-config and use the rubocops configuration to stop checking the line length. - ask yourself: what value can I get by reducing the length of the line?
- don't think of lines that are too long as a violation of style, but rather as a possible indicator of the underlying problem. Try to find this problem and solve it.
source share