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

eslint-plugin-commonjs-require-case

v1.0.0

Published

eslint plugin for enforcing a `require` case convention

Downloads

2

Readme

eslint-plugin-commonjs-require-case

Contents

Install

  1. Ensure that eslint is installed already.

  2. Install the plugin:

    $ npm install --save-dev eslint-plugin-commonjs-require-case
  3. Configure the plugin...

    • The recommended way, with default settings:

      {
        "extends": [
          "plugin:commonjs-require-case/recommended"
        ]
      }
    • Or override the configuration options as needed:

      {
        "plugins": ["commonjs-require-case"],
        "rules": {
          "commonjs-require-case/rule": ["warn", {"type": "camel"}]
        }
      }

Summary

This plugin contains a single rule, commonjs-require-case/rule, that enforces a case convention for require module assignments. The rule checks that the case of the module assignment matches the configured case.

Options

Two options arguments are accepted:

"commonjs-require-case/rule": [
  "error",          // the eslint error level
  {"type": "camel"} // options object
]

The options use the following schema:

  • An object with the following keys:
    • disable - a list of regex strings that, if matched against the module name, the rule will not run.
    • type - the type of case that module assignments must use.

disable

  • Default: ["^jquery$", "^lodash$", "^underscore$"]

This option is useful for projects that typically use modules with assignment names that deliberately don't follow the enforced rules but are still common enough that they can't be disabled individually every time they are used. This is typical for module names such as jquery, lodash, underscore that are assigned to variables like $ or _.

Instead of having to add an eslint-disable directive every time these appear, they can be globally disabled, like so:

"commonjs-require-case": ["error", {"disable": ["^jquery$", "^lodash$", "^underscore$"]}]

Since disable uses regex strings, it can be configured for projects that use vendored dependencies:

"commonjs-require-case": ["error", {"disable": ["vendor/(jquery|lodash)/dist"]}]

type

  • Default: "camel"
  • Valid values: camel, constant, cram, lower-first, pascal, snake, upper-first

This option configures the type of case that module assignments must conform to.

Here are some examples:

// "commonjs-require-case": ["error", {"type": "camel"}]

const hapi = require("hapi");                // ok
const goodConsole = require("good-console"); // ok
const Joi = require("joi");                  // reported


// "commonjs-require-case": ["error", {"type": "constant"}]

const CORS = require("cors");               // ok
const BODY_PARSER = require("body-parser"); // ok
const express = require("express");         // reported


// "commonjs-require-case": ["error", {"type": "cram"}]

const koa = require("koa");                    // ok
const trierouter = require("trie-router");     // ok
const responseTime = require("response-time"); // reported


// "commonjs-require-case": ["error", {"type": "lower-first"}]

const knex = require("knex");           // ok
const typeORM = require("typeorm");     // ok
const Objection = require("objection"); // reported


// "commonjs-require-case": ["error", {"type": "pascal"}]

const FindIndex = require("lodash/findIndex"); // ok
const Immutable = require("immutable");        // ok
const rxJS = require("rxjs");                  // reported


// "commonjs-require-case": ["error", {"type": "snake"}]

const got = require("got");               // ok
const node_fetch = require("node-fetch"); // ok
const superAgent = require("superagent"); // reported


// "commonjs-require-case": ["error", {"type": "upper-first"}]

const Sinon = require("sinon");           // ok
const ProxyQuire = require("proxyquire"); // ok
const testDouble = require("testdouble"); // reported