# jsonc/sort-array-values

require array values to be sorted

# 📖 Rule Details

This rule checks values of array and verifies that values are sorted alphabetically or specified order.

Now loading...

# 🔧 Options

{
    "jsonc/sort-array-values": ["error", 
        {
            "pathPattern": "^files$",  // Hits the files property
            "order": { "type": "asc" }
        },
        {
            "pathPattern": "^keywords$", // Hits the keywords property
            "order": [
                "eslint",
                "eslintplugin",
                "eslint-plugin",
                {
                    // Fallback order
                    "order": { "type": "asc" }
                }
            ]
        }
    ]
}

The option receives multiple objects with the following properties:

  • pathPattern (Required) ... Defines the regular expression pattern of paths to which you want to enforce the order. If you want to apply to the top level, define "^$".
  • order (Required) ... Defines how to enforce the order. You can use an object or an array.
    • Array ... Defines an array of values to enforce the order.
      • String ... Defines the value.
      • Object ... The object has the following properties:
        • valuePattern ... Defines a pattern to match the value. Default is to match all.
        • order ... The object has the following properties:
          • type:
            • "asc" ... Enforce values to be in ascending order. This is default.
            • "desc" ... Enforce values to be in descending order.
          • caseSensitive ... If true, enforce values to be in case-sensitive order. Default is true.
          • natural ... If true, enforce values to be in natural order. Default is false.
    • Object ... The object has the following properties:
      • type:
        • "asc" ... Enforce values to be in ascending order. This is default.
        • "desc" ... Enforce values to be in descending order.
      • caseSensitive ... If true, enforce values to be in case-sensitive order. Default is true.
      • natural ... If true, enforce values to be in natural order. Default is false.
  • minValues ... Specifies the minimum number of values that an array should have in order for the array's unsorted values to produce an error. Default is 2, which means by default all arrays with unsorted values will result in lint errors.

# 🚀 Version

This rule was introduced in eslint-plugin-jsonc v2.2.0

# 🔍 Implementation

Last Updated: 10/28/2022, 6:54:42 PM