Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Parsing spreads in function call returns #285

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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