最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Enforcing newlines separating code blocks in eslint - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question asked Mar 28, 2016 at 18:09 helion3helion3 37.4k16 gold badges64 silver badges110 bronze badges 1
  • 1 For the record, you can use newline-after-var to enforce a break after the var declaration. I'm still anxious to find a rule to enforce separation of the two if blocks in the case where the var isn't there, though. – rockerest Commented Mar 31, 2016 at 4:09
Add a comment  | 

1 Answer 1

Reset to default 21

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: '*' },
]
发布评论

评论列表(0)

  1. 暂无评论