helion3
helion3

Reputation: 37481

Enforcing newlines separating code blocks in eslint

I've been scouring the Eslint rule docs and cannot figure out how to enforce newlines between blocks.

For example, in jscs I can reject these for having no separating new line:

if (!rows.length) {
  // code
}
var pagination;
if (something) {
  // code
}

"space-before-blocks" sounded like it's what I wanted but it applies only to spaces, not newlines.

Upvotes: 12

Views: 3987

Answers (1)

Billy Reilly
Billy Reilly

Reputation: 1542

Response is a bit late but you can now use the padding-line-between-statements rule for this: http://eslint.org/docs/rules/padding-line-between-statements

I think the config you'd want would be something like

"padding-line-between-statements": [
  "warn",
  { blankLine: 'always', prev: '*', next: 'block' },
  { blankLine: 'always', prev: 'block', next: '*' },
  { blankLine: 'always', prev: '*', next: 'block-like' },
  { blankLine: 'always', prev: 'block-like', next: '*' },
]

Upvotes: 21

Related Questions