Skip to main content

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?

  1. Makes dynamic property writes explicit and easy to search for.
  2. Avoids accidental mutation of function parameters when combined with no-param-reassign.
  3. 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.

OptionTypeDefaultDescription
ignoreFilesstring[][]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] = value also use computed member access. Use Reflect.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 like const x = target[key].