# 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`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"no-restricted-properties" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

```toml bunfig.toml
[lint.rules]
"no-restricted-properties" = ["error", {
  object = "Math",
  property = "pow",
  message = "Use the ** operator.",
}]
```

Reported:

{/* bad {"count": 3, "options": [{"object": "Math", "property": "pow", "message": "Use the ** operator."}]} */}
```js
const area = Math.pow(side, 2);
const volume = Math["pow"](side, 3);
const { pow } = Math;
```

Not reported:

{/* good {"options": [{"object": "Math", "property": "pow", "message": "Use the ** operator."}]} */}
```js
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:

{/* bad {"options": [{"property": "__proto__", "message": "Use Object.getPrototypeOf()."}]} */}
```js
const parent = user.__proto__;
```

A whole object, with one property left open:

{/* bad {"options": [{"object": "process", "allowProperties": ["env"]}]} */}
```js
process.exit(1);
```

{/* good {"options": [{"object": "process", "allowProperties": ["env"]}]} */}
```js
const port = process.env.PORT;
```

A property that only one object may have:

{/* bad {"options": [{"property": "push", "allowObjects": ["router"]}]} */}
```js
items.push(item);
```

{/* good {"options": [{"property": "push", "allowObjects": ["router"]}]} */}
```js
router.push("/home");
```
