sorted-array-values
What it does
Section titled “What it does”Reports the items of a sequence that are not in order, for sequences of only strings or only numbers (ascending by default; numbers compare as numbers). A sequence of other or mixed items is skipped. The fewest items that would have to move are reported, and the first report carries the fix. The fix is unsafe: the order of a sequence can be data. Options: direction, compare (ordinal, case_insensitive, natural), min_values (default 2), blank_line_groups and path_patterns (only the sequences whose key path matches one).
Why it matters
Section titled “Why it matters”A list that is kept sorted is easy to scan and to merge: new entries go to one place, and two branches that add different entries rarely conflict. The rule only makes sense where the order is not data, so it is off by default.
To fix, sort the items, or turn the rule off for that list with path_patterns.
Example
Section titled “Example”With this configuration:
sorted-array-values: level: warn options: direction: desc["a", "c", "b"]["c", "b", "a"]Configuration
Section titled “Configuration”lint: rules: sorted-array-values: level: warn # off (default), warn, error options: direction: "asc" compare: "ordinal" min_values: 2 blank_line_groups: false path_patterns: []| Option | Type | Default | Description |
|---|---|---|---|
direction |
string | "asc" |
asc or desc.Values: asc, desc |
compare |
string | "ordinal" |
ordinal (code points), case_insensitive, or natural (digit runs compare as numbers: a2 before a10).Values: ordinal, case_insensitive, natural |
min_values |
int | 2 |
Sequences with fewer items are not checked. |
blank_line_groups |
bool | false |
Sort each run of entries between blank lines on its own. |
path_patterns |
list | [] |
Regular expressions; only mappings (sequences) whose key path matches one are checked. The path is a.b[0].c (["odd key"] for keys that are not identifiers), empty for the root; none listed means everywhere. A TOML table counts as its header key and an array table is not indexed. |
Suppress one line with sudsy-disable-next-line sorted-array-values in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| eslint-plugin-jsonc | jsonc/sort-array-values |
partial | one ordering per rule configuration (ESLint takes a list of {pathPattern, order} entries with different orders per path; use overrides per file instead); no key (sort objects by a property), no explicit value lists or valuePattern, mixed or non-scalar arrays are skipped, report positions when several equally short moves exist |
| taplo | reorder_arrays |
partial | Taplo sorts only values not separated by blank lines; the rule sorts the whole array. |