question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `no-useless-recursion`

See original GitHub issue

Disallow simple recursive function.

Fail

function foo(bar) {
  if (bar.baz) {
    return foo(bar.baz);
  }

  return bar;
}

Pass

function foo(bar) {
  while (bar.baz) {
    bar = bar.baz:
  }

  return bar;
}
function foo(bar) {
  for (; bar.baz; bar = bar.baz) {}

  return bar;
}
function foo(bar) {
  if (Array.isArray(bar)) {
    return bar.map(baz => foo(bar));
  }

  return bar;
}

I’m not sure how to define “simple”.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
silverwindcommented, Jan 28, 2021

Recursion is necessary for some algorithms, one can not simply forbid it generally. Maybe call it no-useless-recursion but detecting which cases are useless will probably be hard.

1reaction
sindresorhuscommented, Feb 9, 2021

I agree, it should be named no-useless-recursion and should only target some simple cases that can use loops instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rule proposal: No implicit recursion · Issue #2664 - GitHub
This rule flags all recursive calls as invalid, except of those calls that are marked with an eslint-disable-line . This rule should help...
Read more >
Common Patterns in Recursive Procedures - People @EECS
The only general principle we can offer is that you have to think about what base cases are appropriate, not just routinely copy...
Read more >
Proposed rule: Order Competition Rule - SEC.gov
proposed rule would prohibit a restricted competition trading center from internally executing certain orders of individual investors at a ...
Read more >
Binary Recursive Estimation on Noisy Hardware - Elsa Dupraz
Lk. This is why the theoretical analysis we propose studies the convergence of the expected gap E[|˜Lk − Lk|] between the noisy and...
Read more >
Adaptive stepsizes for recursive estimation with applications in ...
techniques that uses this idea is the delta-bar-delta learning rule, proposed in Jacobs (1988), which decreases the stepsize exponentially ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found