sonarjs/prefer-object-literal
eslint-plugin-sonarjs
No autofix
eslint.config.js
export default [
{
rules: {
"sonarjs/prefer-object-literal": "error",
},
},
];let person = {}; // Noncompliant
person.firstName = "John";
person.middleInitial = "Q";
person.lastName = "Public";let person = {
firstName: "John",
middleInitial: "Q",
lastName: "Public",
}Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
sonarjs/prefer-object-literal
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/prefer-object-literal": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Local variables should not be declared and then immediately returned or thrown
Shorthand object properties should be grouped at the beginning or end of an object declaration
Arithmetic operations should not result in "NaN"
Loops should not contain more than a single "break" or "continue" statement
Arithmetic operators should only have numbers as operands