sort-keys
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"sort-keys": "error",
},
},
];const obj1 = {a: 1, c: 3, b: 2};
const obj2 = {a: 1, "c": 3, b: 2};
// Case-sensitive by default.
const obj3 = {a: 1, b: 2, C: 3};
// Non-natural order by default.
const obj4 = {1: a, 2: c, 10: b};
// This rule checks computed properties which have a simple name as well.
// Simple names are names which are expressed by an Identifier node or a Literal node.
const S = Symbol("s")
const obj5 = {a: 1, ["c"]: 3, b: 2};
const obj6 = {a: 1, [S]: 3, b: 2};const obj1 = {a: 1, b: 2, c: 3};
const obj2 = {a: 1, "b": 2, c: 3};
// Case-sensitive by default.
const obj3 = {C: 3, a: 1, b: 2};
// Non-natural order by default.
const obj4 = {1: a, 10: b, 2: c};
// This rule checks computed properties which have a simple name as well.
const obj5 = {a: 1, ["b"]: 2, c: 3};
const obj6 = {a: 1, [b]: 2, c: 3};
// This rule ignores computed properties which have a non-simple name.
const obj7 = {a: 1, [c + d]: 3, b: 2};
const obj8 = {a: 1, ["c" + "d"]: 3, b: 2};
const obj9 = {a: 1, [`${c}`]: 3, b: 2};
const obj10 = {a: 1, [tag`c`]: 3, b: 2};
// This rule does not report unsorted properties that are separated by a spread property.
const obj11 = {b: 1, ...c, a: 2};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.
sort-keys
eslint
export default [
{
rules: {
"sort-keys": "error",
},
},
];sort-keys
eslint plugin · style
{
"rules": {
"sort-keys": "error"
}
}Biome does not have this rule.
Enforce sort-keys in a manner that is compatible with order-in-components