JavaScript Lint – checks your JavaScript source code for common mistakes

I recently worked on a web application with a lot of Javascript code in it. The app worked well in Firefox, but when trying it in Internet Explorer 7 – to my surprise – the app did not work and reported a lot of weird errors (unfortunately, the error report wasn’t helpful). The IDE (Eclipse) did not report any errors in my Javascript files.

I found a tool that helped me a lot in finding the errors: JavaScript Lint.

JavaScript Lint is an open source tool (GPL) that checks your JavaScript source code for syntax errors and questionable coding practices. It gives you a detailed report with line numbers and a description whats wrong (and what could be improved) in your code. You can configure which warnings schould be reported.

Some problems the tool is able to detect (excerpt):

  • Missing semicolons at the end of a line.
  • Curly braces without an if, for, while, etc.
  • Code that is never run because of a return, throw, continue, or break.
  • Case statements in a switch that do not have a break statement.
  • Leading and trailing decimal points on a number.
  • A leading zero that turns a number into octal (base 8).
  • Comments within comments.
  • Ambiguity whether two adjacent lines are part of the same statement.
  • Statements that don’t do anything.

There’s also an online version of the tool that you can use to try it out.

After fixing the errors reported by JSLint, the app worked in both IE and Firefox.

Short URL for this post:
This entry was posted in Java and Quality, Other languages for the Java VM and tagged , . Bookmark the permalink.

1 Response to JavaScript Lint – checks your JavaScript source code for common mistakes

  1. Stefan Frank says:

    … and last, but not least: It finds undeclared variables (missing var) – on which IE regularly (and rightfully so) chokes, but ff silently ignores. For me, that was the number one reason for “runs on ff, doesn’t do anything on IE.

Leave a Reply

Your email address will not be published. Required fields are marked *