ExecJSLint
ExecJSLint is a thin Ruby wrapper that uses ExecJS to execute Douglas Crockford's JSLint.
Install
$ gem install execjslint
Usage
js = File.open('path/to/my.js')
results = JSLint.run(js)
if result.valid?
puts "GREAT SUCCESS!"
else
puts "You suck at JavaScript!"
puts result.errors
end
If you're looking to use this in a Rails app, take a look at examples/jslint.rake.
Requirements
You'll need one of the supported ExecJS runtimes. OS X comes with JavaScriptCore by default, so you likely don't need to install anything.
JSLint Options
Right now, ExecJSLint
does not support setting global JSLint options, so you'll
have to include them in a /*jslint */
comment at the top of each file.
jslint.js
will automatically parse and apply options specified like this. A
full list of options is available on jslint.com.
Using an Alternate jslint.js
ExecJSLint depends on the jslint-source
gem, which is a ruby packaging
of the official jslint.js. By default, ExecJSLint depends on the
latest version of the jslint-source
gem. As there are no official releases
of JSLint, jslint-source
is versioned according to the date at the top of
jslint.js (eg, 2012.01.23
). rubygems.org has a full list of
jslint-source
gem versions.
To override this, you can specify an explicit dependency on jslint-source
,
for example, using bundler:
gem 'execjslint'
gem 'jslint-source', '2011.01.23'
You can also explicitly specify a local copy of jslint.js
to use by setting
the JSLINT_PATH
env variable.
$ JSLINT_PATH=../lib/jslint.js rake jslint
Similar Projects
ExecJSLint is meant to be as simple as possible. If it doesn't fit your needs, you may want to try one of these projects:
geraud/jslint - rubygem that provides a standalone
jslint
script that can be run from the command line. Supports Rhino and Node JavaScript engines.psionides/jslint_on_rails - rubygem meant for integrating JSLint into a Rails application. Uses Rhino JavaScript engine.
rondevera/jslintmate - TextMate plugin for running JSLint. Uses JSC.
Why
Why another JSLint wrapper?