FP suggesting nullish coalescing operator

Please provide

  • Operating system: Windows 11
  • SonarQube for VS Code plugin version: 4.24.0
  • Programming language you’re coding in: Typescript
  • Is connected mode used: No
    • SonarQube Cloud, SonarQube Server, or SonarQube Community Build? (if one of the latter two, which version?):

And a thorough description of the problem / question:
The following code:

function nodeMatches(spec: any, event: any) {
	return 	spec?.includes(event.node.id) ||
					spec?.includes(event.node.data?.id) ||
					spec?.includes(event.node.title)
}

returns
Prefer using nullish coalescing operator (??) instead of a logical or (||), as it is a safer operator.sonarqube(typescript:S6606)

which is invalid as this will not return true/false based on a value in spec such as ‘[output]’ matching for example event.node.data?.id.

Hello @Alain_Picard,

Based on your and other community posts, we are making this rules less strict as in the original @typescript-eslint implementation. Here is a PR with details: JS-373 Make S6606 less strict by zglicz · Pull Request #5463 · SonarSource/SonarJS · GitHub

It will be fixed in the upcoming release.

Cheers,
Michal

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.