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

lint-diff-line

v1.2.16

Published

:Run eslint only in the changed parts of the code

Downloads

11,411

Readme

lint-diff-line

Run eslint only in the changed parts of the code

Acknowledgment

This is almost entirely a port of lint-diff.

That library, at the time of the creation of this library has not been updated in 5 years and is using eslit 4.x. The library does not seem to be accepting pull requests, so I decided to do it my self.

The original is written entirely in rambda and quite nicely so. Unfortunately, my rambda abilities are questionable at best. I was unable to thorouly understand the code nor make updates for the new api versions until I ported it into boring old js.

I also have not had time to update it into typescript. But I intend eventually to do that.

The logic and hard work has all been done by grvcoelho. Thank you

Why

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.

lint-diff-line receives a commit range and uses 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 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:
$ npm install lint-diff-line
  1. Install eslint and add your eslint configuration file.

  2. Use it:

# This will lint the last commit
$ lint-diff-line -r HEAD^..HEAD

# This will lint the differences between your current commit and your origin
$ lint-diff-line -r origin/$(git branch --show-current)..$(git branch --show-current)

# The default is just `.js` This will lint the last commit but only typescript and json files (for an example)
$ lint-diff-line -r HEAD^..HEAD --ext .ts,.json

# This will lint .ts and .json files only in the src/fubar folder
$ lint-diff-line -r HEAD^..HEAD --ext .ts,.json -f '/src/fubar/**'

Examples

  1. Lint the last 3 commits:
$ lint-diff-line -r HEAD~3..HEAD
  1. Lint local changes that are not yet commited (similar to what lint-staged do):
$ lint-diff-line -r HEAD
# or
$ lint-diff-line

Flags

The git commit range e.g. -r HEAD~1..HEAD, -r master..my-branch etc

--range -r :default 'HEAD'

Restict file extenstions e.g. -e .js,.ts,.jsx,.tsx

--ext -e :default '.js'

A glob pattern for which files to lint. Please NOTE the quotes around the pattern e.g. -f '/frontendApp/src/** backendApp/src/*.ts'. multiple values can be used space deliniated

--files -f :default '**'

helpful values

I use this range pattern to lint the files changed since the last time I pushed to the remote. This works great unless you have not yet pushed to remote (i.e. there is no version 'origin/whatever'), in which case it throws. I don't know quite how to get around that. I welcome ideas. -r origin/$(git branch --show-current)..$(git branch --show-current)