Installation

This page explains how to install CoffeeLint 2.1.0 as a project dependency, as a global command, or as a browser script, and how to verify that the installation works.

Requirements

The engines field of the package declares the minimum versions:

Requirement Minimum version
Node.js 6.9.1
npm 1.3.7

The project's CI configuration tested Node.js 6.9.1, 7, 8, and the then-current Node.js release.

CoffeeLint depends on the coffeescript package (^2.1.0), which npm installs automatically. Your code is therefore parsed with the CoffeeScript 2 lexer and parser. Source that relies on syntax that changed between CoffeeScript 1 and 2 may be reported as a coffeescript_error.

Note: The repository's README states that CoffeeLint is no longer maintained. Version 2.1.0 is the last version in the repository.

Installing CoffeeLint as a development dependency pins the version for everyone working on the project and keeps CI reproducible:

npm install --save-dev coffeelint

npm links the coffeelint executable into node_modules/.bin, so you can run it directly:

./node_modules/.bin/coffeelint src

Or, more conveniently, add a script to your package.json:

{
  "scripts": {
    "lint": "coffeelint src test"
  },
  "devDependencies": {
    "coffeelint": "^2.1.0"
  }
}

and run:

npm run lint

Installing Globally

A global install puts coffeelint on your PATH:

npm install -g coffeelint

The global executable is smart about versions. When it starts, it first tries to resolve a coffeelint package installed in the current project (searching from the current working directory, the same approach grunt-cli uses). If it finds one, it runs that project-local version; otherwise it falls back to the globally installed code. This means a global install never overrides the version a project has pinned.

Installing from GitHub

The package defines an npm install script that compiles the CoffeeScript sources in src/ into lib/ when lib/commandline.js does not exist yet. This is what allows installing directly from the Git repository rather than from the npm registry:

npm install --save-dev clutchski/coffeelint

The published npm package already contains the compiled lib/ directory (the src/ and test/ folders are excluded via .npmignore), so the compile step is skipped for registry installs.

Using CoffeeLint in the Browser

The package's main entry point, lib/coffeelint.js, is a Browserify standalone bundle that exposes a global coffeelint object when loaded with a <script> tag. In the browser, CoffeeLint does not bundle the CoffeeScript compiler; it expects window.CoffeeScript to exist, so load the CoffeeScript browser compiler first:

<script src="coffeescript.js"></script>
<script src="coffeelint.js"></script>
<script>
  var source = 'x = 1;';
  var errors = coffeelint.lint(source);
  console.log(errors);
</script>

If window.CoffeeScript is missing, the bundle falls back to require('coffeescript'), which only works in environments that provide a Node-style require (Atom-style editors, for example). See the API Reference for the full library interface.

Verifying the Installation

Print the version number:

coffeelint --version
2.1.0

Then lint some code from standard input, ignoring any configuration files:

echo "y = 1" | coffeelint --noconfig --stdin
  ✓ stdin

✓ Ok! » 0 errors and 0 warnings in 1 file

If both commands work, CoffeeLint is installed correctly.

Troubleshooting Installation

  • coffeelint: command not found: for a project install, call it through ./node_modules/.bin/coffeelint or an npm script. For a global install, make sure npm's global bin directory is on your PATH.
  • A different version runs than the one you installed globally: this is expected when the current project has its own coffeelint dependency; the global executable defers to it.
  • Syntax errors on code that compiled before: your code may target CoffeeScript 1. CoffeeLint 2.1.0 parses with CoffeeScript 2.

Next Steps

Continue with the Quick Start to lint your first project, or see Command-Line Usage for every available option.