[英]ESLint: disallow empty lines inside function body
I strongly believe that empty lines inside the body of a function are code smells indicating that we need to perform refactoring to break the function apart.我坚信 function 主体内的空行是代码异味,表明我们需要执行重构以将 function 分开。
But among the existing rules in ESLint ( no-multiple-empty-lines
/ lines-between-class-members
, etc.), including those presented in popular plugins, I could not find a rule that will restrict me from the use of empty lines inside the body of a function .但是在 ESLint 中的现有规则(
no-multiple-empty-lines
/ lines-between-class-members
等)中,包括流行插件中提供的规则,我找不到限制我使用 empty的规则function 体内的线条。 Has anyone encountered this problem before?有没有人遇到过这个问题?
This is bad:这是不好的:
function add(a, b) {
const result = a + b;
return result;
}
const multiply = (a, b) => {
const result = a * b;
return result;
}
This is good:这很好:
function add(a, b) {
const result = a + b;
return result;
}
const multiply = (a, b) => {
const result = a * b;
return result;
}
I personally strongly believe that empty lines are of paramount importance to make code more readable.我个人坚信空行对于使代码更具可读性至关重要。 Anyway: did you check out the
padding-line-between-statements
rule?无论如何:您是否检查过
padding-line-between-statements
规则?
If your goal is preventing complex function rather use max-lines-per-function
and complexity
.如果您的目标是防止
complexity
的 function ,请使用max-lines-per-function
和 complex 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.