The --fix
option on the command line can automatically fix some of the problems reported by this rule.
It’s unnecessary to use computed properties with literals such as:
var foo = {["a"]: "b"};
The code can be rewritten as:
var foo = {"a": "b"};
This rule disallows unnecessary usage of computed property keys.
Examples of incorrect code for this rule:
/*eslint no-useless-computed-key: "error"*/ /*eslint-env es6*/ var a = { ['0']: 0 }; var a = { ['0+1,234']: 0 }; var a = { [0]: 0 }; var a = { ['x']: 0 }; var a = { ['x']() {} };
Examples of correct code for this rule:
/*eslint no-useless-computed-key: "error"*/ var c = { 'a': 0 }; var c = { 0: 0 }; var a = { x() {} }; var c = { a: 0 }; var c = { '0+1,234': 0 };
If you don’t want to be notified about unnecessary computed property keys, you can safely disable this rule.
This rule was introduced in ESLint 2.9.0.
© JS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/rules/no-useless-computed-key