Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 587
helion3 Avatar asked Mar 28 '16 18:03

helion3


1 Answers

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: '*' },
]
like image 73
Billy Reilly Avatar answered Sep 24 '22 10:09

Billy Reilly