oxlint-tailwindcss 1.15.0 → 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
@@ -4781,16 +4781,49 @@ function toPersisted(r) {
4781
4781
  const WORKER_SCRIPT$2 = makeWorkerScript(`async (ds, request, env) => {
4782
4782
  const { classes, rem } = request;
4783
4783
  const options = rem ? { rem } : undefined;
4784
- const OWN_CLASS = /("(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*')|(^|[{};])(\\s*)\\.(?:\\\\[0-9a-fA-F]{1,6}\\s?|\\\\[^0-9a-fA-F\\s]|[\\w-])+/g;
4784
+ const escapeClass = (s) => {
4785
+ if (s === '-') return '\\\\-';
4786
+ let out = '';
4787
+ for (let i = 0; i < s.length; i++) {
4788
+ const c = s.charCodeAt(i);
4789
+ if (c === 0) out += '\\uFFFD';
4790
+ else if ((c >= 1 && c <= 31) || c === 127 || (c >= 48 && c <= 57 && (i === 0 || (i === 1 && s[0] === '-')))) {
4791
+ out += '\\\\' + c.toString(16) + ' ';
4792
+ } else if (c >= 128 || c === 45 || c === 95 || (c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122)) {
4793
+ out += s[i];
4794
+ } else {
4795
+ out += '\\\\' + s[i];
4796
+ }
4797
+ }
4798
+ return out;
4799
+ };
4800
+ const NAME_CHAR = /[\\w\\\\-]|[^\\x00-\\x7f]/;
4785
4801
  const rawOf = (d, cls) => {
4786
4802
  let out;
4787
4803
  try { out = d.candidatesToCss([cls]); } catch (e) { return null; }
4788
4804
  return out && out[0] ? out[0] : null;
4789
4805
  };
4790
- const own = (css) => css
4791
- .replace(OWN_CLASS, (m, str, start, ws) => (str !== undefined ? str : start + ws + '.__c'))
4792
- .replace(/\\s+/g, ' ')
4793
- .trim();
4806
+ const own = (css, cls) => {
4807
+ const token = '.' + escapeClass(cls);
4808
+ let out = '';
4809
+ let i = 0;
4810
+ while (i < css.length) {
4811
+ const ch = css[i];
4812
+ if (ch === '"' || ch === "'") {
4813
+ let j = i + 1;
4814
+ while (j < css.length && css[j] !== ch) j += css[j] === '\\\\' ? 2 : 1;
4815
+ out += css.slice(i, j + 1);
4816
+ i = j + 1;
4817
+ } else if (css.startsWith(token, i) && css[i - 1] !== '\\\\' && !NAME_CHAR.test(css[i + token.length] || ' ')) {
4818
+ out += '.__c';
4819
+ i += token.length;
4820
+ } else {
4821
+ out += ch;
4822
+ i++;
4823
+ }
4824
+ }
4825
+ return out.replace(/\\s+/g, ' ').trim();
4826
+ };
4794
4827
  // Declarations only, selectors and at-rule preludes dropped: equal for two
4795
4828
  // rules that set the same things on different selectors.
4796
4829
  const declarationsOf = (css) => css.replace(/[^{};]+\\{/g, '').replace(/\\}/g, '').replace(/\\s+/g, ' ').trim();
@@ -4857,14 +4890,14 @@ const WORKER_SCRIPT$2 = makeWorkerScript(`async (ds, request, env) => {
4857
4890
  if (canonical === cls) { results.push({ canonical: cls, safe: true }); continue; }
4858
4891
  const rawA = rawOf(ds, cls);
4859
4892
  const rawB = rawOf(ds, canonical);
4860
- const a = rawA === null ? null : own(rawA);
4861
- const b = rawB === null ? null : own(rawB);
4893
+ const a = rawA === null ? null : own(rawA, cls);
4894
+ const b = rawB === null ? null : own(rawB, canonical);
4862
4895
  if (a !== null && b !== null && a === b) { results.push({ canonical, safe: true }); continue; }
4863
4896
  if (a === null || b === null) { results.push({ canonical, safe: false }); continue; }
4864
4897
  const ma = stripMirrors(rawA);
4865
4898
  const mb = stripMirrors(rawB);
4866
- const sa = own(ma.css);
4867
- const sb = own(mb.css);
4899
+ const sa = own(ma.css, cls);
4900
+ const sb = own(mb.css, canonical);
4868
4901
  if (sa === sb) {
4869
4902
  // The same CSS once the mirrors are gone. It is 'variable' only when the
4870
4903
  // canonical form ADDS mirrors and drops none; any other way to get here
@@ -4884,7 +4917,7 @@ const WORKER_SCRIPT$2 = makeWorkerScript(`async (ds, request, env) => {
4884
4917
  try { stock = await env.loadStock(); } catch (e) {}
4885
4918
  const xa = stock && rawOf(stock, cls);
4886
4919
  const xb = stock && rawOf(stock, canonical);
4887
- const same = xa && xb && own(stripMirrors(xa).css) === own(stripMirrors(xb).css);
4920
+ const same = xa && xb && own(stripMirrors(xa).css, cls) === own(stripMirrors(xb).css, canonical);
4888
4921
  results.push({ canonical, safe: false, reason: same ? 'variant' : 'selector' });
4889
4922
  }
4890
4923
  return results;
@@ -8923,6 +8956,31 @@ function isJsxAttributeString(loc) {
8923
8956
  const node = loc.node;
8924
8957
  return node.type === "Literal" && node.parent?.type === "JSXAttribute";
8925
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
+ }
8926
8984
  /** One indentation level added below the statement's base indent for wrapped lines. */
8927
8985
  const INDENT_UNIT = " ";
8928
8986
  /** Group `classes` into chunks of at most `n`, each chunk space-joined. */
@@ -9006,7 +9064,7 @@ const enforceConsistentLineWrapping = defineRule({
9006
9064
  recommended: false,
9007
9065
  designSystem: "optional"
9008
9066
  }),
9009
- fixable: "whitespace",
9067
+ fixable: "code",
9010
9068
  schema: [{
9011
9069
  type: "object",
9012
9070
  properties: {
@@ -9027,7 +9085,11 @@ const enforceConsistentLineWrapping = defineRule({
9027
9085
  },
9028
9086
  wrapStrings: {
9029
9087
  type: "string",
9030
- enum: ["never", "jsx"]
9088
+ enum: [
9089
+ "never",
9090
+ "jsx",
9091
+ "all"
9092
+ ]
9031
9093
  }
9032
9094
  },
9033
9095
  additionalProperties: false
@@ -9069,10 +9131,10 @@ const enforceConsistentLineWrapping = defineRule({
9069
9131
  return "";
9070
9132
  }
9071
9133
  /**
9072
- * The line ending a JSX string's fix writes. A JSX attribute keeps the
9073
- * file's `\r\n` in its value (a template's is LF already), so a CRLF file
9074
- * gets CRLF breaks: from the value when it has any, else from the line the
9075
- * 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.
9076
9138
  */
9077
9139
  function lineEndingOf(loc) {
9078
9140
  if (loc.value.includes("\r\n")) return "\r\n";
@@ -9167,15 +9229,19 @@ const enforceConsistentLineWrapping = defineRule({
9167
9229
  const group = getGroup();
9168
9230
  const prefix = wrapLines === "all" && group !== "never" && classesPerLine === void 0 ? softGetDS(getDS)?.cache.prefix ?? "" : "";
9169
9231
  const wrapStrings = getWrapStrings();
9232
+ const text = wrapStrings === "all" ? safeSourceCode(context)?.text : void 0;
9170
9233
  for (const written of locations) {
9171
- const wrapsString = wrapStrings === "jsx" && isJsxAttributeString(written);
9172
- const fixable = written.node.type === "TemplateElement" || wrapsString;
9173
- 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";
9174
9238
  const loc = eol === "\n" ? written : {
9175
9239
  ...written,
9176
9240
  value: written.value.replace(/\r\n/g, "\n")
9177
9241
  };
9178
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);
9179
9245
  let maxLine = 0;
9180
9246
  for (const line of loc.value.split("\n")) {
9181
9247
  if (line.length <= maxLine) continue;
@@ -9195,7 +9261,7 @@ const enforceConsistentLineWrapping = defineRule({
9195
9261
  messageId: maxLine > printWidth ? "tooLong" : "inconsistentWrapping",
9196
9262
  data,
9197
9263
  fix(fixer) {
9198
- return fixer.replaceTextRange(loc.range, toSource(fixedValue));
9264
+ return fixer.replaceTextRange(fixRange, toFix(fixedValue));
9199
9265
  }
9200
9266
  });
9201
9267
  } else if (maxLine > printWidth) context.report({
@@ -9222,7 +9288,7 @@ const enforceConsistentLineWrapping = defineRule({
9222
9288
  messageId: "tooManyPerLine",
9223
9289
  data,
9224
9290
  fix(fixer) {
9225
- return fixer.replaceTextRange(loc.range, toSource(preserveSpaces(loc, fixedValue)));
9291
+ return fixer.replaceTextRange(fixRange, toFix(preserveSpaces(loc, fixedValue)));
9226
9292
  }
9227
9293
  });
9228
9294
  } else context.report({
package/dist/index.mjs CHANGED
@@ -4784,16 +4784,49 @@ function toPersisted(r) {
4784
4784
  const WORKER_SCRIPT$2 = makeWorkerScript(`async (ds, request, env) => {
4785
4785
  const { classes, rem } = request;
4786
4786
  const options = rem ? { rem } : undefined;
4787
- const OWN_CLASS = /("(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*')|(^|[{};])(\\s*)\\.(?:\\\\[0-9a-fA-F]{1,6}\\s?|\\\\[^0-9a-fA-F\\s]|[\\w-])+/g;
4787
+ const escapeClass = (s) => {
4788
+ if (s === '-') return '\\\\-';
4789
+ let out = '';
4790
+ for (let i = 0; i < s.length; i++) {
4791
+ const c = s.charCodeAt(i);
4792
+ if (c === 0) out += '\\uFFFD';
4793
+ else if ((c >= 1 && c <= 31) || c === 127 || (c >= 48 && c <= 57 && (i === 0 || (i === 1 && s[0] === '-')))) {
4794
+ out += '\\\\' + c.toString(16) + ' ';
4795
+ } else if (c >= 128 || c === 45 || c === 95 || (c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122)) {
4796
+ out += s[i];
4797
+ } else {
4798
+ out += '\\\\' + s[i];
4799
+ }
4800
+ }
4801
+ return out;
4802
+ };
4803
+ const NAME_CHAR = /[\\w\\\\-]|[^\\x00-\\x7f]/;
4788
4804
  const rawOf = (d, cls) => {
4789
4805
  let out;
4790
4806
  try { out = d.candidatesToCss([cls]); } catch (e) { return null; }
4791
4807
  return out && out[0] ? out[0] : null;
4792
4808
  };
4793
- const own = (css) => css
4794
- .replace(OWN_CLASS, (m, str, start, ws) => (str !== undefined ? str : start + ws + '.__c'))
4795
- .replace(/\\s+/g, ' ')
4796
- .trim();
4809
+ const own = (css, cls) => {
4810
+ const token = '.' + escapeClass(cls);
4811
+ let out = '';
4812
+ let i = 0;
4813
+ while (i < css.length) {
4814
+ const ch = css[i];
4815
+ if (ch === '"' || ch === "'") {
4816
+ let j = i + 1;
4817
+ while (j < css.length && css[j] !== ch) j += css[j] === '\\\\' ? 2 : 1;
4818
+ out += css.slice(i, j + 1);
4819
+ i = j + 1;
4820
+ } else if (css.startsWith(token, i) && css[i - 1] !== '\\\\' && !NAME_CHAR.test(css[i + token.length] || ' ')) {
4821
+ out += '.__c';
4822
+ i += token.length;
4823
+ } else {
4824
+ out += ch;
4825
+ i++;
4826
+ }
4827
+ }
4828
+ return out.replace(/\\s+/g, ' ').trim();
4829
+ };
4797
4830
  // Declarations only, selectors and at-rule preludes dropped: equal for two
4798
4831
  // rules that set the same things on different selectors.
4799
4832
  const declarationsOf = (css) => css.replace(/[^{};]+\\{/g, '').replace(/\\}/g, '').replace(/\\s+/g, ' ').trim();
@@ -4860,14 +4893,14 @@ const WORKER_SCRIPT$2 = makeWorkerScript(`async (ds, request, env) => {
4860
4893
  if (canonical === cls) { results.push({ canonical: cls, safe: true }); continue; }
4861
4894
  const rawA = rawOf(ds, cls);
4862
4895
  const rawB = rawOf(ds, canonical);
4863
- const a = rawA === null ? null : own(rawA);
4864
- const b = rawB === null ? null : own(rawB);
4896
+ const a = rawA === null ? null : own(rawA, cls);
4897
+ const b = rawB === null ? null : own(rawB, canonical);
4865
4898
  if (a !== null && b !== null && a === b) { results.push({ canonical, safe: true }); continue; }
4866
4899
  if (a === null || b === null) { results.push({ canonical, safe: false }); continue; }
4867
4900
  const ma = stripMirrors(rawA);
4868
4901
  const mb = stripMirrors(rawB);
4869
- const sa = own(ma.css);
4870
- const sb = own(mb.css);
4902
+ const sa = own(ma.css, cls);
4903
+ const sb = own(mb.css, canonical);
4871
4904
  if (sa === sb) {
4872
4905
  // The same CSS once the mirrors are gone. It is 'variable' only when the
4873
4906
  // canonical form ADDS mirrors and drops none; any other way to get here
@@ -4887,7 +4920,7 @@ const WORKER_SCRIPT$2 = makeWorkerScript(`async (ds, request, env) => {
4887
4920
  try { stock = await env.loadStock(); } catch (e) {}
4888
4921
  const xa = stock && rawOf(stock, cls);
4889
4922
  const xb = stock && rawOf(stock, canonical);
4890
- const same = xa && xb && own(stripMirrors(xa).css) === own(stripMirrors(xb).css);
4923
+ const same = xa && xb && own(stripMirrors(xa).css, cls) === own(stripMirrors(xb).css, canonical);
4891
4924
  results.push({ canonical, safe: false, reason: same ? 'variant' : 'selector' });
4892
4925
  }
4893
4926
  return results;
@@ -8926,6 +8959,31 @@ function isJsxAttributeString(loc) {
8926
8959
  const node = loc.node;
8927
8960
  return node.type === "Literal" && node.parent?.type === "JSXAttribute";
8928
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
+ }
8929
8987
  /** One indentation level added below the statement's base indent for wrapped lines. */
8930
8988
  const INDENT_UNIT = " ";
8931
8989
  /** Group `classes` into chunks of at most `n`, each chunk space-joined. */
@@ -9009,7 +9067,7 @@ const enforceConsistentLineWrapping = defineRule({
9009
9067
  recommended: false,
9010
9068
  designSystem: "optional"
9011
9069
  }),
9012
- fixable: "whitespace",
9070
+ fixable: "code",
9013
9071
  schema: [{
9014
9072
  type: "object",
9015
9073
  properties: {
@@ -9030,7 +9088,11 @@ const enforceConsistentLineWrapping = defineRule({
9030
9088
  },
9031
9089
  wrapStrings: {
9032
9090
  type: "string",
9033
- enum: ["never", "jsx"]
9091
+ enum: [
9092
+ "never",
9093
+ "jsx",
9094
+ "all"
9095
+ ]
9034
9096
  }
9035
9097
  },
9036
9098
  additionalProperties: false
@@ -9072,10 +9134,10 @@ const enforceConsistentLineWrapping = defineRule({
9072
9134
  return "";
9073
9135
  }
9074
9136
  /**
9075
- * The line ending a JSX string's fix writes. A JSX attribute keeps the
9076
- * file's `\r\n` in its value (a template's is LF already), so a CRLF file
9077
- * gets CRLF breaks: from the value when it has any, else from the line the
9078
- * 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.
9079
9141
  */
9080
9142
  function lineEndingOf(loc) {
9081
9143
  if (loc.value.includes("\r\n")) return "\r\n";
@@ -9170,15 +9232,19 @@ const enforceConsistentLineWrapping = defineRule({
9170
9232
  const group = getGroup();
9171
9233
  const prefix = wrapLines === "all" && group !== "never" && classesPerLine === void 0 ? softGetDS(getDS)?.cache.prefix ?? "" : "";
9172
9234
  const wrapStrings = getWrapStrings();
9235
+ const text = wrapStrings === "all" ? safeSourceCode(context)?.text : void 0;
9173
9236
  for (const written of locations) {
9174
- const wrapsString = wrapStrings === "jsx" && isJsxAttributeString(written);
9175
- const fixable = written.node.type === "TemplateElement" || wrapsString;
9176
- 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";
9177
9241
  const loc = eol === "\n" ? written : {
9178
9242
  ...written,
9179
9243
  value: written.value.replace(/\r\n/g, "\n")
9180
9244
  };
9181
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);
9182
9248
  let maxLine = 0;
9183
9249
  for (const line of loc.value.split("\n")) {
9184
9250
  if (line.length <= maxLine) continue;
@@ -9198,7 +9264,7 @@ const enforceConsistentLineWrapping = defineRule({
9198
9264
  messageId: maxLine > printWidth ? "tooLong" : "inconsistentWrapping",
9199
9265
  data,
9200
9266
  fix(fixer) {
9201
- return fixer.replaceTextRange(loc.range, toSource(fixedValue));
9267
+ return fixer.replaceTextRange(fixRange, toFix(fixedValue));
9202
9268
  }
9203
9269
  });
9204
9270
  } else if (maxLine > printWidth) context.report({
@@ -9225,7 +9291,7 @@ const enforceConsistentLineWrapping = defineRule({
9225
9291
  messageId: "tooManyPerLine",
9226
9292
  data,
9227
9293
  fix(fixer) {
9228
- return fixer.replaceTextRange(loc.range, toSource(preserveSpaces(loc, fixedValue)));
9294
+ return fixer.replaceTextRange(fixRange, toFix(preserveSpaces(loc, fixedValue)));
9229
9295
  }
9230
9296
  });
9231
9297
  } else context.report({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxlint-tailwindcss",
3
- "version": "1.15.0",
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",