2

While running sonar-scanner on a node project, I get a Failed to parse file error, which looks like this

ERROR: Failed to parse file [file:///home/node-app/somedir/index.js] at line 1: Unexpected token './AddCat' (with espree parser in module mode)

And my index.js file looks like this:

export default from './AddCat';

And my AddCat.js file looks like this:

import React from 'react';
import { Image } from '@cat-ui/core';

import { translate } from 'client/helpers/language';
import Page from 'client/components/Page';

import { StyledText, StyledButton, StyledImagePlaceholder } from './AddCat.styled';
import AdditionalApplicant from './images/additional_applicant.png';

const AddCat = () => (
  <Page>
    <StyledImagePlaceholder>
      <Image width="67px" height="60px" src={AdditionalApplicant} />
    </StyledImagePlaceholder>
    <StyledText color="grey">{translate('AddCatText')}</StyledText>
    <StyledButton
      tag="a"
      color="secondary"
      href="/morecats/morecats.html?route=V1&sharedCat=true"
      label={translate('AddCatButton')}
    />
  </Page>
);

export default AddCat;

The problem is only with index.js and not AddCat.js while running sonar-scanner. I think it's some kind of formatting issue and any help in figuring out the problem is highly appreciated.

Regards, Ashutosh

ashutosh singh
  • 76
  • 3
  • 11

1 Answers1

3

Syntax export default from is stage 1 proposal. SonarQube supports out of the box only ES 2018 syntax. Effectively this means that no issues will be detected in this file.

Tibor Blenessy
  • 4,254
  • 29
  • 35
  • thanks alot Tibor. I'll ignore these errors for the time being then. – ashutosh singh Oct 30 '18 at 14:16
  • @Tibor Blenessy, Looks like SonarJS now uses babel-parser instead of espree (https://github.com/SonarSource/SonarJS/pull/1143), which should parse js up to state 3 features if I understood correctly. But it is still an issue in sonar-scanner 3.3.0. Any plans to update it? Thanks. – givehug May 21 '19 at 14:59
  • 2
    @givehug sonar-scanner doesn't include SonarJS, SonarJS is downloaded from your SonarQube instance. You should update SonarJS on your SonarQube. Note however that only some rules have been rewritten to be able to benefit from babel parser. This is ongoing work to port all the rules to the new engine – Tibor Blenessy May 22 '19 at 13:05