Skip to content

noJsRestrictedProperties

biome.json
{
"linter": {
"rules": {
"nursery": {
"noJsRestrictedProperties": "error"
}
}
}
}

Disallow specific object properties.

This rule lets you ban property access for exact object/property pairs, all properties on a given object, or a property name everywhere except for a short allowlist of objects.

It also reports restricted properties when they appear in object destructuring.

This rule requires explicit configuration to specify which properties are restricted, so it does not report anything by default.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noJsRestrictedProperties": {
"level": "on",
"options": {
"entries": [
{
"object": "require",
"property": "ensure",
"message": "Use dynamic import() instead."
}
]
}
}
}
}
}
}

In this example, the rule reports the access of the ensure property on the require object, and emits the message “Use dynamic import() instead.”:

require.ensure("./entry")
code-block.js:1:9 lint/nursery/noJsRestrictedProperties ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Do not use ‘require.ensure’.

> 1 │ require.ensure(”./entry”)
^^^^^^
2 │

Use dynamic import() instead.

Remove this usage to comply with the project’s guidelines.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Property-wide restriction with an allowlist

Section titled “Property-wide restriction with an allowlist”
biome.json
{
"linter": {
"rules": {
"nursery": {
"noJsRestrictedProperties": {
"level": "on",
"options": {
"entries": [
{
"property": "__defineGetter__",
"message": "Use Object.defineProperty() instead.",
"allowObjects": [
"Object"
]
}
]
}
}
}
}
}
}

In this example, the rule reports any access to the property __defineGetter__, except for Object object, and it emits the message “Use Object.defineProperty() instead.”:

foo.__defineGetter__
code-block.js:1:5 lint/nursery/noJsRestrictedProperties ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Do not use property ‘__defineGetter__’.

> 1 │ foo.__defineGetter__
^^^^^^^^^^^^^^^^
2 │

Use Object.defineProperty() instead.

Property ‘__defineGetter__’ is only allowed on these objects: Object.

Remove this usage to comply with the project’s guidelines.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Object.__defineGetter__

Object-wide restriction with allowed exceptions

Section titled “Object-wide restriction with allowed exceptions”
biome.json
{
"linter": {
"rules": {
"nursery": {
"noJsRestrictedProperties": {
"level": "on",
"options": {
"entries": [
{
"object": "arguments",
"message": "Avoid accessing arbitrary arguments properties.",
"allowProperties": [
"length"
]
}
]
}
}
}
}
}
}

In the following example, when the rule encounters the object arguments, it reports all properties except for length with the message “Avoid accessing arbitrary arguments properties.”:

arguments.callee
code-block.js:1:11 lint/nursery/noJsRestrictedProperties ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Do not access properties on ‘arguments’.

> 1 │ arguments.callee
^^^^^^
2 │

Avoid accessing arbitrary arguments properties.

Only these properties are allowed on ‘arguments’: length.

Remove this usage to comply with the project’s guidelines.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

arguments.length

An array of restricted object/property combinations. Depending on the provided options, each entry can:

  • Restrict a specific property on a specific object.
  • Restrict all properties on a specific object except for an allowlist of properties.
  • Restrict a specific property everywhere except for an allowlist of objects.
  • Provide a custom message to include in the diagnostic when the restriction is violated.

The object for which the restriction applies. If not provided, the restriction applies to all objects. If combined with property, it restricts only that property on the specified object.

The property for which the restriction applies. If not provided, the restriction applies to all properties. If combined with object, it restricts that property only on that object.

When restricting a property, an optional allowlist of objects that are exempt from the restriction. Only applicable when property is provided and object is not provided.

It conflicts with allowProperties.

When restricting an object, an optional allowlist of properties that are exempt from the restriction. Only applicable when object is provided and property is not provided.

It conflicts with allowObjects.

An optional custom message to include in the diagnostic when this restriction is violated. If not provided, a default message will be used.

Use this to give context and explain why the property is restricted, and to suggest an alternative.