15

Is there some tool that can syntax-check my JavaScript files to see if they contain syntax errors that would bother the Javascript engine of Internet Explorer, especially excess trailing commas?

Example:

var some_object = {
  valid : "property",
  one : "comma too much ---> ",
};

This code works fine in FireFox, Chrome and Node.JS but fails in IE because of the trailing comma. The integrated debugger of IE is rarely a help since it doesn't produce useful errors/warnings for large web applications as we have (lots of JavaScript files combined together summing up to 50-100 k lines of code).

JSLint doesn't help as it reports a huge amount of other warnings or stops at some meaningless error.

One idea could be using eval() directly within IE and catch SyntaxError exceptions but I can't do this in an automated way (ie. on a command line).

Unfortunately Node.JS doesn't bother about trailing commas.

No Linux / Windows tool around that can do basic JavaScript syntax checking for a file?

Todd Smith
  • 17,084
  • 11
  • 59
  • 78
Udo G
  • 12,572
  • 13
  • 56
  • 89

2 Answers2

5

You can try also http://www.javascriptlint.com/. After installed, you may edit jsl.default.conf to set the warnings reported.

jsl -process file.js

Brian White
  • 8,332
  • 2
  • 43
  • 67
Prusse
  • 4,287
  • 2
  • 24
  • 29
  • This helped me too, It was required that it worked on ie7 and one small error was proving a lot of problems, thanks for jsl – relipse Feb 13 '14 at 16:59
-5

Our JavaScript Formatter will prettyprint your JavaScript code. It uses a full JavaScript parser to do so. It reports syntax errors as it parses. Windows.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • 7 years in and this get downvotes. Will the downvoter please explain how this doesn't solve exactly the problem posed? – Ira Baxter Jan 05 '18 at 03:39
  • 6
    Your answer is unclearly worded, your given solution costs money, it only works on Windows, and there are no docs on your site that specify whether its correctness check even meets the OP's needs. Namely, whether it can handle *browser specific* linting. Your site doesn't even say what JS engine it's validating against. – VivaLaPanda Jan 12 '18 at 22:40