Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Feature: Find or create a lint rule around not making values before they're needed #1188

Open
3 tasks done
JoshuaKGoldberg opened this issue Jan 4, 2024 · 0 comments
Labels
status: accepting prs Please, send a pull request to resolve this! type: feature New enhancement or request

Comments

@JoshuaKGoldberg
Copy link
Owner

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Overview

I oftentimes find myself leaving reviews on code that creates values before checking whether they're needed. For example, in this rough pseudocode, banana doesn't need to be created if !!apple:

const apple = expensiveCreate("apple");
const banana = expensiveCreate("banana");

return !!apple && !!banana;

I would like to find (or create if it doesn't yet exist) an ESLint rule to enforce not making values until they're needed:

const apple = expensiveCreate("apple");

if (!!apple) {
  return true;
}

const banana = expensiveCreate("banana");

if (!!banana) {
  return true;
}

...this isn't a great example for readability, and I'm sure there's nuance around here that I'm not thinking of. Even if this rule does exist it might be too opinionated. Let's try it out!

Additional Info

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! type: feature New enhancement or request
Projects
None yet
Development

No branches or pull requests

1 participant