Autocorrection of line length in the library

I am working on a huge project, and we decided to make the code more than 80 characters per line. This is a ruby ​​project with wrappers for C. For Ruby, I decided to use Rubocop with the command:

rubocop --only LineLength 

I got 1,714 errors, the length of which was more than 80 characters. In addition, many other errors were discovered in Rubocop that I now want to ignore.

I’m looking for the easiest way to automatically fix all string length errors to satisfy the 80 character limit in both C and Ruby.

+6
source share
1 answer

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.
+1
source

All Articles