Installing jshint and rhino for command line javascript analysis

I recently had to install jshint and rhino. It was a bit of a challenge because they needed ant and npm (node package manager). This blog describes what I did and provides a bash shell script that you can use.

Jshint (http://www.jshint.com) is a tool that allows you to statically analyze javascript code. It is useful for detecting ertors and enforcing coding standards.

Rhino is a command line interpreter for javascript (http://mozilla.org/rhino) that is written in java. It can be used for testing and for server side implementations.

You do not have to be root to install these tools.

1 Download

Here are the links to the project code:

Archive Size Extract Command
jsdev.tar.bz2 4.6K tar jxf jsdev.tar.bz2
jsdev.tar.gz 4.6K tar zxf jsdev.tar.gz
jsdev.zip 6.0K unzip jsdev.zip

2 Extract

Use the appropriate command from the previous to table to extract the contents of the archive. When you are finished it will look like this:

jsdev/Makefile
jsdev/conf/std.conf
jsdev/tests/test.sh
jsdev/tests/test01.js
jsdev/tests/test02.js
jsdev/setup.sh

3 Build

Build the system using make. It requires you to have make and java to be installed.

When the build it complete, the tools will be in jsdev/rtf/bin directory. You will need to add this directory to your path environment variable as shown in next section to use the tools.

4 Usage

The example below takes you through the entire process of downloading, installing and using the tools.

5 Trouble Shooting

I have only tested this on a CentOS 5.5 system.

If something goes wrong, take a look at the setup.sh script. It is most likely because there are some packages missing.

Furthermore, you can remove the sections for ant and/or npm if you already have them installed.

6 Manual Steps

Here are the manual steps.

  1. Install ant.
  2. Install npm (node).
  3. Install jshost using npm.
  4. Install rhino using ant.
  5. Create the rhino tool.

If you want to install in a directory like /usr/local/bin change the rtf variable assignment at line 43.

I hope that this is helpful.

4 thoughts on “Installing jshint and rhino for command line javascript analysis”

  1. Error received is as follows

    # ================================================================
    # CMD: tar jxf /home/administrator/Downloads/Rhino/jsdev/archives/apache-ant-1.8.4-bin.tar.bz2
    # PWD: /home/administrator/Downloads/Rhino/jsdev/pkgs
    # ================================================================

    bzip2: Compressed file ends unexpectedly;
    perhaps it is corrupted? *Possible* reason follows.
    bzip2: Inappropriate ioctl for device
    Input file = (stdin), output file = (stdout)

    It is possible that the compressed file(s) have become corrupted.
    You can use the -tvv option to test integrity of such files.

    You can use the `bzip2recover’ program to attempt to recover
    data from undamaged sections of corrupted files.

    tar: Child returned status 2
    tar: Error is not recoverable: exiting now
    EXIT: Command exited with status 2 (FAILED).
    CMD: tar jxf /home/administrator/Downloads/Rhino/jsdev/archives/apache-ant-1.8.4-bin.tar.bz2
    Command exited with non-zero status 1
    0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 5696maxresident)k
    0inputs+0outputs (0major+2000minor)pagefaults 0swaps
    make: *** [all] Error 1

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.