In javascript, when checking an array like this:
if (array && array.length > 0)
an optional chain expression is the better choice:
if (array?.length > 0)
However, at least sonarlint does not recognize this case.
It would be helpful to know:
- If there’s a specific rule you expect to trigger here (or if this is a new rule idea)
- What IDE you’re using SonarLint in, and what version of SonarLint
Hey Colin, we’re using Developer Edition v10.5.1, the rule I’m talking about is javascript:S6582.
I’m proposing to extend it detecting the case mentioned.
Hey @Udo_Pape-Kampmeier, thank you for bringing this up. I’ve created a ticket to track this [JS-184] - Jira