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

Merge nested if conditions #349

Open
chrisfalaska opened this issue Oct 30, 2024 · 0 comments
Open

Merge nested if conditions #349

chrisfalaska opened this issue Oct 30, 2024 · 0 comments

Comments

@chrisfalaska
Copy link
Contributor

chrisfalaska commented Oct 30, 2024

Merge nested if conditions (merge-nested-ifs)

i18n.js

if (typeof window !== "undefined") {
  if (window.MutationObserver) {
    const observer = new MutationObserver(handleChange);
    observer.observe(document.documentElement, { attributes: true,
      attributeFilter: ['lang'] });
  }
}
if (typeof window !== "undefined" && window.MutationObserver) {
      const observer = new MutationObserver(handleChange);
      observer.observe(document.documentElement, { attributes: true,
        attributeFilter: ['lang'] });
}


ExplanationReading deeply nested conditional code is confusing, since you have to keep track of which
conditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two if conditions can be combined using
and is an easy win.

Originally posted by @sourcery-ai[bot] in AlaskaAirlines/auro-formkit#16 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants