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 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-piggyback

v2.0.0

Published

A set of ESLint rules that help catch undeclared references

Readme

node npm

eslint-plugin-piggyback

A set of ESLint rules that help catch undeclared references that ESLint's built-in no-undef rule doesn't find because they are extending other objects
(AKA "piggybacking" :stuck_out_tongue:)

Motivation

This ESLint plugin is useful for migrating a large legacy project that relies on global scope "pollution" into one where all module dependencies are properly declared (via AMD, CommonJS, ES6 Modules, etc.) and automatic module-bundling is possible.
For the most part ESLint's no-undef will get you most of the way there, but each of these custom rules handle a certain edge-case that it does not.

no-restricted-global-extend

Consider the result of linting this code with ESLint when just the no-undef rule is in-use:

/*eslint-env browser*/
Foo.bar(); //`Foo` is not defined in this script. `no-undef` will catch this
window.location.reload(); //`window` is not defined in this script but `no-undef` will not throw an error because `window` has been white-listed as a valid global
window.Foo.baz(); //This will not throw an error despite `Foo` not being defined anywhere and is not a valid property of `window`

In the case above browser is set as the environment because you want to access window.location which is valid because it exists in any browser. But once you do this anyone can assign and access other properties on window without triggering a lint violation, which is why no error is thrown for window.Foo.baz().

The no-restricted-global-extend rule can identify cases where you're using an object which references the global scope (e.g. window in front-end code), and it will alert you if the property you're accessing is not available in the global scope in that environment.

With both no-undef and no-restricted-global-extend in-use:

/*eslint-env browser*/
Foo.bar(); //`Foo` is not defined in this script. `no-undef` will catch this
window.location.reload(); //`window` is not defined in this script but `no-undef` will not throw an error because `window` has been white-listed as a valid global
window.Foo.baz(); //This will now throw an error

no-jquery-extend

This rule helps catch cases where you're using jQuery plugins (e.g. $.cookie, $.query).
jQuery plugins are somewhat of an anti-pattern when it comes to properly declaring your module dependencies because they don't export anything, but rather extend the jQuery object itself.
Generally speaking, if you're refactoring old code that uses a jQuery plugin, there's probably a modern library available that provides the same functionality without relying on or extending jQuery.

With no-jquery-extend in-use:

import $ from 'jquery';

$.ajax( ... ); //This is fine.
$.when( ... ); //This is fine.
$.cookie( ... ); //This will now trigger an ESLint error

Note: This rule will only catch jQuery plugins that extend the jQuery object. It cannot catch jQuery plugins that extend jQuery elements (via jQuery.fn).

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-piggyback:

$ npm install eslint-plugin-piggyback --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-piggyback globally.

Usage

Add piggyback to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "piggyback"
    ]
}

Add the no-restricted-global-extend rule

Configure the 'no-restricted-global-extend' under the rules section in your .eslintrc configuration file. You must specify which identifiers reference the global scope in your environment (e.g. 'window').

{
    "rules": {
        "piggyback/no-restricted-global-extend": [2, "window"]
    }
}

Add the no-jquery-extend rule

Configure the 'no-jquery-extend' under the rules section in your .eslintrc configuration file. You can specify which identifiers reference the jQuery library in your code (default: $ & jQuery).

{
    "rules": {
        "piggyback/no-jquery-extend": [2, "$", "jQuery", "myJQuery"]
    }
}

Changelog

2.0.0 - Switch to ESLint's new rule format. This is a breaking change because as of this ESLint version >= 2.13.0 is required. 1.0.0 - Add the no-jquery-extend rule. This is a breaking change because as of this Node.js version >= 4 is required.

Running tests

Run mocha tests with npm test