简体   繁体   English

Eslint 规则“padding-line-between-statements”没有按预期工作

[英]Eslint rule “padding-line-between-statements” not working as expected

I am trying to configure eslint to force newlines after return statements and block openings using the padding-line-between-statements rule.我正在尝试将 eslint 配置为在 return 语句后强制换行,并使用 padding-line-between-statements 规则阻止开口。 Enforcing a newline before the return works well but I can't get it after by just swapping prev/next.在返回之前强制执行换行符效果很好,但我无法通过交换 prev/next 来获得它。

Here is what I tried in eslintrc.js这是我在 eslintrc.js 中尝试过的

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

What am I missing?我错过了什么? Shouldn't it work like this as described in documentation ?它不应该像 文档中描述的那样工作吗? Or is there a better rule for wrapping block content in new lines?或者是否有更好的规则将块内容包装在新行中?

The padding-line-between-statements rule works adding a padding line between two statements. padding-line-between-statements规则用于在两个语句之间添加填充线。 As there is no statement after the return it won't never work.由于退货后没有任何声明,因此它永远不会起作用。 The wildcard * means "any statements", but that doesn't mean anything .通配符*表示“任何陈述”,但这并不意味着任何东西 There is a list of valid statement types in the docs . 文档中有一个有效语句类型的列表。

Anyways, check out the Google JavaScript Style Guide :无论如何,请查看Google JavaScript 样式指南

[A single blank line appears] within method bodies, sparingly to create logical groupings of statements. [出现一个空行] 在方法主体中,谨慎地创建语句的逻辑分组。 Blank lines at the start or end of a function body are not allowed. function 正文的开头或结尾处不允许有空行。

Of course it's just a style guide, but I thought it's interesting to have in mind that Google considers that a bad practice style-wise.当然,这只是一个风格指南,但我认为有趣的是,Google 认为这是一种不好的做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM