typescript:S7755 should not apply to non-arrays

  • Language: Typescript
  • Rule: typescript:S7755 - Complex index access patterns should be replaced with “.at()” method
  • SonarQube for IDE: 8.29.0.14599 on Visual Studio 2022 (not connected)

This rule should not be triggered for collection types (e.g. NodeList returned by querySelectorAll) which do not have an .at(n) method.

function getLastNode() {
    const items = document.querySelectorAll(".someClass"); // not an array
    return items[items.length - 1];
}

Hello @m-gallesio,

thanks for the feedback. I created a ticket to fix this.

Cheers

1 Like