Skip to main content

Python-unittest integration for jslint.

Project description

This package integrates Douglas Crockford’s JSLint tool (https://jslint.com) with Python’s unittest module.

It provides a special JSLint-TestCase class that collects JavaScript files (in a configurable manner) and dynamically generates a test method for each file that calls jslint on that file.

To use it, create a test class like this:

class MyJSLintTest(gocept.jslint.TestCase):

    include = ('my.package.browser:js',
               'my.package.browser:js/lib')
    options = (gocept.jslint.TestCase.options +
               ('--predef=jQuery',))

include is a list of “resource paths” of the form packagename:path (passed to pkg_resources).

options is a list of arguments that are passed to JSLint (see its documentation for details). The default value is:

options = (
    '--browser',
    '--continue',
    '--newcap',
    '--nomen',
    '--sloppy',
    '--sub',
    '--unparam',
    '--vars',
    '--white',
    )

exclude can be a list of filenames (without path) that will not be collected.

All files ending in .js contained in each of these paths will be collected, and the test class will grow a method named test_jslint_filename.js.

You can ignore JSLint error by setting ignore on the test class (a list of substrings that are matched against each JSLint output line):

ignore = (

“Use a named parameter”, )

Requirements

gocept.jslint requires Python 2.6 or later, but is not sure to run under Python 3.

gocept.jslint uses node.js to run jslint (powered by the jslint-reporter wrapper for the original JSLint script), so you need to have node.js (version 0.3 or later) installed and the node binary available on your $PATH.

You can customize the name of the node.js binary by setting node_js_command on the TestCase.

gocept.jslint also provides a command-line script to run jslint, for convenience. There you can customize the name of the node binary by setting the environment variable NODE_JS_COMMAND.

CHANGES

1.0.1 (2012-04-18)

  • Uniquify duplicate file names in a prettier way: increment a counter, don’t just blindly append ‘_1’ (#9454).

1.0 (2011-08-25)

  • Add support for linting JS files contained in zipped eggs (#9453).

  • Add an entry point for running jslint from the command line (#9449).

  • Skip tests if node.js is not available. Skipping tests only works properly in Python >= 2.7, though. (#9458)

0.2 (2011-08-24)

  • Implement custom error ignores (#9456).

0.1 (2011-08-10)

  • first release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gocept.jslint-1.0.1.zip (63.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page