No Bracket Assignment
Use Reflect.set() instead of bracket notation assignment for dynamic property writes.
Summary
The no-bracket-assignment rule reports any assignment expression where the left-hand side uses computed (bracket) member access (e.g., target[key] = value).
It is recommended to use Reflect.set(target, key, value) instead.
Why Use This Rule?
- Makes dynamic property writes explicit and easy to search for.
- Avoids accidental mutation of function parameters when combined with
no-param-reassign. - Provides a consistent pattern for all dynamic property writes across the codebase.
Examples
Configuration
Options
warning
ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.
| Option | Type | Default | Description |
|---|---|---|---|
ignoreFiles | string[] | [] | File patterns to skip. |
Autofix
This rule provides automatic fixes for simple = assignments. Compound operators (+=, -=, *=, etc.) are reported but not auto-fixed. Run ESLint with the --fix flag:
npx eslint --fix . --rule '@cbnventures/nova/no-bracket-assignment: error'
Troubleshooting
- Warning fires on array index assignment — Array index writes like
arr[0] = valuealso use computed member access. UseReflect.set(arr, 0, value)or consider whether.splice()or a new array is more appropriate. - Reading via bracket notation is allowed — The rule only flags assignments (
=,+=, etc.), not reads likeconst x = target[key].