Skip to content

Commit

Permalink
fix: parsing spreads in function call returns (#285)
Browse files Browse the repository at this point in the history
* fix: Parsing spreads in function call returns
* Revert style change

---------

Co-authored-by: Egor Pavlikhin <egor@pavlikhin.com>
  • Loading branch information
egorpavlikhin and Egor Pavlikhin authored Jan 17, 2024
1 parent 5fdb806 commit 01bd10c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/util/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/classnames-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ ruleTester.run("classnames-order", rule, {
{
code: `<div class="py-1\u3000px-2 block">Do not treat full width space as class separator</div>`,
},
{
code: `
const func = () => ({ a: 12 });
<div className={clsx(['text-sm', {
...func()
}])}>Spread of a function return inside clsx</div>
`,
},
],
invalid: [
{
Expand Down

0 comments on commit 01bd10c

Please sign in to comment.