JavaScript Syntax Checking from gedit

JSLint is a tool for finding problems in JavaScript programs. Unfortunately, to use it, you need to paste your source code into a textarea on a website - less than ideal. This post will explain how to check your JavaScript directly from gedit.

It is based on these instructions for vim, combined with this method to allow piping text into JSLint from the standard input.


1. Install SpiderMonkey See the build instructions page for installing on many different architectures, or these instructions for quick installations on Ubuntu and CentOS 5.

2. Download JSLint SpiderMonkey Hack Edition Get this version of JSLint which has been modified to allow piping code from the standard input. Save it somewhere in your home directory, say /home/username/bin/js/jslinthack.js. You'll also need to make it executable by typing chmod +x /home/username/bin/js/jslinthack.js

3. Enable the External Tools plugin in gedit Open gedit and click the Edit menu, then choose Preferences. Click the Plugins tab and tick to enable the Extenal Tools plugin.

4. Set up the JSLint External Tool In gedit, open the Tools menu and click External Tools. Click the New button and give your new tool the name JSLint. Give it a descriptive name like "Check JavaScript source code". Give it an Accelerator if you wish (mine is Shift+Ctrl+j). Set the Command to the location at which you saved the hacked JSLint file, eg. /home/username/bin/js/jslinthack.js. Set Input to Current Document and set Output to Insert in Output Panel (you'll need to have the Bottom Panel enabled in gedit's View menu).

5. Profit! Open up a JavaScript source file, and either press your Accelarator keyboard shortcut, or go to Tools > JSLint. The results of the syntax check will be output in the bottom panel.


blog comments powered by Disqus