:nail_care: Run eslint only in the changed parts of the code
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.
State of the art
- 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.
- Install it:
npm install @grvcoelho/lint-diff
eslintand add your eslint configuration file.
# This will lint the last commit lint-diff lint HEAD^..HEAD
- Lint the last 3 commits:
lint-diff lint HEAD~3..HEAD
- Lint local changes that are not yet commited (similar to what lint-staged do):
lint-diff lint HEAD
- Lint all commits from a build in Travis:
# This environment variable will be available in any Travis build lint-diff lint $TRAVIS_COMMIT_RANGE