Optional chaining in TypeScript not supported by SonarJS

Hello,

Our developers are doing some TypeScript development, and are using the optional chaining ? feature. SonarJS is flagging the uses of this feature as a bug, Expected an assignment or function call and instead saw an expression. via the typescript:S905 rule:

This has been reported numerous times:

And the commonly linked GitHub issue is closed: S905: FP with optional chaining · Issue #1930 · SonarSource/SonarJS · GitHub

We are using the latest available version of SonarJS, but are still experiencing this issue. Is this issue still being worked on? If so, what is the status, and is there an ETA?

Currently the workaround is to manually resolve all instances of this bug in SonarQube, which is tedious to say the least. Another option is to entirely disable the typescript:S905 rule, which I don’t like.

I apologize for opening yet another thread on this topic, but it’s unclear to me what the status of this issue is based on the other topics.

Our toolchain:

  • SonarQube 7.9.4 Enterprise
  • SonarScanner MSBuild 4.7.1.2311
  • SonarJS 6.2.2, which is the latest available in the Marketplace
  • TypeScript 3.7

Thanks,

Dennis

As a followup, I’ve done some testing and this is definitely an issue specific to using the optional chaining ? feature.

For example, in each of the two screenshots below you can see two lines of code, one using optional chaining ?, the other without it, but they are otherwise identical. The code with the chaining is flagged with the typescript:S905 rule.

Example 1:

Example 2:

Hi @zapp-dennis,

We will support optional chaining with SonarJS in SonarQube 8.5 based on our development team here, which will be released very soon. Keep on eye on the What’s new page and look for the latest download here. I also highly suggest you sign up for our announcement email on this page as well: Sonar Community - Home of Clean Code

Please also note this:

Since SonarTS v2.0, TypeScript analysis is performed by SonarJS analyzer v6.0 or later. No TypeScript analysis is performed by SonarTS.)

Joe

Hi @Joe,

Thank you for the response!

Do you happen to know when the next SonarQube LTS will be released, which I’m assuming would include support for this feature? We’d like to avoid running the interim releases from a supportability standpoint.

Thanks,

Dennis

Yes, SonarQube 8.x LTS will most likely be released in early 2021, which should also support TypeScript 4, so yes, we will support optional chaining definitely in SonarQube 8.x LTS.

Here’s our Roadmap page to give you an outlook on the horizon: https://www.sonarqube.org/roadmap/

1 Like

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