From 362c2c9ee378b98b27d7a3fba0b418b714cb2a8f Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Thu, 17 Feb 2022 10:51:57 +0900 Subject: [PATCH] False positives for object values in sort-array-values rule (#155) --- lib/rules/sort-array-values.ts | 3 ++- tests/lib/rules/sort-array-values.ts | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/rules/sort-array-values.ts b/lib/rules/sort-array-values.ts index c198535e..fc8a784e 100644 --- a/lib/rules/sort-array-values.ts +++ b/lib/rules/sort-array-values.ts @@ -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 diff --git a/tests/lib/rules/sort-array-values.ts b/tests/lib/rules/sort-array-values.ts index f3375217..8a3ed676 100644 --- a/tests/lib/rules/sort-array-values.ts +++ b/tests/lib/rules/sort-array-values.ts @@ -48,6 +48,10 @@ tester.run("sort-array-values", rule as any, { }, ], }, + { + code: '{"key": [["b"], ["a"], "c"] }', + options: [{ pathPattern: "^key$", order: { type: "asc" } }], + }, ], invalid: [ {