no-useless-computed-key
Configuration
rslint.config.ts
Rule Details
Disallow computed property keys when their use is unnecessary. For example, { ["a"]: 1 } can be rewritten as { a: 1 } with the same behavior. The rule applies to object literals, destructuring patterns, and (by default) class members. A few keys retain distinct semantics in computed form and are therefore exempt:
{ ["__proto__"]: v }defines a regular property, whereas{ __proto__: v }sets the object's prototype.- In a class,
["constructor"]()is a regular method whereasconstructor()is the constructor. - In a class,
static ["prototype"]/static ["prototype"]()produce only a runtime error, whereas the unbracketed form is a parse error that breaks the whole script.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
This rule has one option, an object with a single key:
enforceForClassMembers(defaulttrue): whenfalse, the rule only flags object literals and destructuring patterns and leaves class members alone.
Examples of correct code for this rule with { "enforceForClassMembers": false }: