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: support tag.div and tag(Component) #302

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rules/classnames-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ module.exports = {
TextAttribute: attributeVisitor,
CallExpression: callExpressionVisitor,
TaggedTemplateExpression: function (node) {
if (!tags.includes(node.tag.name)) {
if (!tags.includes(node.tag.name ?? node.tag.object?.name ?? node.tag.callee?.name)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/enforces-negative-arbitrary-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ module.exports = {
TextAttribute: attributeVisitor,
CallExpression: callExpressionVisitor,
TaggedTemplateExpression: function (node) {
if (!tags.includes(node.tag.name)) {
if (!tags.includes(node.tag.name ?? node.tag.object?.name ?? node.tag.callee?.name)) {
return;
}
parseForNegativeArbitraryClassNames(node, node.quasi);
Expand Down
7 changes: 3 additions & 4 deletions lib/rules/enforces-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,8 @@ module.exports = {
} else if (hasY || hasX) {
const xOrY = hasX ? 'x' : 'y';
const xOrYType = getBodyByShorthand(targetGroups, classname.parentType, xOrY);
const patchedName = `${cls.variants}${important}${minus}${mergedConfig.prefix}${xOrYType}${
absoluteVal.length ? '-' + absoluteVal : ''
}`;
const patchedName = `${cls.variants}${important}${minus}${mergedConfig.prefix}${xOrYType}${absoluteVal.length ? '-' + absoluteVal : ''
}`;
const toBeReplaced = sameVariantAndValue
.filter((c) => {
const candidates = hasX ? ['l', 'r'] : ['t', 'b'];
Expand Down Expand Up @@ -501,7 +500,7 @@ module.exports = {
TextAttribute: attributeVisitor,
CallExpression: callExpressionVisitor,
TaggedTemplateExpression: function (node) {
if (!tags.includes(node.tag.name)) {
if (!tags.includes(node.tag.name ?? node.tag.object?.name ?? node.tag.callee?.name)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/migration-from-tailwind-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ module.exports = {
TextAttribute: attributeVisitor,
CallExpression: callExpressionVisitor,
TaggedTemplateExpression: function (node) {
if (!tags.includes(node.tag.name)) {
if (!tags.includes(node.tag.name ?? node.tag.object?.name ?? node.tag.callee?.name)) {
return;
}
parseForObsoleteClassNames(node, node.quasi);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-arbitrary-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ module.exports = {
TextAttribute: attributeVisitor,
CallExpression: callExpressionVisitor,
TaggedTemplateExpression: function (node) {
if (!tags.includes(node.tag.name)) {
if (!tags.includes(node.tag.name ?? node.tag.object?.name ?? node.tag.callee?.name)) {
return;
}
parseForArbitraryValues(node, node.quasi);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-contradicting-classname.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ module.exports = {
TextAttribute: attributeVisitor,
CallExpression: callExpressionVisitor,
TaggedTemplateExpression: function (node) {
if (!tags.includes(node.tag.name)) {
if (!tags.includes(node.tag.name ?? node.tag.object?.name ?? node.tag.callee?.name)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-custom-classname.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ module.exports = {
TextAttribute: attributeVisitor,
CallExpression: callExpressionVisitor,
TaggedTemplateExpression: function (node) {
if (!tags.includes(node.tag.name)) {
if (!tags.includes(node.tag.name ?? node.tag.object?.name ?? node.tag.callee?.name)) {
return;
}
astUtil.parseNodeRecursive(node, node.quasi, parseForCustomClassNames, false, false, ignoredKeys);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"packageManager": "npm@10.2.5+sha256.8002e3e7305d2abd4016e1368af48d49b066c269079eeb10a56e7d6598acfdaa",
"engines": {
"node": ">=12.13.0"
"node": ">=14.0.0"
Copy link
Contributor

@kachkaev kachkaev May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this is a breaking change (should generate v2 of the plugin). But in practice, v12 is too old so maybe it’s OK. If someone complains about v12 → v14 without notice, it is possible to release a bugfix. It will bring back v12 and replace ?. / ?? with longer notations.

If there are any plans to release anything breaking soon, might be worth bumping Node to v18 given the opportunity. v16 and below are EOL.

},
"license": "MIT"
}
9 changes: 9 additions & 0 deletions tests/lib/rules/arbitrary-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,5 +677,14 @@ ruleTester.run("arbitrary-values", rule, {
options: config,
errors: generateErrors("stroke-[angle:var(--some)]"),
},
...(['myTag', 'myTag.subTag', 'myTag(SomeComponent)'].map(tag => ({
code: `${tag}\`stroke-[var(--some)] stroke-['yolo'] stroke-[angle:var(--some)]\``,
errors: generateErrors("stroke-[angle:var(--some)]"),
options: [
{
tags: ["myTag"],
},
],
}))),
],
});
168 changes: 85 additions & 83 deletions tests/lib/rules/classnames-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ ruleTester.run("classnames-order", rule, {
},
},
},
{
code: `myTag\`
...(['myTag', 'myTag.subTag', 'myTag(SomeComponent)'].map(tag => ({
code: `${tag}\`
container
flex
w-12
Expand All @@ -200,7 +200,7 @@ ruleTester.run("classnames-order", rule, {
tags: ["myTag"],
},
],
},
}))),
{
code: `<div class="z-dialog flex w-12">Number values</div>`,
settings: {
Expand Down Expand Up @@ -699,86 +699,88 @@ ruleTester.run("classnames-order", rule, {
`,
errors: generateErrors(2),
},
{
code: `
myTag\`
invalid
sm:w-6
container
w-12
flex
lg:w-4
\`;`,
output: `
myTag\`
invalid
container
flex
w-12
sm:w-6
lg:w-4
\`;`,
options: [
{
tags: ["myTag"],
},
],
errors: errors,
},
{
code: `
const buttonClasses = myTag\`
\${fullWidth ? "w-12" : "w-6"}
container
\${fullWidth ? "sm:w-8" : "sm:w-4"}
lg:w-9
flex
\${hasError && "bg-red"}
\`;`,
output: `
const buttonClasses = myTag\`
\${fullWidth ? "w-12" : "w-6"}
container
\${fullWidth ? "sm:w-8" : "sm:w-4"}
flex
lg:w-9
\${hasError && "bg-red"}
\`;`,
options: [
{
tags: ["myTag"],
},
],
errors: errors,
},
{
code: `
const buttonClasses = myTag\`
\${fullWidth ? "w-12" : "w-6"}
flex
container
\${fullWidth ? "sm:w-7" : "sm:w-4"}
lg:py-4
sm:py-6
\${hasError && "bg-red"}
\`;`,
output: `
const buttonClasses = myTag\`
\${fullWidth ? "w-12" : "w-6"}
container
flex
\${fullWidth ? "sm:w-7" : "sm:w-4"}
sm:py-6
lg:py-4
\${hasError && "bg-red"}
\`;`,
options: [
{
tags: ["myTag"],
},
],
errors: generateErrors(2),
},
...(['myTag', 'myTag.subTag', 'myTag(SomeComponent)'].flatMap(tag => ([
{
code: `
${tag}\`
invalid
sm:w-6
container
w-12
flex
lg:w-4
\`;`,
output: `
${tag}\`
invalid
container
flex
w-12
sm:w-6
lg:w-4
\`;`,
options: [
{
tags: ["myTag"],
},
],
errors: errors,
},
{
code: `
const buttonClasses = ${tag}\`
\${fullWidth ? "w-12" : "w-6"}
container
\${fullWidth ? "sm:w-8" : "sm:w-4"}
lg:w-9
flex
\${hasError && "bg-red"}
\`;`,
output: `
const buttonClasses = ${tag}\`
\${fullWidth ? "w-12" : "w-6"}
container
\${fullWidth ? "sm:w-8" : "sm:w-4"}
flex
lg:w-9
\${hasError && "bg-red"}
\`;`,
options: [
{
tags: ["myTag"],
},
],
errors: errors,
},
{
code: `
const buttonClasses = ${tag}\`
\${fullWidth ? "w-12" : "w-6"}
flex
container
\${fullWidth ? "sm:w-7" : "sm:w-4"}
lg:py-4
sm:py-6
\${hasError && "bg-red"}
\`;`,
output: `
const buttonClasses = ${tag}\`
\${fullWidth ? "w-12" : "w-6"}
container
flex
\${fullWidth ? "sm:w-7" : "sm:w-4"}
sm:py-6
lg:py-4
\${hasError && "bg-red"}
\`;`,
options: [
{
tags: ["myTag"],
},
],
errors: generateErrors(2),
},
]))),
{
code: `
classnames([
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/enforces-negative-arbitrary-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,14 @@ ruleTester.run("enforces-negative-arbitrary-values", rule, {
code: `<div class="group/edit:-inset-[1px] group/edit:top-[-1px]">support named group/peer syntax</div>`,
errors: generateErrors("group/edit:-inset-[1px]"),
},
...(['myTag', 'myTag.subTag', 'myTag(SomeComponent)'].map(tag => ({
code: `${tag}\`-my-[1px] -mx-[1px]\``,
errors: generateErrors("-my-[1px] -mx-[1px]"),
options: [
{
tags: ["myTag"],
},
],
}))),
],
});
10 changes: 10 additions & 0 deletions tests/lib/rules/enforces-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,5 +800,15 @@ ruleTester.run("shorthands", rule, {
errors: [generateError(["h-custom", "w-custom"], "size-custom")],
options: customSpacingOnlyOptions,
},
...["myTag", "myTag.subTag", "myTag(SomeComponent)"].map((tag) => ({
code: `${tag}\`overflow-hidden text-ellipsis whitespace-nowrap text-white text-xl\``,
output: `${tag}\`truncate text-white text-xl\``,
errors: [generateError(["overflow-hidden", "text-ellipsis", "whitespace-nowrap"], "truncate")],
options: [
{
tags: ["myTag"],
},
],
})),
],
});
18 changes: 18 additions & 0 deletions tests/lib/rules/migration-from-tailwind-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,5 +382,23 @@ ruleTester.run("migration-from-tailwind-2", rule, {
filename: "test.vue",
parser: require.resolve("vue-eslint-parser"),
},
...(['myTag', 'myTag.subTag', 'myTag(SomeComponent)'].map(tag => ({
code: `${tag}\`flex-grow-0\``,
output: `${tag}\`grow-0\``,
errors: [
{
messageId: "classnameChanged",
data: {
deprecated: "flex-grow-0",
updated: "grow-0",
},
},
],
options: [
{
tags: ["myTag"],
},
],
}))),
],
});
9 changes: 9 additions & 0 deletions tests/lib/rules/no-arbitrary-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,14 @@ ruleTester.run("no-arbitrary-value", rule, {
code: `<div className={'min-h-[75dvh]'}>Dynamic viewport units</div>`,
errors: generateErrors(["min-h-[75dvh]"]),
},
...(['myTag', 'myTag.subTag', 'myTag(SomeComponent)'].map(tag => ({
code: `${tag}\`w-[100px]\``,
errors: generateErrors("w-[100px]"),
options: [
{
tags: ["myTag"],
},
],
}))),
],
});
Loading