Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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. 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;
}
like image 407
AndreyProgr Avatar asked May 09 '26 19:05

AndreyProgr


1 Answers

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?

If your goal is preventing complex function rather use max-lines-per-function and complexity.

like image 188
doberkofler Avatar answered May 11 '26 11:05

doberkofler