hash icon indicating copy to clipboard operation
hash copied to clipboard

Prefer nullish coalescing

Open nathggns opened this issue 3 years ago • 1 comments

🌟 What is the purpose of this PR?

This introduces an eslint rule to prefer ?? over || when not using booleans.

🔗 Related links

🚫 Blocked by

N/A

🔍 What does this change?

  • Introduce eslint rule to prefer?? over || when not using booleans – this forces us to be intentional about handling "falsey" values and can prevent some subtle bugs
  • Fix errors where simple to do so without changing behaviour
  • Add temporary lint rule disable comments for most existing errors to reduce change of this PR breaking stuff – can slowly improve existing problems as we touch that come

📜 Does this require a change to the docs?

N/A

⚠️ Known issues

N/A

🐾 Next steps

  • Remove all existing uses of || when ?? is more appropriate - this will be done slowly instead of one big bang – so it can be done when the intention is known

🛡 What tests cover this?

Playwright tests

nathggns avatar Aug 30 '22 02:08 nathggns

@CiaranMn to clarify, this is not the same as #916. We delayed this because that changed code, and we weren't certain it didn't introduce bugs, whereas in 99% of cases here I've added ignore comments (which is the strategy I was arguing for in #916).

I've exempted the backend packages from this now, so will just review any remaining comments & hopefully we can get this merge

nathggns avatar Sep 12 '22 09:09 nathggns

@nathggns WDYT of marking this PR as draft till dev-graph is merged into main? Not sure we should finish this PR till then to avoid extra work.

kachkaev avatar Sep 27 '22 10:09 kachkaev

@kachkaev dev graph packages are exempted, as requested by @CiaranMn https://github.com/hashintel/hash/pull/1005#pullrequestreview-1089938443

nathggns avatar Sep 27 '22 10:09 nathggns