Skip to content

Latest commit

 

History

History
97 lines (72 loc) · 1.92 KB

ban-dependencies.md

File metadata and controls

97 lines (72 loc) · 1.92 KB

Bans a list of dependencies from being used

This rule bans dependencies based on a preset list or a user defined list.

Options

presets

You may choose a preset list of dependencies (or none). The following are available:

  • microutilities - micro utilities (e.g. one liners)
  • native - redundant packages with native equivalents
    • Note that this preset will take into account engines in your package.json if it is set. In that only native functionality available in your defined engines.node version range will be considered (or all if it isn't set)
  • preferred - an opinionated list of packages with better maintained and lighter alternatives

Example config:

{
  "rules": {
    "depend/ban-dependencies": ["error", {
      "presets": ["native"]
    }]
  }
}

The default is ['native', 'microutilities', 'preferred'].

modules

You may specify your own list of packages which will be disallowed in code.

For example:

{
  "rules": {
    "depend/ban-dependencies": ["error", {
      "modules": ["im-a-banned-package"]
    }]
  }
}

allowed

You may specify your own list of packages that will be allowed in code even if they are in presets.

For example:

{
  "rules": {
    "depend/ban-dependencies": ["error", {
      "allowed": ["is-nan"]
    }]
  }
}

Rule Details

This rule bans certain dependencies from being used.

The following patterns are considered warnings:

// with `presets: ['native']`
const isNaN = require('is-nan');
isNaN(v);

The following patterns are not warnings:

// with `presets: ['native']`
Number.isNaN(v);

// with `presets: ['native'], allowed: ['is-nan']`
const isNaN = require('is-nan');
isNaN(v);

When Not To Use It

If you prefer not to restrict which dependencies are used, this rule should be disabled.