Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/automattic/eslint-changed
[READ ONLY] Run ESLint on files and only report new warnings and errors. This repository is a mirror, for issue tracking and development head to: https://github.com/Automattic/Jetpack/
https://github.com/automattic/eslint-changed
eslint npm-module npm-package
Last synced: 3 months ago
JSON representation
[READ ONLY] Run ESLint on files and only report new warnings and errors. This repository is a mirror, for issue tracking and development head to: https://github.com/Automattic/Jetpack/
- Host: GitHub
- URL: https://github.com/automattic/eslint-changed
- Owner: Automattic
- License: other
- Created: 2021-08-12T22:49:21.000Z (over 3 years ago)
- Default Branch: trunk
- Last Pushed: 2024-10-02T14:50:53.000Z (3 months ago)
- Last Synced: 2024-10-07T11:16:33.304Z (3 months ago)
- Topics: eslint, npm-module, npm-package
- Language: JavaScript
- Homepage: https://github.com/Automattic/Jetpack/
- Size: 87.9 KB
- Stars: 3
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Security: SECURITY.md
Awesome Lists containing this project
README
# ESLint Changed
Run [ESLint] on files and only report new warnings and errors.
## Installation
Install via your favorite JS package manager. Note the peer dependency on eslint.
For example,
```
npm install @automattic/eslint-changed eslint
```## Usage
To identify the changes, `eslint-changed` needs the ESLint output for both the old and new versions of the file, as well as the diff between them.
If you use git, it can determine this automatically. Otherwise, you can supply the necessary information manually.Options used in both modes are:
* `--debug`: Enable debug output.
* `--ext `: Comma-separated list of JavaScript file extensions. Ignored if files are listed. (default: ".js")
* `--format `: ESLint format to use for output. (default: "stylish")
* `--in-diff-only`: Only include messages on lines changed in the diff. This may miss things like deleting a `var` that leads to a new `no-undef` elsewhere.### Manual diff
The following options are used with manual mode:
* `--diff `: A file containing the unified diff of the changes.
* `--diff-base `: Base directory the diff is relative to. Defaults to the current directory.
* `--eslint-orig `: A file containing the JSON output of eslint on the unchanged files.
* `--eslint-new `: A file containing the JSON output of eslint on the changed files.### With git
In git mode, `eslint-changed` needs to be able to run `git`. If this is not available by that name in the shell path,
set environment variable `GIT` as appropriate.The following options are used with manual mode:
* `--git`: Signify that you're using git mode.
* `--git-staged`: Compare the staged version to the HEAD version (this is the default).
* `--git-unstaged`: Compare the working copy version to the staged (or HEAD) version.
* `--git-base `: Compare the HEAD version to the HEAD of a different base (e.g. branch).## Examples
This will compare the staged changes with HEAD.
```bash
npx @automattic/eslint-changed --git
```This will compare HEAD with origin/trunk.
```bash
npx @automattic/eslint-changed --git --git-base origin/trunk
```This does much the same as the previous example, but manually. If you're using something other than git, you might do something like this.
```bash
# Produce a diff.
git diff origin/trunk...HEAD > /tmp/diff# Check out the merge-base of origin/trunk and HEAD.
git checkout origin/trunk...HEAD# Run ESLint.
npx eslint --format=json . > /tmp/eslint.orig.json# Go back to HEAD.
git checkout -# Run ESLint again.
npx eslint --format=json . > /tmp/eslint.new.json# Run eslint-changed.
npx @automattic/eslint-changed --diff /tmp/diff --eslint-orig /tmp/eslint.orig.json --eslint=new /tmp/eslint.new.json
```
Note that, to be exactly the same as the above, you'd want to extract the list of files from the diff instead of linting everything. But this will work.## Inspiration
We had been using [phpcs-changed] for a while, and wanted the same thing for ESLint.
[ESLint]: https://www.npmjs.com/package/eslint
[phpcs-changed]: https://packagist.org/packages/sirbrillig/phpcs-changed