SonarJS ERROR: Parse error to optional chaining

Project ReactNative
We have noticed that our online sonar ( * Community Edition

  • Version 7.9.1 (build 27448)) not updating the unit test coverage but locally configured sonar works well. then we check jenkin build and found about these errors. what can we about these?

    15:23:48 ERROR: Parse error at line 66 column 51:
    15:23:48
    15:23:48 56: } else {
    15:23:48 57: this.state.selectedItems.push(index);
    15:23:48 58: this.setState({
    15:23:48 59: selectedItems: […this.state.selectedItems]
    15:23:48 60: });
    15:23:48 61: }
    15:23:48 62: this.props.onChangeSelection(index);
    15:23:48 63: };
    15:23:48 64:
    15:23:48 65: renderCheckboxButton = (index) => {
    15:23:48 66: const isSelected = this.props.data[index]?.isSelected || this.state.selectedItems.includes(index);

Hello @Chathura_Lakmal,

Thank you for your message, and welcome to SonarSource community!

You are using an old version of SonarQube whose JavaScript analyzer doesn’t support optional chaining, hence the parsing error you are encountering. Therefore, I invite you to use the latest SonarQube 8.9, which happens to include the support of JavaScript optional chaining.

Hope this helps,
Yassin

1 Like

Thank you very much. i have already informed our DevOps to update our sonar.

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