-
Notifications
You must be signed in to change notification settings - Fork 26.6k
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
[ESLint] Why are padded blocks not permitted? #483
Comments
Yeah, the eslint config is out of sync with our actual styleguide in a number of places. I am working on a test suite to bring them together here: |
However in this case I think we should amend the styleguide to say that a comment on the first line of a block does not need a preceding line. |
I don't see anywhere in the style guide that mentions padded blocks, so maybe we should make a change in the styleguide to address it as well. |
This addresses airbnb#483
In airbnb#483, justjake said that we should update the style guide to allow single line comments in the first line of a block.
#547, which was recently merged, addresses this issue by adding a section to the style guide that prohibits padded blocks. |
This addresses airbnb#483
In airbnb#483, justjake said that we should update the style guide to allow single line comments in the first line of a block.
This addresses airbnb#483
In airbnb#483, justjake said that we should update the style guide to allow single line comments in the first line of a block.
I know this question is closed, but I am wondering if there is a justification for why padded blocks aren't allowed? I noticed both AirBnB and Google's styles disallow it, so we are following the same convention, but we are wondering why. |
Whitespace is beneficial when it adds readability, but not when it creates visual noise. With syntax highlighting, lines padding blocks add zero benefit, but increase the vertical length of code, and reduce the amount you can see at once. |
@ljharb - good enough for me, thanks! Would be awesome to see that in the style guide (I often wish style guides had more justifications) but that is very helpful. |
This addresses airbnb#483
In airbnb#483, justjake said that we should update the style guide to allow single line comments in the first line of a block.
@ljharb , that's not true for all cases. In several cases, adding a blank line add a HUGE readability improvement to the code, and it outweighs the fact that the code gets longer by 1 single line. For example in a test file:
vs
So what's the real reason for not allowing the first line of a block to be empty? Myself, I never pad a block at the end, but doing it in the beginning give way more readable code in such cases. If you want to reduce visual noise, then there also should be no spaces inside object declarations as well imho... So I believe that those both rules are conflicting with the reason behind them. Imho, a styleguide should have some general principles, and use them throughout, unless there is a very good reason not to adhere it. |
Personally i find the latter case much more readable. |
I don't quite understand why the ESLint config file prohibits padded blocks. What would happen if you needed to make a comment after a block opens:
In addition, I don't see anywhere in the style guide where padded blocks are prohibited.
The text was updated successfully, but these errors were encountered: