npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coffee-jshint

v1.2.2

Published

Checks CoffeeScript source for errors using JSHint

Downloads

5,425

Readme

Coffee->JSHint

npm version David dependency drift detection

Runs your CoffeeScript source through JSHint to check for errors.

NOTE: As of version 1.0.0, coffee-jshint changed its dependencies to be on coffeescript in favor of the, now deprecated, coffee-script name.

Installation

npm install coffeescript -g ##  See package.json for supported versions (most)
npm install coffee-jshint -g

Usage

To check some files:

coffee-jshint file1.coffee file2.coffee ...

Options

JSHint takes a bunch of options that tell it various rules to enforce or relax. Some of these don't make much sense to check for JS generated by the CoffeeScript compiler, so by default these options are turned on:

Enforcing options

  • undef: warns about the use of explicitly undeclared variables;

Relaxing options

  • eqnull: suppresses warnings about == null comparisons, which CoffeeScript uses in its generated JS;
  • expr: suppresses warnings about the use of expressions where normally you would expect to see assignments or function calls, which can only occur in the generated JS when the CoffeeScript compiler does it on purpose;
  • loopfunc: suppresses warnings about functions inside of loops, which CoffeeScript produces so often that it becomes too hard to spot the legitimate reports between the false-positives (introduced with version 1.1.0);
  • multistr: suppresses warnings about multi-line strings, since CoffeeScript takes care of them;
  • shadow: suppresses warnings about variable shadowing i.e. declaring a variable that had been already declared somewhere in the outer scope, which is fine since CoffeeScript has sane scoping rules and generates safely scoped JS that uses shadowed variables;
  • sub: suppresses warnings about using [] notation when it can be expressed in dot notation since we're grown ups and can make our own decisions about what lookup syntax is best;

To turn on more options, you can use the --options or -o flag:

coffee-jshint -o trailing,browser,sub file1.coffee file2.coffee ...

If you really must turn off some of the default options, use the --default-options-off flag (you can always use --options to turn some back on):

coffee-jshint --default-options-off --options undef,eqnull ...

About esversion

Since the CoffeeScript compiler as of version 2 will produce ES6, Coffee->JSHint (as of version 1.0.1) detects if your coffeescript has a semver version number >= 2, in which case the JSHint esversion: 6 option will be set, and if not esversion: 5. This happens independent of the --default-options-off command line flag and currently there's no way to override this behaviour.

Globals

You'll probably get a lot of complaints from Coffee->JSHint about undefined global variables like console, $, or require. Depending on where you're running your code, you might want to allow a few global variables. One easy way to handle this is to use JSHint's built in environment options.

For instance, if you're running your code using Node.js, then you'll want to turn on the node option. It works like any other option:

coffee-jshint -o node ...

If you have some globals that aren't covered by any of environments, well then you should probably check yo'self before you wreck yo'self. But if you really want to turn off warnings for some global variables, Coffee->JSHint supports it using the --globals or -g option. One use case is when using Mocha, a testing library:

coffee-jshint -o node --globals describe,it ...

Shell scripting

Coffee->JSHint plays nicely with your favorite Unix utilities. If you want to recursively search all the files in a directory, try piping in the results of a find. Here's an example that also filters away any files under the node_modules/ tree:

find . -name node_modules -prune -o -type f -name \*.coffee -print0 | xargs -0 coffee-jshint

Git hook

To use Coffee->JSHint as a git pre-commit hook to check changed files before you commit, put something like this in .git/hooks/pre-commit:

git diff --staged --name-only | xargs coffee-jshint
if [[ $? -ne 0 ]]; then
    echo 'WARNING: You are about to commit files with coffee-jshint warnings'
    exit 1
fi

This will take all the files you plan to commit changes to, run them through coffee-jshint, and exit with status code 1 if there are any warnings (which it will also print out). If there are warnings, the commit will be aborted, but you can always do git commit --no-verify to bypass the hook.

Contributing

See CONTRIBUTING.

Changelog

See CHANGELOG.

License

BSD-3-Clause