Skip to content

Latest commit

 

History

History
54 lines (38 loc) · 1.29 KB

object-properties.md

File metadata and controls

54 lines (38 loc) · 1.29 KB

Object Property Sorting (sort/object-properties)

🔧 The --fix option on the command line can automatically fix the problems reported by this rule.

Sorts object properties alphabetically and case insensitive in ascending order.

Rule Details

Examples of incorrect code for this rule:

var a = { b: 1, c: 2, a: 3 }
var a = { C: 1, b: 2 }
var a = { C: 1, b: { y: 1, x: 2 } }

Examples of correct code for this rule:

var a = { a: 1, b: 2, c: 3 }
var a = { b: 1, C: 2 }
var a = { b: { x: 1, y: 2 }, C: 1 }

Options

This rule has an options object with the following defaults.

{
  "sort/object-properties": [
    "error",
    { "caseSensitive": false, "natural": true }
  ]
}

caseSensitive

If true, enforce properties to be in case-sensitive order.

natural

If true, enforce properties to be in natural order. Natural order compares strings containing combination of letters and numbers in the way a human being would sort. For example, a-10 would come after a-3 when using natural ordering.

When Not To Use It

This rule is a formatting preference and not following it won't negatively affect the quality of your code. If alphabetizing object properties isn't a part of your coding standards, then you can leave this rule off.