Skip to content

Commit

Permalink
docs: add why and usage sections
Browse files Browse the repository at this point in the history
  • Loading branch information
grvcoelho authored Apr 12, 2018
1 parent 27b338f commit 11ec33a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,51 @@
[![Build Status](https://travis-ci.org/grvcoelho/difflint.svg?branch=master)](https://travis-ci.org/grvcoelho/difflint)

:nail_care: Run eslint only in the changed parts of the code

## Why

[ESLint](https://github.com/eslint/eslint) is a great tool to enforce code
style in your code, but it has some limitations: it can only lint entire files.
When working with legacy code, we often have to make changes to very large
files (which would be too troublesome to fix all lint errors)and thus it would
be good to lint only the lines changed and not the entire file.

[difflint](https://github.com/grvcoelho/difflint) receives a commit range and
uses [ESLint](https://github.com/eslint/eslint) to lint the changed files and
filter only the errors introduced in the commit range (and nothing more).

### State of the art

* [lint-staged](https://github.com/okonet/lint-staged) is a similar tool that lints only the staged changes. It's very helpful for adding a precommit hook, but it cannot be used to enforce the styleguide on a Continuous Integration service like Travis, because the changes are already commited.

## Usage

1. Install it:

```sh
npm install difflint
```

2. Install `eslint` and add your eslint configuration file.

3. Use it:

```sh
# This will lint the last commit
difflint lint --commit-range HEAD^..HEAD
```

## Examples

1. Lint the last 3 commits:

```sh
difflint lint --commit-range HEAD~3..HEAD
```

2. Lint all commits from a build in Travis:

```sh
# This environment variable will be available in any Travis build
difflint lint --commit-range $TRAVIS_COMMIT_RANGE
```

0 comments on commit 11ec33a

Please sign in to comment.