oxlint-tailwindcss 1.15.1 → 1.16.0

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
@@ -8956,6 +8956,31 @@ function isJsxAttributeString(loc) {
8956
8956
  const node = loc.node;
8957
8957
  return node.type === "Literal" && node.parent?.type === "JSXAttribute";
8958
8958
  }
8959
+ /**
8960
+ * A JS string `wrapStrings: 'all'` turns into a template literal. Its place
8961
+ * takes any expression — a call argument (`cn("…")`), `className={"…"}`, an
8962
+ * array element, an object value, a ternary or `&&` branch, a variable's
8963
+ * initializer — but never an object key or a `+` operand. And a template reads
8964
+ * its text the same way: `raw` is the source between the quotes, so it must
8965
+ * equal the value (no escape sequence, which a template can read differently)
8966
+ * and hold no `` ` `` or `${`.
8967
+ */
8968
+ function isConvertibleJsString(loc, raw) {
8969
+ const node = loc.node;
8970
+ if (node.type !== "Literal" || raw !== loc.value) return false;
8971
+ if (raw.includes("`") || raw.includes("${")) return false;
8972
+ const parent = node.parent;
8973
+ switch (parent?.type) {
8974
+ case "CallExpression": return parent.arguments?.includes(node) === true;
8975
+ case "Property": return parent.value === node;
8976
+ case "VariableDeclarator": return parent.init === node;
8977
+ case "ConditionalExpression": return parent.test !== node;
8978
+ case "ArrayExpression":
8979
+ case "LogicalExpression":
8980
+ case "JSXExpressionContainer": return true;
8981
+ default: return false;
8982
+ }
8983
+ }
8959
8984
  /** One indentation level added below the statement's base indent for wrapped lines. */
8960
8985
  const INDENT_UNIT = " ";
8961
8986
  /** Group `classes` into chunks of at most `n`, each chunk space-joined. */
@@ -9039,7 +9064,7 @@ const enforceConsistentLineWrapping = defineRule({
9039
9064
  recommended: false,
9040
9065
  designSystem: "optional"
9041
9066
  }),
9042
- fixable: "whitespace",
9067
+ fixable: "code",
9043
9068
  schema: [{
9044
9069
  type: "object",
9045
9070
  properties: {
@@ -9060,7 +9085,11 @@ const enforceConsistentLineWrapping = defineRule({
9060
9085
  },
9061
9086
  wrapStrings: {
9062
9087
  type: "string",
9063
- enum: ["never", "jsx"]
9088
+ enum: [
9089
+ "never",
9090
+ "jsx",
9091
+ "all"
9092
+ ]
9064
9093
  }
9065
9094
  },
9066
9095
  additionalProperties: false
@@ -9102,10 +9131,10 @@ const enforceConsistentLineWrapping = defineRule({
9102
9131
  return "";
9103
9132
  }
9104
9133
  /**
9105
- * The line ending a JSX string's fix writes. A JSX attribute keeps the
9106
- * file's `\r\n` in its value (a template's is LF already), so a CRLF file
9107
- * gets CRLF breaks: from the value when it has any, else from the line the
9108
- * string ends on.
9134
+ * The line ending a string's fix writes. A JSX attribute keeps the file's
9135
+ * `\r\n` in its value (a template's is LF already), so a CRLF file gets
9136
+ * CRLF breaks: from the value when it has any, else from the line the
9137
+ * string ends on — the only source for a JS string turned into a template.
9109
9138
  */
9110
9139
  function lineEndingOf(loc) {
9111
9140
  if (loc.value.includes("\r\n")) return "\r\n";
@@ -9200,15 +9229,19 @@ const enforceConsistentLineWrapping = defineRule({
9200
9229
  const group = getGroup();
9201
9230
  const prefix = wrapLines === "all" && group !== "never" && classesPerLine === void 0 ? softGetDS(getDS)?.cache.prefix ?? "" : "";
9202
9231
  const wrapStrings = getWrapStrings();
9232
+ const text = wrapStrings === "all" ? safeSourceCode(context)?.text : void 0;
9203
9233
  for (const written of locations) {
9204
- const wrapsString = wrapStrings === "jsx" && isJsxAttributeString(written);
9205
- const fixable = written.node.type === "TemplateElement" || wrapsString;
9206
- const eol = wrapsString ? lineEndingOf(written) : "\n";
9234
+ const wrapsString = wrapStrings !== "never" && isJsxAttributeString(written);
9235
+ const convertsString = wrapStrings === "all" && !wrapsString && isConvertibleJsString(written, text?.slice(written.range[0], written.range[1]));
9236
+ const fixable = written.node.type === "TemplateElement" || wrapsString || convertsString;
9237
+ const eol = wrapsString || convertsString ? lineEndingOf(written) : "\n";
9207
9238
  const loc = eol === "\n" ? written : {
9208
9239
  ...written,
9209
9240
  value: written.value.replace(/\r\n/g, "\n")
9210
9241
  };
9211
9242
  const toSource = (value) => eol === "\n" ? value : value.replace(/\n/g, eol);
9243
+ const fixRange = convertsString ? loc.node.range : loc.range;
9244
+ const toFix = (value) => convertsString ? "`" + toSource(value) + "`" : toSource(value);
9212
9245
  let maxLine = 0;
9213
9246
  for (const line of loc.value.split("\n")) {
9214
9247
  if (line.length <= maxLine) continue;
@@ -9228,7 +9261,7 @@ const enforceConsistentLineWrapping = defineRule({
9228
9261
  messageId: maxLine > printWidth ? "tooLong" : "inconsistentWrapping",
9229
9262
  data,
9230
9263
  fix(fixer) {
9231
- return fixer.replaceTextRange(loc.range, toSource(fixedValue));
9264
+ return fixer.replaceTextRange(fixRange, toFix(fixedValue));
9232
9265
  }
9233
9266
  });
9234
9267
  } else if (maxLine > printWidth) context.report({
@@ -9255,7 +9288,7 @@ const enforceConsistentLineWrapping = defineRule({
9255
9288
  messageId: "tooManyPerLine",
9256
9289
  data,
9257
9290
  fix(fixer) {
9258
- return fixer.replaceTextRange(loc.range, toSource(preserveSpaces(loc, fixedValue)));
9291
+ return fixer.replaceTextRange(fixRange, toFix(preserveSpaces(loc, fixedValue)));
9259
9292
  }
9260
9293
  });
9261
9294
  } else context.report({
package/dist/index.mjs CHANGED
@@ -8959,6 +8959,31 @@ function isJsxAttributeString(loc) {
8959
8959
  const node = loc.node;
8960
8960
  return node.type === "Literal" && node.parent?.type === "JSXAttribute";
8961
8961
  }
8962
+ /**
8963
+ * A JS string `wrapStrings: 'all'` turns into a template literal. Its place
8964
+ * takes any expression — a call argument (`cn("…")`), `className={"…"}`, an
8965
+ * array element, an object value, a ternary or `&&` branch, a variable's
8966
+ * initializer — but never an object key or a `+` operand. And a template reads
8967
+ * its text the same way: `raw` is the source between the quotes, so it must
8968
+ * equal the value (no escape sequence, which a template can read differently)
8969
+ * and hold no `` ` `` or `${`.
8970
+ */
8971
+ function isConvertibleJsString(loc, raw) {
8972
+ const node = loc.node;
8973
+ if (node.type !== "Literal" || raw !== loc.value) return false;
8974
+ if (raw.includes("`") || raw.includes("${")) return false;
8975
+ const parent = node.parent;
8976
+ switch (parent?.type) {
8977
+ case "CallExpression": return parent.arguments?.includes(node) === true;
8978
+ case "Property": return parent.value === node;
8979
+ case "VariableDeclarator": return parent.init === node;
8980
+ case "ConditionalExpression": return parent.test !== node;
8981
+ case "ArrayExpression":
8982
+ case "LogicalExpression":
8983
+ case "JSXExpressionContainer": return true;
8984
+ default: return false;
8985
+ }
8986
+ }
8962
8987
  /** One indentation level added below the statement's base indent for wrapped lines. */
8963
8988
  const INDENT_UNIT = " ";
8964
8989
  /** Group `classes` into chunks of at most `n`, each chunk space-joined. */
@@ -9042,7 +9067,7 @@ const enforceConsistentLineWrapping = defineRule({
9042
9067
  recommended: false,
9043
9068
  designSystem: "optional"
9044
9069
  }),
9045
- fixable: "whitespace",
9070
+ fixable: "code",
9046
9071
  schema: [{
9047
9072
  type: "object",
9048
9073
  properties: {
@@ -9063,7 +9088,11 @@ const enforceConsistentLineWrapping = defineRule({
9063
9088
  },
9064
9089
  wrapStrings: {
9065
9090
  type: "string",
9066
- enum: ["never", "jsx"]
9091
+ enum: [
9092
+ "never",
9093
+ "jsx",
9094
+ "all"
9095
+ ]
9067
9096
  }
9068
9097
  },
9069
9098
  additionalProperties: false
@@ -9105,10 +9134,10 @@ const enforceConsistentLineWrapping = defineRule({
9105
9134
  return "";
9106
9135
  }
9107
9136
  /**
9108
- * The line ending a JSX string's fix writes. A JSX attribute keeps the
9109
- * file's `\r\n` in its value (a template's is LF already), so a CRLF file
9110
- * gets CRLF breaks: from the value when it has any, else from the line the
9111
- * string ends on.
9137
+ * The line ending a string's fix writes. A JSX attribute keeps the file's
9138
+ * `\r\n` in its value (a template's is LF already), so a CRLF file gets
9139
+ * CRLF breaks: from the value when it has any, else from the line the
9140
+ * string ends on — the only source for a JS string turned into a template.
9112
9141
  */
9113
9142
  function lineEndingOf(loc) {
9114
9143
  if (loc.value.includes("\r\n")) return "\r\n";
@@ -9203,15 +9232,19 @@ const enforceConsistentLineWrapping = defineRule({
9203
9232
  const group = getGroup();
9204
9233
  const prefix = wrapLines === "all" && group !== "never" && classesPerLine === void 0 ? softGetDS(getDS)?.cache.prefix ?? "" : "";
9205
9234
  const wrapStrings = getWrapStrings();
9235
+ const text = wrapStrings === "all" ? safeSourceCode(context)?.text : void 0;
9206
9236
  for (const written of locations) {
9207
- const wrapsString = wrapStrings === "jsx" && isJsxAttributeString(written);
9208
- const fixable = written.node.type === "TemplateElement" || wrapsString;
9209
- const eol = wrapsString ? lineEndingOf(written) : "\n";
9237
+ const wrapsString = wrapStrings !== "never" && isJsxAttributeString(written);
9238
+ const convertsString = wrapStrings === "all" && !wrapsString && isConvertibleJsString(written, text?.slice(written.range[0], written.range[1]));
9239
+ const fixable = written.node.type === "TemplateElement" || wrapsString || convertsString;
9240
+ const eol = wrapsString || convertsString ? lineEndingOf(written) : "\n";
9210
9241
  const loc = eol === "\n" ? written : {
9211
9242
  ...written,
9212
9243
  value: written.value.replace(/\r\n/g, "\n")
9213
9244
  };
9214
9245
  const toSource = (value) => eol === "\n" ? value : value.replace(/\n/g, eol);
9246
+ const fixRange = convertsString ? loc.node.range : loc.range;
9247
+ const toFix = (value) => convertsString ? "`" + toSource(value) + "`" : toSource(value);
9215
9248
  let maxLine = 0;
9216
9249
  for (const line of loc.value.split("\n")) {
9217
9250
  if (line.length <= maxLine) continue;
@@ -9231,7 +9264,7 @@ const enforceConsistentLineWrapping = defineRule({
9231
9264
  messageId: maxLine > printWidth ? "tooLong" : "inconsistentWrapping",
9232
9265
  data,
9233
9266
  fix(fixer) {
9234
- return fixer.replaceTextRange(loc.range, toSource(fixedValue));
9267
+ return fixer.replaceTextRange(fixRange, toFix(fixedValue));
9235
9268
  }
9236
9269
  });
9237
9270
  } else if (maxLine > printWidth) context.report({
@@ -9258,7 +9291,7 @@ const enforceConsistentLineWrapping = defineRule({
9258
9291
  messageId: "tooManyPerLine",
9259
9292
  data,
9260
9293
  fix(fixer) {
9261
- return fixer.replaceTextRange(loc.range, toSource(preserveSpaces(loc, fixedValue)));
9294
+ return fixer.replaceTextRange(fixRange, toFix(preserveSpaces(loc, fixedValue)));
9262
9295
  }
9263
9296
  });
9264
9297
  } else context.report({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxlint-tailwindcss",
3
- "version": "1.15.1",
3
+ "version": "1.16.0",
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",