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 ast expression tests for null expressions #345

Merged
merged 2 commits into from
Jun 20, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/util/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function isVLiteralValue(node) {
* @returns {Boolean}
*/
function isArrayExpression(node) {
return node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ArrayExpression';
return node.value && node.value.type === 'VExpressionContainer' && node.value.expression && node.value.expression.type === 'ArrayExpression';
}

/**
Expand All @@ -106,7 +106,7 @@ function isArrayExpression(node) {
* @returns {Boolean}
*/
function isObjectExpression(node) {
return node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ObjectExpression';
return node.value && node.value.type === 'VExpressionContainer' && node.value.expression && node.value.expression.type === 'ObjectExpression';
}

/**
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.

34 changes: 30 additions & 4 deletions tests/lib/rules/no-custom-classname.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ ruleTester.run("no-custom-classname", rule, {
},
],
},
...(['myTag', 'myTag.subTag', 'myTag(SomeComponent)'].map(tag => ({
...["myTag", "myTag.subTag", "myTag(SomeComponent)"].map((tag) => ({
code: `
${tag}\`
sm:w-6
Expand All @@ -455,7 +455,7 @@ ruleTester.run("no-custom-classname", rule, {
lg:w-4
\`;`,
options: [{ tags: ["myTag"] }],
}))),
})),
{
code: `
<div class="flex flex-row-reverse space-x-4 space-x-reverse">
Expand Down Expand Up @@ -1063,6 +1063,32 @@ ruleTester.run("no-custom-classname", rule, {
code: `
<h1 class="forced-color-adjust-none">New forced-color-adjust utilities</h1>`,
},
{
// fix ast expression tests for null expressions
// @see https://github.com/francoismassart/eslint-plugin-tailwindcss/pull/345
code: `
<template>
<div
class="text-end"
:class="(marketValue ?? 0) < (totalCost ?? 0) ? 'text-danger' : 'text-success'"
>
{{ marketValue?.toFixed(2) }}
</div>
</template>

<script>
export default {
data () {
return {
marketValue: 10,
totalCost: 10
};
}
};
</script>`,
filename: "test.vue",
parser: require.resolve("vue-eslint-parser"),
},
],

invalid: [
Expand Down Expand Up @@ -1224,7 +1250,7 @@ ruleTester.run("no-custom-classname", rule, {
],
errors: generateErrors("dark"),
},
...(['myTag', 'myTag.subTag', 'myTag(SomeComponent)'].flatMap(tag => ([
...["myTag", "myTag.subTag", "myTag(SomeComponent)"].flatMap((tag) => [
{
code: `
${tag}\`
Expand Down Expand Up @@ -1272,7 +1298,7 @@ ruleTester.run("no-custom-classname", rule, {
options: [{ tags: ["myTag"] }],
errors: generateErrors("custom-2 custom-1"),
},
]))),
]),
{
code: `
<div class="bg-red-600 p-10">
Expand Down