Search code examples
javascriptmavensonarqubestatic-code-analysissonarjs

Sonar javascript static code analyze - javascript riport missing. Maven project


Help me, please. I don't know why missing only javascript static code analyze riports.

So, I have a maven project with multiple modules and the javascript codes in the frontend project.

  • SonarJS plugin installed
  • i'm running: mvn clean install sonar:sonar
  • i have configure sonar from pom.xml instead of sonar-project.properties
  • sonar version: 6.7 community edition

In the sonar overview it has java static code analyze riport both of modules, but nothin about javascript codes.

Here is my pom.xml settings in the parent project.

 <?xml version="1.0" encoding="UTF-8"?>
 <project ... >
...
<version>0.0.1-SNAPSHOT</version>
<modules>
    <module>backend</module>
    <module>frontend</module>
</modules>
<properties>
    ...
    <!-- sonar -->
    <sonar.version>3.4.0.905</sonar.version>
    <sonar.host.url>http://my.sonar.domain.url</sonar.host.url>
    <sonar.login>asdsd43f8g7fs498u9s8df7s97zf9er97zf7</sonar.login>
    <sonar.javascript.file.suffixes>.js,.jsx,.vue</sonar.javascript.file.suffixes>
    <sonar.sources>src/main/</sonar.sources>
    <sonar.test>src/test/</sonar.test>
    <sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
    <sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
    <sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
    <!-- For Java -->
    <sonar.junit.reportsPath>reports/java/surefire-reports</sonar.junit.reportsPath>

    <!-- For JavaScript -->
    <sonar.javascript.lcov.reportPath>reports/js/lcov.dat</sonar.javascript.lcov.reportPath>
    ...
</properties>
<dependencies> ... </dependencies>
<build>
    <pluginManagement>
        <plugins>
            ...
            <plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>${sonar.version}</version>
                <executions>
                    <execution>
                        <id>sonar-run</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sonar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ....
        </plugins>
    </pluginManagement>
   </build>
</project>

UPDATE:

I have run sonar analyze with -X debug. The logs below:

[DEBUG] 15:08:27.144 'src/main/resources/static/js/template/template.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter
[DEBUG] 15:08:27.145 'src/main/resources/static/js/navigation/navigationEvents.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter
[DEBUG] 15:08:27.145 'src/main/resources/static/js/navigation/navigation.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter
[DEBUG] 15:08:27.145 'src/main/resources/static/js/navigation/moduleLoader.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter

But doesn't have any exculde settings.


Solution

  • You wrote in the comment that:

    sonar.javascript.exclusions=**/node_modules/**,**/bower_components/**,**/js/**
    

    If you didn't specify it in any pom.xml file, then that value is taken from the server. You can see the configuration by opening: https://sonar.host/admin/settings?category=javascript or Administration → Configuration → JavaSctript. Next you have to find the JavaScript Exclusions section:

    JavaScript Exclusions section

    Probably you will also see **/js/**. From my point of view you should delete that entry because it has no sense. If you cannot then you have to overwrite the default value by adding:

    <sonar.javascript.exclusions>**/node_modules/**,**/bower_components/**</sonar.javascript.exclusions>
    

    or

    <sonar.javascript.exclusions></sonar.javascript.exclusions>