Skip to content

No Restricted Property Assignment

Error
small-rules/no-restricted-property-assignment

Disallow assignment to restricted object properties.

Diagnostic Messages

restricted
Assignment to '{{object}}.{{property}}' is not permitted.
restrictedCustom
{{message}}

Configuration

This rule accepts one options object after the severity.

allowFilesOptional

No description available.

checkComputedOptional

No description available.

restrictionsRequired

No description available.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-restricted-property-assignment": [
"error",
{
"allowFiles": [
"value"
],
"checkComputed": true,
"restrictions": [
{
"message": "value",
"object": "value",
"properties": [
"value"
]
}
]
}
]
}
}

Examples

Restricted property assignment
_G.__DEV__ = true;
Non-matching property assignment
_G.__PROD__ = true;

Rationale

This rule blocks writes to selected properties on selected objects. It reports direct assignments, compound assignments, and update expressions such as ++ or . Reading the same property remains allowed.

Each restriction pairs an object pattern with one or more property patterns. Literal names and glob patterns can cover families of globals or properties. The object must be a direct identifier such as _G; a nested expression such as container._G.DEV does not match.

Computed string properties are checked by default. Set checkComputed to false to exclude code such as _G[“DEV”] = true. Dynamic keys cannot match because their property name is unknown during linting.

The restrictions array is required. Each restriction can supply a diagnostic message; otherwise, the rule reports the matched object and property names. Use allowFiles for filenames or glob patterns that are permitted to perform these writes.