No Bracket Method Call
Use dot notation to call methods because obj['toString']() hides the call behind bracket syntax when dot notation is available.
Summary
The no-bracket-method-call rule reports any call expression where the callee uses computed member access with a static string literal key (e.g., obj['method']()).
Bracket property access (reads without a call) and dynamic bracket calls (where the key is a variable) are not affected.
Why Use This Rule?
- Dot notation is the standard way to call methods and is immediately recognizable.
- Static bracket calls hide intent behind unnecessary indirection.
- Dynamic bracket calls (
obj[variable]()) are exempt since they cannot use dot notation.
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 |
|---|---|---|---|
allowedMethods | string[] | [] | Method names that are allowed to be called via bracket 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/no-bracket-method-call: error'
Troubleshooting
- Warning fires on a hyphenated method name — If the method name contains characters that are not valid identifiers (e.g., hyphens), dot notation is not possible. Add the method name to
allowedMethods. - Dynamic key calls are not flagged — The rule only flags static string literal keys. Variable keys like
obj[methodName]()are exempt because dot notation is not an option.