eslint/no-restricted-properties Restriction
What it does
This rule allows you to disallow access to certain properties on certain objects.
Why is this bad?
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, you may want to disallow using describe.only when using Mocha or telling people to use Object.assign instead of _.extend.
If you want to disallow APIs marked with @deprecated, consider using the type-aware typescript/no-deprecated rule instead.
Examples
With options:
"no-restricted-properties": ["error", {
"object": "JSON",
"property": "parse"
}]Examples of incorrect code for this rule:
/* no-restricted-properties: ["error", { "object": "JSON", "property": "parse" }] */
JSON.parse('{ "json": "here" }'); // 'JSON.parse' is restricted from being used.Examples of correct code for this rule:
/* no-restricted-properties: ["error", { "object": "JSON", "property": "parse" }] */
JSON.stringify({ json: "here" });With options:
"no-restricted-properties": ["error", {
"property": "extend",
"allowObjects": ["safeUtils"]
}]Examples of incorrect code for this rule:
/* no-restricted-properties: ["error", { "property": "extend", "allowObjects": ["safeUtils"] }] */
unsafeUtils.extend(value); // 'extend' is restricted from being used. Property 'extend' is only allowed on these objects: safeUtils.Examples of correct code for this rule:
/* no-restricted-properties: ["error", { "property": "extend", "allowObjects": ["safeUtils"] }] */
safeUtils.extend(value);With options:
"no-restricted-properties": ["error", {
"object": "legacyApi",
"allowProperties": ["stableMethod"]
}]Examples of incorrect code for this rule:
/* no-restricted-properties: ["error", { "object": "legacyApi", "allowProperties": ["stableMethod"] }] */
legacyApi.unstableMethod(); // 'legacyApi' is restricted from being used. Only these properties are allowed: stableMethod.Examples of correct code for this rule:
/* no-restricted-properties: ["error", { "object": "legacyApi", "allowProperties": ["stableMethod"] }] */
legacyApi.stableMethod();How to use
To enable this rule using the config file or in the CLI, you can use:
{
"rules": {
"no-restricted-properties": "error"
}
}import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"no-restricted-properties": "error",
},
});oxlint --deny no-restricted-propertiesVersion
This rule was added in v1.63.0.
