Parse error in javascript

Hi,

Sonarqube not able to analyze javascript code.I am using sonarqube 7.6 and javascript plugin sonar-javascript-plugin-5.1.1.7506.

Below is my code :

ERROR: Parse error at line 14 column 7:

4:
5: var rows = prompt(“How many rows for your multiplication table?”);
6: var cols = prompt(“How many columns for your multiplication table?”);
7: if(rows == “” || rows == null)
8: rows = 10;
9: if(cols== “” || cols== null)
10: cols = 10;
11: createTable(rows, cols);
12: function createTable(rows, cols)
13: {
14: var j=1;
^
15: var output = “<table border=‘1’ width=‘500’ cellspacing='0’cellpadding=‘5’>”;
16: for(i=1;i<=rows;i++)
17: {
18: output = output + “

”;
19: while(j<=cols)
20: {
21: output = output + “” + i*j + “”;
22: j = j+1;
23: }
24: output = output + “”;

Thanks
Dhanush

Hi @Dhanush_KC,

  • Are you sure the code you’re analyzing doesn’t actually contain parse errors? Did you verify it somewhere else?
  • If you’re sure the code is valid, could you please share a small reproducer (in the example you posted the code seems to be incomplete) and the logs?

Thanks,
Andrea

Thanks for the reply

Below is the code:

Multiplication Table

1.Yes,This code will run successfully in the browser but sonarqube is giving parse errors which is indicated above(logs in the sonarqube).

  1. Sonarqube says analysis successful but when see in the dashboard it is “This project is empty” is dispalyed.

logs:

INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=1ms
INFO: Sensor Analyzer for “php.ini” files [php]
INFO: Sensor Analyzer for “php.ini” files [php] (done) | time=2ms
INFO: Sensor SonarJS [javascript]
INFO: 1 source files to be analyzed
ERROR: Unable to parse file: file:///E:/sonar_test/mem_js5/mem_js5/test5.js
ERROR: Parse error at line 14 column 3:

4:
5: var rows = prompt(“How many rows for your multiplication table?”);
6: var cols = prompt(“How many columns for your multiplication table?”);
7: if(rows == “” || rows == null)
8: rows = 10;
9: if(cols== “” || cols== null)
10: cols = 10;
11: createTable(rows, cols);
12: function createTable(rows, cols)
13: {
14: var j=1;
^
15: var output = “<table border=‘1’ width=‘500’ cellspacing='0’cellpadding=‘5’>”;
16: for(i=1;i<=rows;i++)
17: {
18: output = output + “

”;
19: while(j<=cols)
20: {
21: output = output + “” + i*j + “”;
22: j = j+1;
23: }
24: output = output + “”;

INFO: Sensor SonarJS [javascript] (done) | time=39ms
INFO: 1/1 source files have been analyzed
INFO: Sensor ESLint-based SonarJS [javascript]
INFO: 1 source files to be analyzed
ERROR: Failed to parse file [file:///E:/sonar_test/mem_js5/mem_js5/test5.js] at line 14: Unexpected token var
INFO: Sensor ESLint-based SonarJS [javascript] (done) | time=13421ms
INFO: 1/1 source files have been analyzed
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=11ms
INFO: Sensor CPD Block Indexer
INFO: Sensor CPD Block Indexer (done) | time=1ms
INFO: No SCM system was detected. You can use the ‘sonar.scm.provider’ property to explicitly specify it.
INFO: Calculating CPD for 0 files
INFO: CPD calculation finished
INFO: Analysis report generated in 107ms, dir size=372 KB
INFO: Analysis reports compressed in 33ms, zip size=68 KB
INFO: Analysis report uploaded in 1970ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/mem_js5
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AWsCcbt1D2q25q8PcBP-
INFO: Executing post-job Final report
INFO: Turn debug info on to get more details (sonar-scanner -X -Dsonar.verbose=true …).
INFO: Executing post-job Final report
INFO: Turn debug info on to get more details (sonar-scanner -X -Dsonar.verbose=true …).
INFO: Task total time: 37.863 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 39.469s
INFO: Final Memory: 16M/328M
INFO: ------------------------------------------------------------------------

How to fix this issue?

Warm Regards,
Dhanush

Could you attach this file? I think it may contain some special characters which breaks the parser.

1 Like

Thanks for this help.
Removed Special characters (<>…</>) and kept pure javascript code and it is displaying report