From b28bef9c93d5a21f8efa084ec14b88c361706ecc Mon Sep 17 00:00:00 2001 From: Egor Pavlikhin Date: Fri, 20 Oct 2023 18:50:10 +1100 Subject: [PATCH 1/2] fix: Parsing spreads in function call returns --- lib/util/ast.js | 10 +++++++++- tests/lib/rules/classnames-order.js | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/util/ast.js b/lib/util/ast.js index e420ef1..0034f51 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -184,6 +184,9 @@ function extractRangeFromNode(node) { if (node.type === 'TextAttribute' && node.name === 'class') { return [node.valueSpan.fullStart.offset, node.valueSpan.end.offset]; } + if (node.value === undefined) { + return [0,0]; + } switch (node.value.type) { case 'JSXExpressionContainer': return node.value.expression.range; @@ -196,6 +199,10 @@ function extractValueFromNode(node) { if (node.type === 'TextAttribute' && node.name === 'class') { return node.value; } + if (node.value === undefined) { + return node.value; + } + switch (node.value.type) { case 'JSXExpressionContainer': return node.value.expression.value; @@ -204,9 +211,10 @@ function extractValueFromNode(node) { case 'ArrayExpression': return node.value.expression.elements; break; - case 'ObjectExpression': + case 'ObjectExpression': { return node.value.expression.properties; break; + } } return node.value.expression.value; default: diff --git a/tests/lib/rules/classnames-order.js b/tests/lib/rules/classnames-order.js index 894367c..a9adead 100644 --- a/tests/lib/rules/classnames-order.js +++ b/tests/lib/rules/classnames-order.js @@ -281,6 +281,14 @@ ruleTester.run("classnames-order", rule, { { code: `
Do not treat full width space as class separator
`, }, + { + code: ` + const func = () => ({ a: 12 }); +
Spread of a function return inside clsx
+ `, + }, ], invalid: [ { From 1945b75edfed385918ceb08dc2cc893ee6aa5090 Mon Sep 17 00:00:00 2001 From: Egor Pavlikhin Date: Fri, 20 Oct 2023 18:52:30 +1100 Subject: [PATCH 2/2] Revert style change --- lib/util/ast.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/util/ast.js b/lib/util/ast.js index 0034f51..4648f8d 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -211,10 +211,9 @@ function extractValueFromNode(node) { case 'ArrayExpression': return node.value.expression.elements; break; - case 'ObjectExpression': { + case 'ObjectExpression': return node.value.expression.properties; break; - } } return node.value.expression.value; default: