question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ESLint] Why are padded blocks not permitted?

See original GitHub issue

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:

// ESLint Error: "Block must not be padded by blank lines. (padded-blocks)"
$document.ready(() => {

  // Initialize/Render React
  React.render(React.createElement(Index), $react.get(0));
  ...
}

// Violates 17.2 of the style guide: "Put an empty line before the [single-line] comment."
$document.ready(() => {
  // Initialize/Render React
  React.render(React.createElement(Index), $react.get(0));
  ...
}

In addition, I don’t see anywhere in the style guide where padded blocks are prohibited.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

24reactions
ljharbcommented, Mar 10, 2017

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.

12reactions
dietergeertscommented, Jun 9, 2018

@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:

import { withJsonDefault } from './with-json-default';

describe('withJsonDefault', () => {

  it(`must use the serializer of the given schema directly,
    as defaults are only meant to be used on deserialization,
    where we have no control over the actual json coming through.`, () => {
    const primitive = _clone(PRIMITIVE);
    sinon.spy(primitive, 'serialize');
    const schema = withJsonDefault('B', primitive);

vs

import { withJsonDefault } from './with-json-default';

describe('withJsonDefault', () => {
  it(`must use the serializer of the given schema directly,
    as defaults are only meant to be used on deserialization,
    where we have no control over the actual json coming through.`, () => {
    const primitive = _clone(PRIMITIVE);
    sinon.spy(primitive, 'serialize');
    const schema = withJsonDefault('B', primitive);

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

padded-blocks - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Padding-block rule issue - javascript - Stack Overflow
I've started learning react from tutorials. I got error: /NotesInReact/node_modules/eslint-config-airbnb-base/rules/style.js: ...
Read more >
https://unpkg.com/react-beautiful-dnd@2.2.4/.eslintrc
... blocks "padded-blocks": ["error", "never"], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unused-prop-types.md // Adding ...
Read more >
Rules - JavaScript Standard Style
Rules · Use 2 spaces for indentation. eslint: indent · Use single quotes for strings except to avoid escaping. eslint: quotes · No...
Read more >
tslint-eslint-rules | Yarn - Package Manager
Improve your TSLint with the missing ESLint Rules ... You want to code in TypeScript but miss all the rules available in ESLint?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found