Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5e08b2

Browse files
julienbenaczyyv
andauthored
fix(eslint): enhance handling of array expressions (#4925)
Co-authored-by: Chris <[email protected]>
1 parent ffa2297 commit d5e08b2

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

packages-integrations/eslint-plugin/src/rules/order.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ run({
220220
{ code: `tv({ base: 'bottom-1 top-1', variants: { size: { small: 'text-sm px-2 py-1', medium: 'text-base px-4 py-2' } } })`, options: [{ unoFunctions: ['tv'] }] },
221221
// eslint-disable-next-line no-template-curly-in-string
222222
'clsx(`pl1 pr1 ${more}`, test ? `ml-1 mr-1 ${more}` : `left-1 right-1 ${more}`, test && `bottom-1 top-1 ${more}`, { [`bottom-1 top-1 ${more}`]: test })',
223+
`clsx(['ml-1 mr-1'])`,
224+
`clsx(['flex flex-col'], ['bottom-1 top-1'])`,
223225
`notSorted('mr-1 ml-1')`,
224226
],
225227
invalid: [
@@ -349,6 +351,34 @@ run({
349351
{ messageId: 'invalid-order' },
350352
],
351353
},
354+
{
355+
code: `clsx(['mr-1 ml-1'])`,
356+
output: output => expect(output).toMatchInlineSnapshot(`
357+
"clsx(['ml-1 mr-1'])"
358+
`),
359+
errors: [
360+
{ messageId: 'invalid-order' },
361+
],
362+
},
363+
{
364+
code: `clsx(['mr-1 ml-1'], ['top-1 bottom-1'])`,
365+
output: output => expect(output).toMatchInlineSnapshot(`
366+
"clsx(['ml-1 mr-1'], ['bottom-1 top-1'])"
367+
`),
368+
errors: [
369+
{ messageId: 'invalid-order' },
370+
{ messageId: 'invalid-order' },
371+
],
372+
},
373+
{
374+
code: `clsx(['flex-col flex'], className)`,
375+
output: output => expect(output).toMatchInlineSnapshot(`
376+
"clsx(['flex flex-col'], className)"
377+
`),
378+
errors: [
379+
{ messageId: 'invalid-order' },
380+
],
381+
},
352382
],
353383
})
354384

packages-integrations/eslint-plugin/src/rules/order.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ export default createRule({
257257
if (arg.type === 'ObjectExpression') {
258258
return handleObjectExpression(arg)
259259
}
260+
261+
if (arg.type === 'ArrayExpression') {
262+
return arg.elements.forEach((element) => {
263+
if (element && isPossibleLiteral(element)) {
264+
return checkPossibleLiteral(element)
265+
}
266+
})
267+
}
260268
})
261269
},
262270

0 commit comments

Comments
 (0)