Skip to main content

Require Bracket Property Access

Require bracket notation (obj['prop']) instead of dot notation (obj.prop) for property access on project-defined plain objects so there is a visual distinction between accessing your own data and built-in or library properties.

Summary

The require-bracket-property-access rule reports dot notation property access on types defined in project source (interfaces, type aliases, Records). It auto-fixes obj.prop to obj['prop'].

The rule inspects TypeScript's type information to distinguish project-defined types from built-in, Node.js, and third-party types.

Why Use This Rule?

  1. Creates a clear visual boundary between your own data shapes and built-in or library properties.
  2. Makes property access on plain data objects greppable and explicit.
  3. Pairs with no-bracket-assignment to keep bracket notation reserved for reads and Reflect.set() for writes.

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
allowedPropertiesstring[][]Property names to always allow dot notation.
ignoreFilesstring[][]File patterns to skip.

Autofix

This rule provides automatic fixes. Run ESLint with the --fix flag:

npx eslint --fix . --rule '@cbnventures/nova/require-bracket-property-access: error'

Troubleshooting

  • Error fires on a third-party type — The rule resolves type origins by inspecting TypeScript's type information. If the type is defined in your project but wraps a third-party type, the rule may still flag it. Use the allowedProperties option to exclude specific property names.
  • Error fires on a class instance property — Class instance members accessed via this or a typed instance variable are excluded. If the rule still fires, check that the type is declared as a class and not a plain type or interface.
  • Left-side assignments are not flagged — Assignment targets like obj.prop = value are handled by the separate no-bracket-assignment rule.