Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way to check/validate javascript syntax

I have some big set of different javascript-snippets (several thousands), and some of them have some stupid errors in syntax (like unmatching braces/quotes, HTML inside javascript, typos in variable names).

I need a simple way to check JS syntax. I've tried JSLint but it send too many warnings about style, way of variable definitions, etc. (even if i turn off all flags). I don't need to find out style problems, or improve javascript quality, i just need to find obvious syntax errors. Of course i can simply check it in browser/browser console, but i need to do it automatically as the number of that snippets is big.

Add:
JSLint/JSHint reports a lot of problems in the lines that are not 'beauty' but working (i.e. have some potential problems), and can't see the real problems, where the normal compiler will simply report syntax error and stop execution. For example, try to JSLint that code, which has syntax errors on line 4 (unmatched quotes), line 6 (comma required), and line 9 (unexpected <script>).

document.write('something');
a = 0;
if (window.location == 'http://google.com')  a = 1;
document.write("aaa='andh"+a+"eded"');
a = {
  something: ['a']
  something2: ['a']
};
<script>
a = 1;
like image 801
filimonov Avatar asked Mar 28 '13 10:03

filimonov


1 Answers

You could try JSHint, which is less verbose.

like image 122
Piet van Dongen Avatar answered Sep 22 '22 08:09

Piet van Dongen