npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@automattic/eslint-changed

v2.0.9

Published

Run eslint on files, but only report warnings and errors from lines that were changed.

Downloads

1,009

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 <list>: Comma-separated list of JavaScript file extensions. Ignored if files are listed. (default: ".js")
  • --format <name>: 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 <file>: A file containing the unified diff of the changes.
  • --diff-base <dir>: Base directory the diff is relative to. Defaults to the current directory.
  • --eslint-orig <file>: A file containing the JSON output of eslint on the unchanged files.
  • --eslint-new <file>: 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 <ref>: Compare the HEAD version to the HEAD of a different base (e.g. branch).

Examples

This will compare the staged changes with HEAD.

npx @automattic/eslint-changed --git

This will compare HEAD with origin/trunk.

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.

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