SonarJS: not able to parse with optional-chaining/nullables

Hello,

currently I am using SonarQube with SonarJS version 5.0 (build 6962). My source files are es2017 files which are transpiled using babel. Thus, there are some features, which lead Sonar into not beeing able to parse some source files.

Especially with using babel plugins, for instance ‘plugin-proposal-optional-chaining’, this leads into parser errors:
ERROR: Parse error at line 74 column 37:

73:     const browserData = bowser.getParser(ctx.request.header['user-agent']).parse().parsedResult;
74:     const test = ctx.request.body?.test;
                                                       ^

Is there any way to install babel-plugins to the sonar analyzer or are there any other workarounds, that let me analyse my source files?

Greetings Sven,

We support new syntax as it reaches Stage 2 in the ECMAScript Proposal Process. Optional Chaining is in Stage 1.

Colin

Hi Colin,

Optional Chaining is in Stage 2 now: https://github.com/tc39/proposal-optional-chaining

Philipp

hello @pmb,

we are in the process of migrating SonarJS to a new parser, which will support babel and consequently it will allow to use different ecma script proposals. With the latest SonarJS plugin you can already run some of the rules using this new parser and we will migrate all the other rules during this year.

You can follow this ticket https://jira.sonarsource.com/browse/MMF-1521 to see which rules are going to be migrated.

Since optional chaining is now stage-4, do we support it now?

You can forget about stages, as we don’t rely on them as we rely on babel parser now. Currently we use babel-eslint 10.0.1 version, I tested it, it seems to parse optional chaining.

1 Like

Thank you Elena. I think the version that we are using need to be updated. I will check with the team and get it updated.

Hi Elena

Is this issue fixed in a version of SonarQube or JS plugin?
We are hitting this issue with SQ 7.9.1 and JS plugin 5.2.1.
Thanks
Jason

A new version of our Javascript analyzer. The latest version is v6.2 – (you should make sure you upgrade the TypeScript analyzer to the latest version as well if you upgrade).

Hi,
We use sonarcloud with https://bitbucket.org/sonarsource/sonarcloud-scan/ (i.e. it’s dockerized artifact). Is there a way to upgrade it, for that our parser does not stumble upon the optional chaining?
Thanks,
thomas

Hi,
We’re using sonarcloud for multiple projects and also facing the problem with the optional chaining. Do we have any update on this?
Thanks