This plugin contains a rule that helps you to disallow usage of a variable and suggest you an autofix to replace it by its matching variable name
npm install --save-dev eslint-plugin-no-deprecated-variable
Prevent usage of specific deprecated variable.
For example, we want to prevent usage of DEPRECATED_COLORS
variable and prefer usage of COLORS
with a matching object of preferences.
We could setup our rule like that:
"no-deprecated-variable": [
2,
{
"properties": [{
"deprecate": "DEPRECATED_COLORS",
"matchingVariable": "COLORS",
"matchObject": {
"white": "light[900]",
"secondary": "warning[500]",
}
}]
}
],
With those options, the rule will trigger an error when we use DEPRECATED_COLORS
and suggest to fix the error by replacing DEPRECATED_COLORS.white
by COLORS.light[900]
.
👎 Examples of incorrect code for this rule (defined as above):
/**
* BAD
*/
// file.js
var color = DEPRECATED_COLORS.white;
👍 Examples of correct code for this rule (defined as above):
/**
* GOOD
*/
// file.js
var color = COLORS.light[900];