From de061ff451b4d52366ab14aa9ec048d28407c1cc Mon Sep 17 00:00:00 2001 From: Azat S Date: Mon, 5 Jun 2023 01:24:19 +0300 Subject: [PATCH] fix: fix working sort-map-elements with empty map --- rules/sort-map-elements.ts | 1 + test/sort-map-elements.test.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/rules/sort-map-elements.ts b/rules/sort-map-elements.ts index 61cc7acc..d98d4e41 100644 --- a/rules/sort-map-elements.ts +++ b/rules/sort-map-elements.ts @@ -74,6 +74,7 @@ export default createEslintRule({ if ( node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === 'Map' && + node.arguments.length && node.arguments[0].type === AST_NODE_TYPES.ArrayExpression ) { let [{ elements }] = node.arguments diff --git a/test/sort-map-elements.test.ts b/test/sort-map-elements.test.ts index 9c9d1175..5040fc6c 100644 --- a/test/sort-map-elements.test.ts +++ b/test/sort-map-elements.test.ts @@ -976,7 +976,7 @@ describe(RULE_NAME, () => { it(`${RULE_NAME}: works with empty map`, () => { ruleTester.run(RULE_NAME, rule, { - valid: ['new Map([[], []])'], + valid: ['new Map([[], []])', 'new Map()'], invalid: [], }) })