AlaskaAirlines / auro-input

Custom HTML element for inputting string data in forms
https://auro.alaskaair.com/components/auro/input
Apache License 2.0
2 stars 4 forks source link

Merge nested if conditions #349

Open chrisfalaska opened 3 weeks ago

chrisfalaska commented 3 weeks ago

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 https://github.com/AlaskaAirlines/auro-form/pull/16#discussion_r1821359245_