pasika 0.10.83 → 0.10.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3029,6 +3029,31 @@ function stringArguments(node) {
|
|
|
3029
3029
|
}
|
|
3030
3030
|
return [];
|
|
3031
3031
|
}
|
|
3032
|
+
function staticClassLiterals(node) {
|
|
3033
|
+
if (!node) return [];
|
|
3034
|
+
if (node.type === "Literal" && typeof node.value === "string") return [node];
|
|
3035
|
+
if (node.type === "CallExpression") {
|
|
3036
|
+
if (node.callee.type === "Identifier" && node.callee.name === "cn") return [];
|
|
3037
|
+
return node.arguments.flatMap(
|
|
3038
|
+
(argument) => argument.type === "SpreadElement" ? [] : staticClassLiterals(argument)
|
|
3039
|
+
);
|
|
3040
|
+
}
|
|
3041
|
+
if (node.type === "ObjectExpression") {
|
|
3042
|
+
return node.properties.flatMap(
|
|
3043
|
+
(property) => property.type === "Property" ? staticClassLiterals(property.value) : []
|
|
3044
|
+
);
|
|
3045
|
+
}
|
|
3046
|
+
if (node.type === "ArrayExpression") {
|
|
3047
|
+
return node.elements.flatMap((element) => element?.type === "SpreadElement" ? [] : staticClassLiterals(element));
|
|
3048
|
+
}
|
|
3049
|
+
if (node.type === "ConditionalExpression") {
|
|
3050
|
+
return [...staticClassLiterals(node.consequent), ...staticClassLiterals(node.alternate)];
|
|
3051
|
+
}
|
|
3052
|
+
if (node.type === "LogicalExpression") {
|
|
3053
|
+
return [...staticClassLiterals(node.left), ...staticClassLiterals(node.right)];
|
|
3054
|
+
}
|
|
3055
|
+
return [];
|
|
3056
|
+
}
|
|
3032
3057
|
var enforceCnMergeRule = {
|
|
3033
3058
|
meta: { schema: [], type: "problem", docs: { description: "Enforce cn() for conditional class merging." } },
|
|
3034
3059
|
create(context) {
|
|
@@ -3042,6 +3067,32 @@ var enforceCnMergeRule = {
|
|
|
3042
3067
|
}
|
|
3043
3068
|
}
|
|
3044
3069
|
return {
|
|
3070
|
+
CallExpression(node) {
|
|
3071
|
+
if (node.callee.type !== "Identifier") return;
|
|
3072
|
+
if (node.callee.name === "cn") {
|
|
3073
|
+
for (const argument of node.arguments) {
|
|
3074
|
+
if (argument.type !== "Literal" || typeof argument.value !== "string" || classCount(argument.value) <= 5) {
|
|
3075
|
+
continue;
|
|
3076
|
+
}
|
|
3077
|
+
context.report({
|
|
3078
|
+
node: argument,
|
|
3079
|
+
message: "Each cn() string argument must contain at most 5 class names. Group by styling concern. See docs/next-tailwind-guide/rules/class-composition-rule.md"
|
|
3080
|
+
});
|
|
3081
|
+
}
|
|
3082
|
+
return;
|
|
3083
|
+
}
|
|
3084
|
+
if (node.callee.name !== "cva") return;
|
|
3085
|
+
for (const argument of node.arguments) {
|
|
3086
|
+
if (argument.type === "SpreadElement") continue;
|
|
3087
|
+
for (const literal of staticClassLiterals(argument)) {
|
|
3088
|
+
if (typeof literal.value !== "string" || classCount(literal.value) <= 5) continue;
|
|
3089
|
+
context.report({
|
|
3090
|
+
node: literal,
|
|
3091
|
+
message: "Static cva class list with more than 5 classes must use cn() with grouped string literals. See docs/next-tailwind-guide/rules/class-composition-rule.md"
|
|
3092
|
+
});
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
},
|
|
3045
3096
|
JSXAttribute(node) {
|
|
3046
3097
|
const attributeName = node.name?.name ?? "";
|
|
3047
3098
|
const element = node.parent.parent;
|
|
@@ -3107,17 +3158,6 @@ var enforceCnMergeRule = {
|
|
|
3107
3158
|
node,
|
|
3108
3159
|
message: "Static className with more than 5 classes must use cn() with grouped string literals. See docs/next-tailwind-guide/rules/class-composition-rule.md"
|
|
3109
3160
|
});
|
|
3110
|
-
return;
|
|
3111
|
-
}
|
|
3112
|
-
if (expr.type === "CallExpression" && expr.callee.type === "Identifier" && expr.callee.name === "cn") {
|
|
3113
|
-
for (const arg of expr.arguments) {
|
|
3114
|
-
if (arg.type === "Literal" && typeof arg.value === "string" && classCount(arg.value) > 5) {
|
|
3115
|
-
context.report({
|
|
3116
|
-
node: arg,
|
|
3117
|
-
message: "Each cn() string argument must contain at most 5 class names. Group by styling concern. See docs/next-tailwind-guide/rules/class-composition-rule.md"
|
|
3118
|
-
});
|
|
3119
|
-
}
|
|
3120
|
-
}
|
|
3121
3161
|
}
|
|
3122
3162
|
}
|
|
3123
3163
|
};
|