Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.03 KB

function.md

File metadata and controls

47 lines (35 loc) · 1.03 KB

Prevents some function usage

Rule Details

This rule allows you to forbid some function usage and to suggest some alternative. Maybe really handy for large teams while refactoring codebase.

Example:

Let's consider we have this configuration in .eslintrc:

{
  "plugins": ["deprecate"],
  "rules": {
    "deprecate/function": ["error",
      {"name": "legacyFunc", "use": "newFunc from this package"}
    ]
  }
}

The following patterns are considered as errors:

// any function call with name legacyFunc
console.log(legacyFunc());
legacyFunc();

Options

You can just pass deprecated function names as strings:

"deprecate/function": [ 2, "<fn name1>", "<fn name2>"]

If you want more control over displayed errors (suggest alternative function e.t.c) you can pass objects instead of just function names:

"deprecate/function": [ 2, 
    {"name": "<fn name>", "use": "<suggested alternative>"}, ... ]

When Not To Use It

When you don't want to forbid some function usage in your codebase.