Skip to content

dot-notation

Write object.property instead of object["property"] when dot notation works.

Bracket access with a string literal is noisier than dot notation and easy to miss in review. This rule converts those cases to dot notation, keeps the standard escape hatches from ESLint and TypeScript ESLint, and adds an opt-in roblox-ts mode for situations where obj["value"] compiles but obj.value would fail.

The default options cover standard TypeScript. Add the roblox-ts options only if your project uses bracket access for members that dot syntax can’t reach.

OptionTypeDefaultWhat it does
allowKeywordsbooleantrueAllow bracket notation for reserved keywords like obj["class"].
allowPatternstring""Regex pattern for property names that can stay in bracket notation.
allowPrivateClassPropertyAccessbooleanfalseAllow bracket notation for private class members.
allowProtectedClassPropertyAccessbooleanfalseAllow bracket notation for protected class members.
allowIndexSignaturePropertyAccessbooleanfalseAllow bracket notation for properties accessed through a string index.
environment"standard" | "roblox-ts""standard"Set to "roblox-ts" to enable the compiler-aware escape.
allowInaccessibleClassPropertyAccessbooleanfalseAllow brackets when dot notation would fail type checking at that site.
  1. Resolve the member symbol from parser services and the object type.
  2. Check upstream escape hatches first (private/protected/index-signature options).
  3. In opt-in roblox-ts mode, ask the TypeScript checker whether dot access is legal at the current site.
  4. Skip reporting only when dot access would be rejected. Otherwise report and autofix normally.
Incorrect
interface PublicBox {
name: number;
}
function incrementValue(object: PublicBox): void {
object["name"] += 1;
}
Correct
interface PublicBox {
name: number;
}
function incrementValue(object: PublicBox): void {
object.name += 1;
}
// Bracket access is fine when the member is private
function incrementHidden(object: ExampleClass): void {
object["value"] += 1;
}
class ExampleClass {
private value = 0;
}

Less noise

obj.property is shorter and easier to scan than obj["property"] when both mean the same thing.

Compiler-aware

In roblox-ts, the rule leaves bracket access alone when converting it would break type checking.

Auto-fixable

Most violations get cleaned up automatically with eslint --fix.