Skip to content

Commit

Permalink
False positives for object values in sort-array-values rule (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Feb 17, 2022
1 parent 0308b7a commit 362c2c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/sort-array-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ function buildValidatorFromType(
if (typeof a.value === "string" && typeof b.value === "string") {
return compareText([a.value, b.value])
}
if (getJSONPrimitiveType(a.value) === getJSONPrimitiveType(b.value)) {
const type = getJSONPrimitiveType(a.value)
if (type && type === getJSONPrimitiveType(b.value)) {
return compareValue([a.value, b.value])
}
// Unknown
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/sort-array-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ tester.run("sort-array-values", rule as any, {
},
],
},
{
code: '{"key": [["b"], ["a"], "c"] }',
options: [{ pathPattern: "^key$", order: { type: "asc" } }],
},
],
invalid: [
{
Expand Down

0 comments on commit 362c2c9

Please sign in to comment.