oxlint-tailwindcss 1.17.2 → 1.17.3

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.
package/dist/index.cjs CHANGED
@@ -568,7 +568,7 @@ function reportSettingsProblems(context, program) {
568
568
  * the single home for that decision so it can't drift between them.
569
569
  */
570
570
  function isFinalClassList(loc) {
571
- return loc.origin === "jsx-native";
571
+ return loc.origin === "jsx-native" && loc.partial !== true;
572
572
  }
573
573
  /**
574
574
  * Preserves leading/trailing spaces in fixed class strings for template literals.
@@ -1024,6 +1024,7 @@ function extractLookupTable(node, out = []) {
1024
1024
  * receive a fresh array.
1025
1025
  */
1026
1026
  function extractFromExpression(node, out = []) {
1027
+ while (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSNonNullExpression" || node.type === "TSTypeAssertion") node = node.expression;
1027
1028
  if (node.type === "Literal" && typeof node.value === "string") {
1028
1029
  out.push({
1029
1030
  value: node.value,
@@ -1081,9 +1082,22 @@ function isStyleDeclaration(key, value) {
1081
1082
  if (CUSTOM_PROPERTY.test(key) || VENDOR_PROPERTY.test(key) || CSS_PROPERTY_NAMES.has(key)) return true;
1082
1083
  return value.type === "TemplateLiteral" || value.type === "Literal" && (typeof value.value === "string" || typeof value.value === "number");
1083
1084
  }
1085
+ /**
1086
+ * Every quasi of a template, and the classes in each `${}` between them (#259):
1087
+ * `` `flex ${ok ? "bg-green-500" : "bg-brand"}` `` holds three. The strings in
1088
+ * an expression are read like the operands of a `+` concatenation: glued to a
1089
+ * neighbouring quasi that doesn't end (or start) with whitespace, or to an
1090
+ * adjacent expression, and a glued last token carries its `runtimeClass`
1091
+ * (`${big ? "p" : "m"}-${size}` → `p-${size}`). A template with an expression
1092
+ * is one class list assembled at runtime, so every piece of it is `partial`.
1093
+ */
1084
1094
  function appendFromTemplateLiteral(node, out) {
1085
- for (let i = 0; i < node.quasis.length; i++) {
1086
- const quasi = node.quasis[i];
1095
+ const { quasis, expressions } = node;
1096
+ const partial = expressions.length > 0 ? true : void 0;
1097
+ let operands = null;
1098
+ let strings = null;
1099
+ for (let i = 0; i < quasis.length; i++) {
1100
+ const quasi = quasis[i];
1087
1101
  const value = quasi.value.raw;
1088
1102
  if (value.trim().length > 0) {
1089
1103
  const start = quasi.range[0] + 1;
@@ -1092,10 +1106,41 @@ function appendFromTemplateLiteral(node, out) {
1092
1106
  node: quasi,
1093
1107
  range: [start, start + value.length],
1094
1108
  preserveLeadingSpace: i > 0,
1095
- preserveTrailingSpace: i < node.quasis.length - 1,
1096
- templateLine: node.loc?.start.line
1109
+ preserveTrailingSpace: i < quasis.length - 1,
1110
+ templateLine: node.loc?.start.line,
1111
+ partial
1097
1112
  });
1098
1113
  }
1114
+ if (i >= expressions.length) continue;
1115
+ const inner = extractFromExpression(expressions[i], []);
1116
+ if (inner.length === 0) continue;
1117
+ const before = value;
1118
+ const after = quasis[i + 1].value.raw;
1119
+ const glueBefore = before.length > 0 ? !/\s$/.test(before) : i > 0;
1120
+ const glueAfter = after.length > 0 ? !/^\s/.test(after) : i + 1 < expressions.length;
1121
+ for (const loc of inner) {
1122
+ loc.partial = true;
1123
+ if (glueBefore) loc.preserveLeadingSpace = true;
1124
+ if (glueAfter) {
1125
+ loc.preserveTrailingSpace = true;
1126
+ if (!/\s$/.test(loc.value)) {
1127
+ if (!operands || !strings) {
1128
+ operands = [];
1129
+ strings = [];
1130
+ for (let j = 0; j < quasis.length; j++) {
1131
+ operands.push(quasis[j]);
1132
+ strings.push(quasis[j].value.raw);
1133
+ if (j < expressions.length) {
1134
+ operands.push(expressions[j]);
1135
+ strings.push(void 0);
1136
+ }
1137
+ }
1138
+ }
1139
+ loc.runtimeClass ??= runtimeClass(loc.value, operands, strings, 2 * i + 1);
1140
+ }
1141
+ }
1142
+ out.push(loc);
1143
+ }
1099
1144
  }
1100
1145
  return out;
1101
1146
  }
@@ -1141,6 +1186,7 @@ function appendFromConcatenation(node, out) {
1141
1186
  if (value === void 0) {
1142
1187
  const inner = extractFromExpression(operands[i], []);
1143
1188
  for (const loc of inner) {
1189
+ loc.partial = true;
1144
1190
  if (glueBefore) loc.preserveLeadingSpace = true;
1145
1191
  if (glueAfter) {
1146
1192
  loc.preserveTrailingSpace = true;
@@ -1157,7 +1203,8 @@ function appendFromConcatenation(node, out) {
1157
1203
  node: operand,
1158
1204
  range: [operand.range[0] + 1, operand.range[1] - 1],
1159
1205
  preserveLeadingSpace: glueBefore,
1160
- preserveTrailingSpace: glueAfter
1206
+ preserveTrailingSpace: glueAfter,
1207
+ partial: true
1161
1208
  };
1162
1209
  if (glueAfter && !/\s$/.test(value)) loc.runtimeClass = runtimeClass(value, operands, strings, i);
1163
1210
  out.push(loc);
package/dist/index.mjs CHANGED
@@ -570,7 +570,7 @@ function reportSettingsProblems(context, program) {
570
570
  * the single home for that decision so it can't drift between them.
571
571
  */
572
572
  function isFinalClassList(loc) {
573
- return loc.origin === "jsx-native";
573
+ return loc.origin === "jsx-native" && loc.partial !== true;
574
574
  }
575
575
  /**
576
576
  * Preserves leading/trailing spaces in fixed class strings for template literals.
@@ -1026,6 +1026,7 @@ function extractLookupTable(node, out = []) {
1026
1026
  * receive a fresh array.
1027
1027
  */
1028
1028
  function extractFromExpression(node, out = []) {
1029
+ while (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSNonNullExpression" || node.type === "TSTypeAssertion") node = node.expression;
1029
1030
  if (node.type === "Literal" && typeof node.value === "string") {
1030
1031
  out.push({
1031
1032
  value: node.value,
@@ -1083,9 +1084,22 @@ function isStyleDeclaration(key, value) {
1083
1084
  if (CUSTOM_PROPERTY.test(key) || VENDOR_PROPERTY.test(key) || CSS_PROPERTY_NAMES.has(key)) return true;
1084
1085
  return value.type === "TemplateLiteral" || value.type === "Literal" && (typeof value.value === "string" || typeof value.value === "number");
1085
1086
  }
1087
+ /**
1088
+ * Every quasi of a template, and the classes in each `${}` between them (#259):
1089
+ * `` `flex ${ok ? "bg-green-500" : "bg-brand"}` `` holds three. The strings in
1090
+ * an expression are read like the operands of a `+` concatenation: glued to a
1091
+ * neighbouring quasi that doesn't end (or start) with whitespace, or to an
1092
+ * adjacent expression, and a glued last token carries its `runtimeClass`
1093
+ * (`${big ? "p" : "m"}-${size}` → `p-${size}`). A template with an expression
1094
+ * is one class list assembled at runtime, so every piece of it is `partial`.
1095
+ */
1086
1096
  function appendFromTemplateLiteral(node, out) {
1087
- for (let i = 0; i < node.quasis.length; i++) {
1088
- const quasi = node.quasis[i];
1097
+ const { quasis, expressions } = node;
1098
+ const partial = expressions.length > 0 ? true : void 0;
1099
+ let operands = null;
1100
+ let strings = null;
1101
+ for (let i = 0; i < quasis.length; i++) {
1102
+ const quasi = quasis[i];
1089
1103
  const value = quasi.value.raw;
1090
1104
  if (value.trim().length > 0) {
1091
1105
  const start = quasi.range[0] + 1;
@@ -1094,10 +1108,41 @@ function appendFromTemplateLiteral(node, out) {
1094
1108
  node: quasi,
1095
1109
  range: [start, start + value.length],
1096
1110
  preserveLeadingSpace: i > 0,
1097
- preserveTrailingSpace: i < node.quasis.length - 1,
1098
- templateLine: node.loc?.start.line
1111
+ preserveTrailingSpace: i < quasis.length - 1,
1112
+ templateLine: node.loc?.start.line,
1113
+ partial
1099
1114
  });
1100
1115
  }
1116
+ if (i >= expressions.length) continue;
1117
+ const inner = extractFromExpression(expressions[i], []);
1118
+ if (inner.length === 0) continue;
1119
+ const before = value;
1120
+ const after = quasis[i + 1].value.raw;
1121
+ const glueBefore = before.length > 0 ? !/\s$/.test(before) : i > 0;
1122
+ const glueAfter = after.length > 0 ? !/^\s/.test(after) : i + 1 < expressions.length;
1123
+ for (const loc of inner) {
1124
+ loc.partial = true;
1125
+ if (glueBefore) loc.preserveLeadingSpace = true;
1126
+ if (glueAfter) {
1127
+ loc.preserveTrailingSpace = true;
1128
+ if (!/\s$/.test(loc.value)) {
1129
+ if (!operands || !strings) {
1130
+ operands = [];
1131
+ strings = [];
1132
+ for (let j = 0; j < quasis.length; j++) {
1133
+ operands.push(quasis[j]);
1134
+ strings.push(quasis[j].value.raw);
1135
+ if (j < expressions.length) {
1136
+ operands.push(expressions[j]);
1137
+ strings.push(void 0);
1138
+ }
1139
+ }
1140
+ }
1141
+ loc.runtimeClass ??= runtimeClass(loc.value, operands, strings, 2 * i + 1);
1142
+ }
1143
+ }
1144
+ out.push(loc);
1145
+ }
1101
1146
  }
1102
1147
  return out;
1103
1148
  }
@@ -1143,6 +1188,7 @@ function appendFromConcatenation(node, out) {
1143
1188
  if (value === void 0) {
1144
1189
  const inner = extractFromExpression(operands[i], []);
1145
1190
  for (const loc of inner) {
1191
+ loc.partial = true;
1146
1192
  if (glueBefore) loc.preserveLeadingSpace = true;
1147
1193
  if (glueAfter) {
1148
1194
  loc.preserveTrailingSpace = true;
@@ -1159,7 +1205,8 @@ function appendFromConcatenation(node, out) {
1159
1205
  node: operand,
1160
1206
  range: [operand.range[0] + 1, operand.range[1] - 1],
1161
1207
  preserveLeadingSpace: glueBefore,
1162
- preserveTrailingSpace: glueAfter
1208
+ preserveTrailingSpace: glueAfter,
1209
+ partial: true
1163
1210
  };
1164
1211
  if (glueAfter && !/\s$/.test(value)) loc.runtimeClass = runtimeClass(value, operands, strings, i);
1165
1212
  out.push(loc);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxlint-tailwindcss",
3
- "version": "1.17.2",
3
+ "version": "1.17.3",
4
4
  "description": "Tailwind CSS v4 lint rules for oxlint that read your design system: unknown, conflicting and deprecated classes, theme colors, class order — with autofixes.",
5
5
  "keywords": [
6
6
  "classnames",