no-restricted-properties
UnreleasedConfiguration
Rule Details
Certain properties on objects may be disallowed in a codebase. This is useful for deprecating an API or restricting usage of a module's methods — for example, disallowing describe.only when using Mocha, or steering people toward Object.assign instead of _.extend.
This rule looks for accessing a given property key on a given object name, either when reading the property's value or invoking it as a function. It applies to both dot/bracket property access and destructuring.
The rule takes a list of objects, where the object name and property name are specified:
Multiple object/property pairs can be disallowed, and each can specify an optional custom message:
Examples of incorrect code for this rule:
Examples of correct code for this rule:
If the object name is omitted, the property is disallowed on every object:
If the property name is omitted, every property access on the given object is disallowed:
Examples of incorrect code for this rule with { "object": "require" }:
Examples of correct code for this rule with { "object": "require" }:
To restrict a property globally but allow specific objects to use it, add allowObjects (mutually exclusive with object):
Examples of incorrect code for this rule with { "property": "push", "allowObjects": ["router", "history"] }:
Examples of correct code for this rule with { "property": "push", "allowObjects": ["router", "history"] }:
To restrict every property on an object except a chosen few, add allowProperties (mutually exclusive with property):
Examples of incorrect code for this rule with { "object": "config", "allowProperties": ["settings", "version"] }:
Examples of correct code for this rule with { "object": "config", "allowProperties": ["settings", "version"] }:
When Not To Use It
If you don't have any object/property combinations to restrict, you should not use this rule.