From 5a2a5fd3199b4f1a8d06a14e388f174176835887 Mon Sep 17 00:00:00 2001 From: Matt Wang Date: Wed, 23 Mar 2022 15:36:16 -0700 Subject: [PATCH 1/2] fixes TypeError error "Cannot destructure property..." in custom-property-pattern Checks if nodes is an empty array, and returns early if so. Adds test case. --- lib/rules/custom-property-pattern/__tests__/index.js | 4 ++++ lib/rules/custom-property-pattern/index.js | 2 ++ 2 files changed, 6 insertions(+) diff --git a/lib/rules/custom-property-pattern/__tests__/index.js b/lib/rules/custom-property-pattern/__tests__/index.js index aba026064b..2ef0a20d24 100644 --- a/lib/rules/custom-property-pattern/__tests__/index.js +++ b/lib/rules/custom-property-pattern/__tests__/index.js @@ -19,6 +19,10 @@ testRule({ { code: ':root { --foo-sub-color: #f00; } a { color: var(--foo-color, var(--foo-sub-color)); }', }, + { + code: 'a { --foo-color: var(); }', + description: 'empty function', + }, ], reject: [ diff --git a/lib/rules/custom-property-pattern/index.js b/lib/rules/custom-property-pattern/index.js index 3f54ed07a0..f30e21e9a9 100644 --- a/lib/rules/custom-property-pattern/index.js +++ b/lib/rules/custom-property-pattern/index.js @@ -58,6 +58,8 @@ const rule = (primary) => { const { nodes, sourceIndex } = node; + if (nodes.length === 0) return; + const { value: firstNodeValue } = nodes[0]; if (check(firstNodeValue)) return; From df205b8ec2dc145f3b04698648e078f9752cc057 Mon Sep 17 00:00:00 2001 From: Matt Wang Date: Wed, 23 Mar 2022 19:46:39 -0700 Subject: [PATCH 2/2] refactors node[0] check with @ybiquitous' suggestion --- lib/rules/custom-property-pattern/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/rules/custom-property-pattern/index.js b/lib/rules/custom-property-pattern/index.js index f30e21e9a9..fc17e15907 100644 --- a/lib/rules/custom-property-pattern/index.js +++ b/lib/rules/custom-property-pattern/index.js @@ -58,11 +58,9 @@ const rule = (primary) => { const { nodes, sourceIndex } = node; - if (nodes.length === 0) return; + const firstNode = nodes[0]; - const { value: firstNodeValue } = nodes[0]; - - if (check(firstNodeValue)) return; + if (!firstNode || check(firstNode.value)) return; complain(declarationValueIndex(decl) + sourceIndex, decl); });