oxlint-tailwindcss 0.1.9 → 0.1.10

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/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  22 Tailwind CSS linting rules for [oxlint](https://oxc.rs/docs/guide/usage/linter). Built for Tailwind CSS v4 with zero-config auto-detection, typo suggestions, and autofixes.
4
4
 
5
+ Read the story behind this plugin: [oxlint-tailwindcss: The Linting Plugin Tailwind v4 Needed](https://sergioazocar.com/en/blog/oxlint-tailwindcss-the-linting-plugin-tailwind-v4-needed)
6
+
5
7
  ## Highlights
6
8
 
7
9
  - **Zero config** — Auto-detects your Tailwind CSS entry point. Works out of the box.
package/dist/index.cjs CHANGED
@@ -864,18 +864,93 @@ async function main() {
864
864
  if (val !== null) order[name] = val.toString();
865
865
  }
866
866
 
867
- // CSS properties per class — extract only from the class rule block, skip @property descriptors
867
+ // CSS properties per class — extract only from the ROOT selector, not descendant selectors.
868
+ // Plugin classes like "prose" generate CSS for both the root element (.prose { color: ...; })
869
+ // and descendant selectors (:where(.prose pre) { overflow-x: auto; }).
870
+ // Only root-level properties should be used for conflict detection.
868
871
  const cssProps = {};
869
872
  const atPropertyDescriptors = new Set(['syntax', 'inherits', 'initial-value']);
870
- const propRegex = /^\\s+([\\w-]+)\\s*:/gm;
871
- for (let i = 0; i < classNames.length; i++) {
872
- if (cssResults[i]) {
873
+
874
+ function extractRootCssProps(cssText, className) {
875
+ const rootProps = [];
876
+ const allProps = [];
877
+ // CSS-escape special chars in class name for selector matching
878
+ const escapedName = className.replace(/([^\\w-])/g, '\\\\$1');
879
+ const classSelector = '.' + escapedName;
880
+ const rawSelector = '.' + className;
881
+ const propRe = /^\\s+([\\w-]+)\\s*:/gm;
882
+
883
+ function isRoot(sel) {
884
+ for (const s of [classSelector, rawSelector]) {
885
+ if (sel === s) return true;
886
+ if (sel.length > s.length && sel.startsWith(s) && sel[s.length] === ':') return true;
887
+ }
888
+ return false;
889
+ }
890
+
891
+ // Extract only top-level declarations from a block body (skip nested blocks).
892
+ // For CSS nesting like .prose { color: ...; :where(a) { color: ...; } },
893
+ // only extracts "color" from the top level, not from the nested :where(a) block.
894
+ function extractTopLevelProps(body) {
873
895
  const props = [];
874
- let match;
875
- propRegex.lastIndex = 0;
876
- while ((match = propRegex.exec(cssResults[i])) !== null) {
877
- if (!atPropertyDescriptors.has(match[1])) props.push(match[1]);
896
+ let depth = 0;
897
+ let lineStart = 0;
898
+ for (let i = 0; i <= body.length; i++) {
899
+ if (i === body.length || body[i] === '\\n') {
900
+ if (depth === 0) {
901
+ const line = body.slice(lineStart, i);
902
+ const m = /^\\s+([\\w-]+)\\s*:/.exec(line);
903
+ if (m && !atPropertyDescriptors.has(m[1])) props.push(m[1]);
904
+ }
905
+ lineStart = i + 1;
906
+ } else if (body[i] === '{') {
907
+ depth++;
908
+ } else if (body[i] === '}') {
909
+ depth--;
910
+ }
878
911
  }
912
+ return props;
913
+ }
914
+
915
+ function processText(text) {
916
+ let i = 0;
917
+ while (i < text.length) {
918
+ while (i < text.length && /\\s/.test(text[i])) i++;
919
+ if (i >= text.length) break;
920
+ const braceIdx = text.indexOf('{', i);
921
+ if (braceIdx === -1) break;
922
+ const selector = text.slice(i, braceIdx).trim();
923
+ let depth = 1, j = braceIdx + 1;
924
+ while (j < text.length && depth > 0) {
925
+ if (text[j] === '{') depth++;
926
+ if (text[j] === '}') depth--;
927
+ j++;
928
+ }
929
+ const body = text.slice(braceIdx + 1, j - 1);
930
+ if (selector.startsWith('@media') || selector.startsWith('@supports') || selector.startsWith('@layer')) {
931
+ processText(body);
932
+ } else if (!selector.startsWith('@')) {
933
+ propRe.lastIndex = 0;
934
+ let m;
935
+ while ((m = propRe.exec(body)) !== null) {
936
+ if (!atPropertyDescriptors.has(m[1])) allProps.push(m[1]);
937
+ }
938
+ if (isRoot(selector)) rootProps.push(...extractTopLevelProps(body));
939
+ }
940
+ i = j;
941
+ }
942
+ }
943
+
944
+ processText(cssText);
945
+ // Use root-only properties when found; fall back to all for classes with
946
+ // escaped selectors or single-block output where root matching may miss.
947
+ const result = rootProps.length > 0 ? rootProps : allProps;
948
+ return [...new Set(result)];
949
+ }
950
+
951
+ for (let i = 0; i < classNames.length; i++) {
952
+ if (cssResults[i]) {
953
+ const props = extractRootCssProps(cssResults[i], classNames[i]);
879
954
  if (props.length > 0) cssProps[classNames[i]] = props;
880
955
  }
881
956
  }
@@ -892,6 +967,20 @@ async function main() {
892
967
  // Component classes from @layer components
893
968
  const componentClasses = extractComponentClasses(cssPath, base);
894
969
 
970
+ // Extract class names from attribute selectors [class~="..."] in CSS output.
971
+ // Plugins like @tailwindcss/typography use these for modifier classes (e.g. "not-prose")
972
+ // that don't generate their own CSS but are referenced in other classes' selectors.
973
+ const attrClassRe = /\\[class~="([^"]+)"\\]/g;
974
+ for (let i = 0; i < cssResults.length; i++) {
975
+ if (cssResults[i]) {
976
+ let acm;
977
+ attrClassRe.lastIndex = 0;
978
+ while ((acm = attrClassRe.exec(cssResults[i])) !== null) {
979
+ componentClasses.push(acm[1]);
980
+ }
981
+ }
982
+ }
983
+
895
984
  // Arbitrary equivalents: map arbitrary forms to named equivalents
896
985
  const arbitraryEquivalents = {};
897
986
  const candidates = [];
@@ -930,7 +1019,7 @@ async function main() {
930
1019
  main().catch(e => { process.stderr.write(e.message); process.exit(1); });
931
1020
  `;
932
1021
  const CACHE_DIR = (0, node_path.join)((0, node_os.tmpdir)(), "oxlint-tailwindcss");
933
- const CACHE_VERSION = 8;
1022
+ const CACHE_VERSION = 10;
934
1023
  function getCachePath(cssPath, mtime) {
935
1024
  return (0, node_path.join)(CACHE_DIR, `${(0, node_crypto.createHash)("md5").update(`v${CACHE_VERSION}:${cssPath}:${mtime}`).digest("hex")}.json`);
936
1025
  }
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import * as _oxlint_plugins0 from "@oxlint/plugins";
1
+ import * as _$_oxlint_plugins0 from "@oxlint/plugins";
2
2
 
3
3
  //#region src/index.d.ts
4
- declare const plugin: _oxlint_plugins0.Plugin;
4
+ declare const plugin: _$_oxlint_plugins0.Plugin;
5
5
  export = plugin;
6
6
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAwBM,MAAA,EA0BJ,gBAAA,CA1BU,MAAA;AAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAwBM,MAAA,EA0BJ,kBAAA,CA1BU,MAAA;AAAA"}
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import * as _oxlint_plugins0 from "@oxlint/plugins";
1
+ import * as _$_oxlint_plugins0 from "@oxlint/plugins";
2
2
 
3
3
  //#region src/index.d.ts
4
- declare const plugin: _oxlint_plugins0.Plugin;
4
+ declare const plugin: _$_oxlint_plugins0.Plugin;
5
5
  //#endregion
6
6
  export { plugin as default };
7
7
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAwBM,MAAA,EA0BJ,gBAAA,CA1BU,MAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAwBM,MAAA,EA0BJ,kBAAA,CA1BU,MAAA"}
package/dist/index.mjs CHANGED
@@ -868,18 +868,93 @@ async function main() {
868
868
  if (val !== null) order[name] = val.toString();
869
869
  }
870
870
 
871
- // CSS properties per class — extract only from the class rule block, skip @property descriptors
871
+ // CSS properties per class — extract only from the ROOT selector, not descendant selectors.
872
+ // Plugin classes like "prose" generate CSS for both the root element (.prose { color: ...; })
873
+ // and descendant selectors (:where(.prose pre) { overflow-x: auto; }).
874
+ // Only root-level properties should be used for conflict detection.
872
875
  const cssProps = {};
873
876
  const atPropertyDescriptors = new Set(['syntax', 'inherits', 'initial-value']);
874
- const propRegex = /^\\s+([\\w-]+)\\s*:/gm;
875
- for (let i = 0; i < classNames.length; i++) {
876
- if (cssResults[i]) {
877
+
878
+ function extractRootCssProps(cssText, className) {
879
+ const rootProps = [];
880
+ const allProps = [];
881
+ // CSS-escape special chars in class name for selector matching
882
+ const escapedName = className.replace(/([^\\w-])/g, '\\\\$1');
883
+ const classSelector = '.' + escapedName;
884
+ const rawSelector = '.' + className;
885
+ const propRe = /^\\s+([\\w-]+)\\s*:/gm;
886
+
887
+ function isRoot(sel) {
888
+ for (const s of [classSelector, rawSelector]) {
889
+ if (sel === s) return true;
890
+ if (sel.length > s.length && sel.startsWith(s) && sel[s.length] === ':') return true;
891
+ }
892
+ return false;
893
+ }
894
+
895
+ // Extract only top-level declarations from a block body (skip nested blocks).
896
+ // For CSS nesting like .prose { color: ...; :where(a) { color: ...; } },
897
+ // only extracts "color" from the top level, not from the nested :where(a) block.
898
+ function extractTopLevelProps(body) {
877
899
  const props = [];
878
- let match;
879
- propRegex.lastIndex = 0;
880
- while ((match = propRegex.exec(cssResults[i])) !== null) {
881
- if (!atPropertyDescriptors.has(match[1])) props.push(match[1]);
900
+ let depth = 0;
901
+ let lineStart = 0;
902
+ for (let i = 0; i <= body.length; i++) {
903
+ if (i === body.length || body[i] === '\\n') {
904
+ if (depth === 0) {
905
+ const line = body.slice(lineStart, i);
906
+ const m = /^\\s+([\\w-]+)\\s*:/.exec(line);
907
+ if (m && !atPropertyDescriptors.has(m[1])) props.push(m[1]);
908
+ }
909
+ lineStart = i + 1;
910
+ } else if (body[i] === '{') {
911
+ depth++;
912
+ } else if (body[i] === '}') {
913
+ depth--;
914
+ }
882
915
  }
916
+ return props;
917
+ }
918
+
919
+ function processText(text) {
920
+ let i = 0;
921
+ while (i < text.length) {
922
+ while (i < text.length && /\\s/.test(text[i])) i++;
923
+ if (i >= text.length) break;
924
+ const braceIdx = text.indexOf('{', i);
925
+ if (braceIdx === -1) break;
926
+ const selector = text.slice(i, braceIdx).trim();
927
+ let depth = 1, j = braceIdx + 1;
928
+ while (j < text.length && depth > 0) {
929
+ if (text[j] === '{') depth++;
930
+ if (text[j] === '}') depth--;
931
+ j++;
932
+ }
933
+ const body = text.slice(braceIdx + 1, j - 1);
934
+ if (selector.startsWith('@media') || selector.startsWith('@supports') || selector.startsWith('@layer')) {
935
+ processText(body);
936
+ } else if (!selector.startsWith('@')) {
937
+ propRe.lastIndex = 0;
938
+ let m;
939
+ while ((m = propRe.exec(body)) !== null) {
940
+ if (!atPropertyDescriptors.has(m[1])) allProps.push(m[1]);
941
+ }
942
+ if (isRoot(selector)) rootProps.push(...extractTopLevelProps(body));
943
+ }
944
+ i = j;
945
+ }
946
+ }
947
+
948
+ processText(cssText);
949
+ // Use root-only properties when found; fall back to all for classes with
950
+ // escaped selectors or single-block output where root matching may miss.
951
+ const result = rootProps.length > 0 ? rootProps : allProps;
952
+ return [...new Set(result)];
953
+ }
954
+
955
+ for (let i = 0; i < classNames.length; i++) {
956
+ if (cssResults[i]) {
957
+ const props = extractRootCssProps(cssResults[i], classNames[i]);
883
958
  if (props.length > 0) cssProps[classNames[i]] = props;
884
959
  }
885
960
  }
@@ -896,6 +971,20 @@ async function main() {
896
971
  // Component classes from @layer components
897
972
  const componentClasses = extractComponentClasses(cssPath, base);
898
973
 
974
+ // Extract class names from attribute selectors [class~="..."] in CSS output.
975
+ // Plugins like @tailwindcss/typography use these for modifier classes (e.g. "not-prose")
976
+ // that don't generate their own CSS but are referenced in other classes' selectors.
977
+ const attrClassRe = /\\[class~="([^"]+)"\\]/g;
978
+ for (let i = 0; i < cssResults.length; i++) {
979
+ if (cssResults[i]) {
980
+ let acm;
981
+ attrClassRe.lastIndex = 0;
982
+ while ((acm = attrClassRe.exec(cssResults[i])) !== null) {
983
+ componentClasses.push(acm[1]);
984
+ }
985
+ }
986
+ }
987
+
899
988
  // Arbitrary equivalents: map arbitrary forms to named equivalents
900
989
  const arbitraryEquivalents = {};
901
990
  const candidates = [];
@@ -934,7 +1023,7 @@ async function main() {
934
1023
  main().catch(e => { process.stderr.write(e.message); process.exit(1); });
935
1024
  `;
936
1025
  const CACHE_DIR = join(tmpdir(), "oxlint-tailwindcss");
937
- const CACHE_VERSION = 8;
1026
+ const CACHE_VERSION = 10;
938
1027
  function getCachePath(cssPath, mtime) {
939
1028
  return join(CACHE_DIR, `${createHash("md5").update(`v${CACHE_VERSION}:${cssPath}:${mtime}`).digest("hex")}.json`);
940
1029
  }