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?
- Creates a clear visual boundary between your own data shapes and built-in or library properties.
- Makes property access on plain data objects greppable and explicit.
- Pairs with
no-bracket-assignmentto keep bracket notation reserved for reads andReflect.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.
| Option | Type | Default | Description |
|---|---|---|---|
allowedProperties | string[] | [] | Property names to always allow dot notation. |
ignoreFiles | string[] | [] | 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
allowedPropertiesoption to exclude specific property names. - Error fires on a class instance property — Class instance members accessed via
thisor a typed instance variable are excluded. If the rule still fires, check that the type is declared as aclassand not a plaintypeorinterface. - Left-side assignments are not flagged — Assignment targets like
obj.prop = valueare handled by the separateno-bracket-assignmentrule.