Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

coffee-jshint

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coffee-jshint

Checks CoffeeScript source for errors using JSHint

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
439
decreased by-79.88%
Maintainers
2
Weekly downloads
 
Created
Source

Coffee->JSHint

Runs your CoffeeScript source through JSHint to check for errors.

Installation

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:

  • undef: warns about use of undeclared variables
  • eqnull: suppresses warnings about == null, which CoffeeScript uses in its generated JS
  • expr: suppresses warnings about expressions in unexpected positions, which can only occur in generated JS when the CoffeeScript compiler does it on purpose
  • shadow: suppresses warnings about variable shadowing, which is fine since CoffeeScript has sane scoping rules and generates safely scoped JS that uses shadowed variables
  • sub: suppresses warnings about using bracket object lookup notation (obj['field']) when you could use dot notation (obj.field) 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 ...

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 ...

Bash

Coffee->JSHint plays nicely with your favorite Bash utilities. We've included a convenient example that recursively checks all .coffee files in a directory (excluding those in any node_modules subdirs):

./scripts/find-and-hint.sh <dir to search> <other options>

For example:

./scripts/find-and-hint.sh . -o node

Git hook

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

# Allows us to read user input below, assigns stdin to keyboard
# http://stackoverflow.com/questions/3417896/how-do-i-prompt-the-user-from-within-a-commit-msg-hook
exec < /dev/tty

# Run Coffee->JSHint
path/to/coffee-jshint/scripts/find-and-hint.sh .
if [ $? -ne 0 ]; then
  read -p "Would you like to ignore JSHint warnings and commit anyway? (y/n) " choice
  case "$choice" in
    [yY] ) exit 0;;
    [nN] ) exit 1;;
    * ) exit 1;;
  esac
fi

FAQs

Package last updated on 23 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc