I have read issue #1658, where the lead developers stated that it is the intention behaviour to record a Style/TrailingWhitespace offense when there is white space on an empty line. That is fine, but would you accepts a PR that adds a configuration option to change how white space is enforced on empty lines?
I propose the following cop and configuration options:
Style/EmptyLineIndentation:
EnforcedStyle: none
SupportedStyles:
- none
- match_outer
- match_inner
where match_outer and match_inner enforce that the indentation of an empty line matches the indentation of the surrounding lines, and the outer/inner deals with the ambiguous cose where the empty line is between two lines of differing indentations.
The PR adding this configuration option would also edit the Style/TrailingWhitespace cop to not report an offense for empty lines, instead letting this cop handle that case. The default behaviour of reporting an offense for empty lines with white space would not be change, but would change the offense that is reported from Style/TrailingWhitespace to Style/EmptyLineIndentation.
One of the benefits of the match_outer and match_inner options is that the expected content of empty lines will still be enforced, which means that there will be no git diffs where the only change is the white space on an empty line - a problem that was pointed out in the comments on #1658.
Is there anyone else who supports this idea? (Personally, I don't favor it.)
Not me. Most editors would flag indented whitespace as trailing whitespace. Seems pointless to me.
Can we close this issue?
I do support this idea. IDEs add by default indentation in new blank lines and I really like that option. It makes it consistent with the idea of pressing the 'End' key placing the cursor at a position where you can just type new code.
I agree with @JorgeRdg and @mikeyhew . I don't think it matters too much what the convention is, as long as everyone in a project is following the same convention, which is what RuboCop is here for.
We use ESLint for our React Native application and they have an option to _not allow_ trailing whitespace but to _allow_ empty lines to be indented. It's not on by default but it can be configured.
It's extremely handy since popular editors like Sublime Text 3 will automatically indent new lines and retain those indents on blank lines. Having this option to skip blank lines saves a lot of unnecessary deleting whilst still keeping the codebase clean.
To be clear, if the lines above and below the line in question have an indent of 2 spaces, it will ONLY allow a blank line with an indentation of 2 spaces. This ensures the enforcement is consistent while saving the tediousness of deleting the indented spaces in those blank lines.
In case you can't tell, I'm _highly_ in favour of allowing this as a configurable option that is not enabled by default.
Since a few folks now feel like this is valuable, I suppose it's time for someone to open a PR.
I still feel like your editor could be configured to trim this whitespace on save and get in line with Rubocop's default config, but if folks want it and it isn't a big deal to support another non-default config, ¯\_(ツ)_/¯.
For the record, my opinion has changed since posting this issue, and I now have my editors configured to remove any trailing whitespace on save. The real advantage of not having trailing whitespace is that it keeps diffs clean.
For anyone still running into this issue, I encourage you to do the same, it'll probably be better for you in the long run. Of course, if it really bothers you that Rubocop doesn't have an option to allow whitespace on empty lines, it sounds like @mikegee is open to accepting a PR, so you're welcome to add that config yourself.