- Operating system: Windows 10
- IDE name and flavor/env: Visual Studio Code / TypeScript
- SonarLint plugin version: 1.22.0 / jdk1.8.0_251
As the title says, an optional chaining in forEach() gets me a warning message: “Expected an assignment or function call and instead saw an expression. sonarlint(typescript:S905)”. I use ? as a precaution in case the variable is null or undefined so that the code does throw an exception. I understand there are other ways to check the truthiness of an array, but I cannot see anything wrong with this approach and it definitely has side effects, so I consider the warning to be unwarranted.
By project requirements, v1.22.0 and jdk1.8.0_251 are to be used, but I tried updating to the latest version (3.4.0) and java 11 and the warning still persists.
Thank you for your feedback, and welcome to Sonar community.
Unfortunately, I am not able to reproduce the false positive you reported. I used the very same code snippet you shared with the latest SonarLint version (3.4.1) on VSCode.
Perhaps, you need to restart your IDE so that the updated SonarLint version is indeed analyzing your code, not the old one.
Hope this helps,
Thank you very much for your response! Following your advice, I tried to reproduce my warning in another machine using the latest version, as you did, and was not able to do so. That made me realise that the issue was not the SonarLint version, but the connection with SonarQube (properties set on “sonarlint.connectedMode.connections.sonarqube”). Since this is out of my control, I will simply have to ignore the warning (just a minor inconvenience, after all), but at least I know it is not an extention bug.
Thank you again. Cheers!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.