object-shorthand
eslint
Safe autofix
eslint.config.js
export default [
{
rules: {
"object-shorthand": "error",
},
},
];Require or disallow method and property shorthand syntax for object literals
const foo = {
w: function() {},
x: function *() {},
[y]: function() {},
z: z
};const foo = {
w() {},
*x() {},
[y]() {},
z
};const foo = {
x: (y) => y
};const foo = {
"bar-baz": function() {},
"qux": qux
};const foo = {
ConstructorFunction: function() {}
};const foo = {
"ConstructorFunction"() {}
};Examples from the ESLint documentation.
object-shorthand
eslint
export default [
{
rules: {
"object-shorthand": "error",
},
},
];object-shorthand
eslint plugin · style
{
"rules": {
"object-shorthand": "error"
}
}style/useConsistentObjectDefinitions
style · since 2.0.0
{
"linter": {
"rules": {
"style": {
"useConsistentObjectDefinitions": "error"
}
}
}
}Require or disallow method and property shorthand syntax for object literals in <template>
Disallow redundant return statements
Disallow loops with a body that allows only one iteration
Require using Error objects as Promise rejection reasons
Disallow specified global variables