Linter · Rules
no-restricted-properties
Disallow the object properties you list
Some properties shouldn't be used in your project, like a deprecated method or an API with a better replacement. You list them, and every use is reported with your own message.
The rule does nothing until you give it a list. It checks object.property, object["property"] and destructuring such as const { property } = object.
Configure
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"no-restricted-properties" = "error" # or "warn"
Examples
bunfig.toml
[lint.rules]
"no-restricted-properties" = ["error", {
object = "Math",
property = "pow",
message = "Use the ** operator.",
}]
Reported:
const area = Math.pow(side, 2);
const volume = Math["pow"](side, 3);
const { pow } = Math;
Not reported:
const area = side ** 2;
const half = Math.floor(side / 2);
Options
Each option is an object that describes one restriction. It needs object, property, or both.
| Option | What it does |
|---|---|
object | The name of the object. Without property, every property of this object is reported. |
property | The name of the property. Without object, the property is reported on every object. |
allowProperties | Properties of the object that are still allowed. Only for a restriction with object alone. |
allowObjects | Objects that may still have the property. Only for a restriction with property alone. |
message | Text added to the end of the report. |
A property on every object:
const parent = user.__proto__;
A whole object, with one property left open:
process.exit(1);
const port = process.env.PORT;
A property that only one object may have:
items.push(item);
router.push("/home");