oxlint-tailwindcss 1.3.0 → 1.3.2

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
@@ -125,7 +125,9 @@ order:
125
125
  ```
126
126
 
127
127
  **Pattern B — one `.oxlintrc.json` per package**, each with its own string `entryPoint`. oxlint
128
- resolves the closest config to the file being linted.
128
+ resolves the closest config to the file being linted, and a relative `entryPoint` is anchored to
129
+ that config's directory (falling back to the working directory), so it resolves to the same CSS
130
+ whether oxlint runs from the package (CLI) or the workspace root (editor).
129
131
 
130
132
  See the full [monorepo guide](https://oxlint-tailwindcss.pages.dev/monorepo) for examples of both.
131
133
 
@@ -930,10 +932,10 @@ The class parser correctly handles:
930
932
 
931
933
  - **`enforce-canonical`**: Named classes are canonicalized via the precomputed map (covers
932
934
  everything in `getClassList()` plus a curated list of legacy v3 spellings like `break-words`,
933
- `flex-grow`, `start-N`, `bg-gradient-to-*`). Arbitrary/CSS-var forms (`p-[2px]`, `bg-(--c)`) are
934
- canonicalized dynamically via the worker. Some valid v4 classes that don't appear in
935
- `getClassList()` and have no canonical rewrite (e.g. `border-1` is valid as a dynamic numeric
936
- value but isn't enumerated) are left untouched.
935
+ `flex-grow`, `start-N`, `bg-gradient-to-*`, `bg-left-top` → `bg-top-left`). Arbitrary/CSS-var
936
+ forms (`p-[2px]`, `bg-(--c)`) are canonicalized dynamically via the worker. Some valid v4 classes
937
+ that don't appear in `getClassList()` and have no canonical rewrite (e.g. `border-1` is valid as a
938
+ dynamic numeric value but isn't enumerated) are left untouched.
937
939
  - **`no-conflicting-classes`**: Uses exact CSS property name matching plus composition heuristics:
938
940
  CSS-var composition (`shadow` + `ring`), narrowing-override (later class is a strict subset of
939
941
  earlier — handles `size-4 h-6`, `rounded-t-lg rounded-tl-sm`, `truncate text-clip`), complementary
package/dist/index.cjs CHANGED
@@ -1309,6 +1309,39 @@ async function main() {
1309
1309
  const dash = cls.lastIndexOf('-');
1310
1310
  if (dash > 0) knownPrefixes.add(cls.slice(0, dash));
1311
1311
  }
1312
+ // Curated static utilities valid in v4 but absent from getClassList() (#37).
1313
+ // These are special-cased in Tailwind's compiler, so they appear in neither
1314
+ // getClassList() NOR the utility registry (\`utilities.keys('static')\`) — only
1315
+ // an explicit probe surfaces them:
1316
+ // - \`@container-size\` (\`container-type: size\`) — sibling of the enumerated
1317
+ // \`@container\` / \`@container-normal\`; was flagged as a typo of \`contain-size\`.
1318
+ // - \`filter-none\` / \`backdrop-filter-none\` (\`filter: none\`) — the reset
1319
+ // utilities; their functional bases enumerate values but omit \`none\`.
1320
+ // - \`max-w-screen\` (\`max-width: 100vw\`).
1321
+ // Validated via candidatesToCss (self-prunes on any Tailwind version that doesn't
1322
+ // emit them) and their CSS is captured so the cssProps phase below treats them
1323
+ // exactly like their getClassList siblings — otherwise no-conflicting-classes
1324
+ // would flag \`@container @container-normal\` but silently accept
1325
+ // \`@container @container-size\`. Named forms (\`@container-size/main\`) are covered
1326
+ // by the slash-modifier path in cache.isValid once the base lands in validClasses.
1327
+ const staticExtras = [
1328
+ '@container-size',
1329
+ 'filter-none',
1330
+ 'backdrop-filter-none',
1331
+ 'max-w-screen',
1332
+ ].filter((c) => !validSet.has(c));
1333
+ const staticExtraCss = {};
1334
+ if (staticExtras.length > 0) {
1335
+ const staticResults = ds.candidatesToCss(staticExtras.map(pfx));
1336
+ for (let i = 0; i < staticExtras.length; i++) {
1337
+ if (staticResults[i] != null) {
1338
+ validClasses.push(staticExtras[i]);
1339
+ validSet.add(staticExtras[i]);
1340
+ staticExtraCss[staticExtras[i]] = staticResults[i];
1341
+ }
1342
+ }
1343
+ }
1344
+
1312
1345
  const extraCandidates = [];
1313
1346
  const breakpoints = ['sm', 'md', 'lg', 'xl', '2xl'];
1314
1347
  for (const prefix of knownPrefixes) {
@@ -1330,6 +1363,27 @@ async function main() {
1330
1363
  }
1331
1364
  }
1332
1365
 
1366
+ // Negative variants of utilities that support them (#37). getClassList()
1367
+ // enumerates negatives for most (\`-m-4\`, \`-translate-x-2\`) but omits a few
1368
+ // (\`-col-1\`, \`-row-1\`, \`-hue-rotate-45\`, \`-backdrop-hue-rotate-45\`). Probe
1369
+ // \`-<prefix>-1\` for every known prefix lacking negative coverage; candidatesToCss
1370
+ // self-prunes utilities that reject negatives (\`-p-1\` → null), so only genuinely
1371
+ // negative-capable prefixes land in validClasses, giving isValid's / getOrder's
1372
+ // numeric-prefix heuristic the \`-<prefix>\` it needs to accept any \`-<prefix>-<n>\`.
1373
+ const negativeProbes = [];
1374
+ for (const prefix of knownPrefixes) {
1375
+ if (!knownPrefixes.has('-' + prefix)) negativeProbes.push('-' + prefix + '-1');
1376
+ }
1377
+ if (negativeProbes.length > 0) {
1378
+ const negResults = ds.candidatesToCss(negativeProbes.map(pfx));
1379
+ for (let i = 0; i < negativeProbes.length; i++) {
1380
+ if (negResults[i] != null && !validSet.has(negativeProbes[i])) {
1381
+ validClasses.push(negativeProbes[i]);
1382
+ validSet.add(negativeProbes[i]);
1383
+ }
1384
+ }
1385
+ }
1386
+
1333
1387
  // Marker classes: group/peer don't produce CSS but enable group-hover:/peer-checked: variants
1334
1388
  const allVariants = ds.getVariants();
1335
1389
  for (const v of allVariants) {
@@ -1376,6 +1430,11 @@ async function main() {
1376
1430
  'decoration-clone', 'decoration-slice',
1377
1431
  'bg-gradient-to-t', 'bg-gradient-to-tr', 'bg-gradient-to-r', 'bg-gradient-to-br',
1378
1432
  'bg-gradient-to-b', 'bg-gradient-to-bl', 'bg-gradient-to-l', 'bg-gradient-to-tl',
1433
+ // v3 background/object-position spellings reordered in v4 (#37):
1434
+ // \`bg-left-top\` -> \`bg-top-left\`. canonicalizeCandidates rewrites them, so
1435
+ // enforce-canonical suggests the v4 form and no-unknown-classes accepts them.
1436
+ 'bg-left-top', 'bg-right-top', 'bg-left-bottom', 'bg-right-bottom',
1437
+ 'object-left-top', 'object-right-top', 'object-left-bottom', 'object-right-bottom',
1379
1438
  ];
1380
1439
  for (const cls of validClasses) {
1381
1440
  if (cls.startsWith('inset-s-')) legacyCandidates.push('start-' + cls.slice(8));
@@ -1504,6 +1563,14 @@ async function main() {
1504
1563
  }
1505
1564
  }
1506
1565
 
1566
+ // cssProps for the curated static extras (#37) so they participate in conflict
1567
+ // detection exactly like their getClassList siblings (e.g. \`@container-size\` and
1568
+ // \`@container\` both declaring \`container-type\`).
1569
+ for (const name in staticExtraCss) {
1570
+ const props = extractRootCssProps(staticExtraCss[name], pfx(name));
1571
+ if (props.length > 0) cssProps[name] = props;
1572
+ }
1573
+
1507
1574
  // Variant ordering from the design system
1508
1575
  const variantOrder = {};
1509
1576
  const variants = ds.getVariants();
@@ -1924,6 +1991,19 @@ function safeFilename(context) {
1924
1991
  }
1925
1992
  }
1926
1993
  /**
1994
+ * Safely read `context.cwd`, falling back to `process.cwd()`. Same try/catch
1995
+ * pattern as the other accessors (the getter throws in `createOnce` on older
1996
+ * oxlint). The fallback keeps relative-path resolution working even when the
1997
+ * linter never populates `cwd`.
1998
+ */
1999
+ function safeCwd(context) {
2000
+ try {
2001
+ return context.cwd ?? process.cwd();
2002
+ } catch {
2003
+ return process.cwd();
2004
+ }
2005
+ }
2006
+ /**
1927
2007
  * Lazily memoize a compiled options object across visitor calls.
1928
2008
  *
1929
2009
  * Every rule with options reinvents:
@@ -2039,6 +2119,76 @@ function resolveByGlobMapping(mappings, filePath, baseDir) {
2039
2119
  return null;
2040
2120
  }
2041
2121
  /**
2122
+ * oxlint discovers nested configuration by walking up from each linted file
2123
+ * looking for files with these names. We mirror that walk to find the config
2124
+ * directory a relative `entryPoint` should be anchored to.
2125
+ */
2126
+ const OXLINT_CONFIG_NAMES = [".oxlintrc.json"];
2127
+ /** Memoizes the nearest-config walk per starting directory (cleared in tests). */
2128
+ const nearestConfigDirCache = /* @__PURE__ */ new Map();
2129
+ /**
2130
+ * Find the directory of the **nearest** enclosing oxlint config, walking up
2131
+ * from `filePath` toward the filesystem root. Returns `undefined` if none is
2132
+ * found. This is the config oxlint applies to the file under its default
2133
+ * nested-config discovery, so a relative `entryPoint` declared in it is meant
2134
+ * to resolve relative to that directory — not the process CWD, which differs
2135
+ * between the CLI (`cd package && oxlint`) and an editor (CWD = workspace
2136
+ * root). See issue #39.
2137
+ *
2138
+ * Stops at the first match (early exit), so in the common case it touches only
2139
+ * the file's package, not the whole path to root.
2140
+ */
2141
+ function nearestConfigDir(filePath) {
2142
+ const start = (0, node_path.dirname)((0, node_path.resolve)(filePath));
2143
+ const cached = nearestConfigDirCache.get(start);
2144
+ if (cached !== void 0) return cached ?? void 0;
2145
+ let dir = start;
2146
+ for (;;) {
2147
+ if (OXLINT_CONFIG_NAMES.some((name) => (0, node_fs.existsSync)((0, node_path.resolve)(dir, name)))) {
2148
+ nearestConfigDirCache.set(start, dir);
2149
+ return dir;
2150
+ }
2151
+ const parent = (0, node_path.dirname)(dir);
2152
+ if (parent === dir) break;
2153
+ dir = parent;
2154
+ }
2155
+ nearestConfigDirCache.set(start, null);
2156
+ }
2157
+ /**
2158
+ * Resolve a string `entryPoint` (from `settings` or a rule option) to an
2159
+ * absolute path.
2160
+ *
2161
+ * Absolute paths are returned normalized and untouched. A **relative** path is
2162
+ * anchored to the directory of the nearest enclosing `.oxlintrc.json` (the
2163
+ * config oxlint applies to the file), with the CWD as a single fallback:
2164
+ *
2165
+ * 1. nearest config dir — if its candidate file exists, use it;
2166
+ * 2. CWD — if its candidate file exists, use it;
2167
+ * 3. otherwise resolve against the nearest config dir (else CWD) so the
2168
+ * downstream "could not stat" diagnostic names the package-local path the
2169
+ * user most likely intended — i.e. fail loud rather than silently reach
2170
+ * past the nearest config into an unrelated ancestor.
2171
+ *
2172
+ * Deliberately a two-step [config dir → CWD] resolution, NOT a walk through
2173
+ * every ancestor config: the v1 charter is deterministic + fail-loud, and a
2174
+ * multi-ancestor existence probe would let a coincidentally same-named CSS in
2175
+ * an unrelated parent silently shadow a genuine misconfiguration.
2176
+ *
2177
+ * This makes resolution independent of where oxlint is launched from: the
2178
+ * editor (CWD = workspace root) and the CLI (CWD = package dir) now agree on
2179
+ * the same CSS file in a Pattern-B monorepo (issue #39).
2180
+ */
2181
+ function resolveStringEntryPoint(entry, filePath, cwd) {
2182
+ if ((0, node_path.isAbsolute)(entry)) return (0, node_path.resolve)(entry);
2183
+ const configDir = filePath ? nearestConfigDir(filePath) : void 0;
2184
+ const bases = configDir && configDir !== cwd ? [configDir, cwd] : [cwd];
2185
+ for (const base of bases) {
2186
+ const candidate = (0, node_path.resolve)(base, entry);
2187
+ if ((0, node_fs.existsSync)(candidate)) return candidate;
2188
+ }
2189
+ return (0, node_path.resolve)(bases[0], entry);
2190
+ }
2191
+ /**
2042
2192
  * Extract `rootFontSize` from `settings.tailwindcss` (default: 16).
2043
2193
  */
2044
2194
  function rootFontSizeFromSettings(settings) {
@@ -2072,7 +2222,7 @@ function getLoadedDesignSystem(cssPath, settings) {
2072
2222
  try {
2073
2223
  mtime = (0, node_fs.statSync)(resolvedPath).mtimeMs;
2074
2224
  } catch (cause) {
2075
- throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable. The path is resolved relative to the oxlint working directory.", { cause: cause instanceof Error ? cause : void 0 });
2225
+ throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable. A relative `entryPoint` is resolved against the nearest `.oxlintrc.json` directory, falling back to the oxlint working directory.", { cause: cause instanceof Error ? cause : void 0 });
2076
2226
  }
2077
2227
  const cached = dsCache.get(resolvedPath);
2078
2228
  if (cached && cached.mtime === mtime) return {
@@ -2111,6 +2261,10 @@ function getLoadedDesignSystem(cssPath, settings) {
2111
2261
  * 3. `settings.tailwindcss.entryPoint` as an `EntryPointMapping[]` —
2112
2262
  * first matching glob (relative to CWD) wins.
2113
2263
  *
2264
+ * A relative string entry (1 or 2) is anchored to the nearest enclosing
2265
+ * `.oxlintrc.json` directory rather than the CWD, so editor and CLI runs agree
2266
+ * in Pattern-B monorepos (issue #39); see `resolveStringEntryPoint`.
2267
+ *
2114
2268
  * If none of those produce an entry point for the current file, throws
2115
2269
  * `MissingEntryPointError`. If the resolved CSS fails to load, throws
2116
2270
  * `DesignSystemLoadError`. Both extend `OxlintTailwindError` and are
@@ -2141,7 +2295,7 @@ function createLazyLoader(context) {
2141
2295
  lastResult = void 0;
2142
2296
  lastError = void 0;
2143
2297
  try {
2144
- lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath), settings);
2298
+ lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath, safeCwd(context)), settings);
2145
2299
  } catch (err) {
2146
2300
  if (isFatalError(err) && err instanceof Error) lastError = err;
2147
2301
  throw err;
@@ -2151,18 +2305,21 @@ function createLazyLoader(context) {
2151
2305
  };
2152
2306
  }
2153
2307
  /**
2154
- * Pure resolution from (rule option, settings entry, file path) to a CSS
2155
- * entry-point path. Exported for testability.
2308
+ * Pure resolution from (rule option, settings entry, file path, cwd) to an
2309
+ * absolute CSS entry-point path. Exported for testability.
2310
+ *
2311
+ * Relative string entries are anchored via `resolveStringEntryPoint` (nearest
2312
+ * `.oxlintrc.json` dir, then `cwd`); mapping arrays match relative to `cwd`.
2156
2313
  *
2157
2314
  * Throws `MissingEntryPointError` if nothing resolves. The error message
2158
2315
  * names the file so the user knows which one tripped the configuration.
2159
2316
  */
2160
- function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath) {
2161
- if (ruleOptionEntry) return ruleOptionEntry;
2162
- if (typeof settingsEntry === "string") return settingsEntry;
2317
+ function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath, cwd = process.cwd()) {
2318
+ if (ruleOptionEntry) return resolveStringEntryPoint(ruleOptionEntry, filePath, cwd);
2319
+ if (typeof settingsEntry === "string") return resolveStringEntryPoint(settingsEntry, filePath, cwd);
2163
2320
  if (Array.isArray(settingsEntry)) {
2164
2321
  if (!filePath) throw new MissingEntryPointError("`settings.tailwindcss.entryPoint` is a mapping array but no file path is available to match against.", "This usually means the rule ran outside the linter context. Open an issue if you see this in a real lint run.");
2165
- const matched = resolveByGlobMapping(settingsEntry, filePath, process.cwd());
2322
+ const matched = resolveByGlobMapping(settingsEntry, filePath, cwd);
2166
2323
  if (matched) return matched;
2167
2324
  throw new MissingEntryPointError(`No \`entryPoint\` mapping matched \`${filePath}\`.`, "Add a mapping covering this file to `settings.tailwindcss.entryPoint`, or use a `\"**\"` fallback entry.");
2168
2325
  }
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { definePlugin, defineRule } from "@oxlint/plugins";
3
3
  import { Worker, threadId } from "node:worker_threads";
4
4
  import { createHash } from "node:crypto";
5
5
  import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync } from "node:fs";
6
- import { dirname, join, relative, resolve } from "node:path";
6
+ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
7
7
  import { tmpdir, userInfo } from "node:os";
8
8
  //#region \0rolldown/runtime.js
9
9
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
@@ -1313,6 +1313,39 @@ async function main() {
1313
1313
  const dash = cls.lastIndexOf('-');
1314
1314
  if (dash > 0) knownPrefixes.add(cls.slice(0, dash));
1315
1315
  }
1316
+ // Curated static utilities valid in v4 but absent from getClassList() (#37).
1317
+ // These are special-cased in Tailwind's compiler, so they appear in neither
1318
+ // getClassList() NOR the utility registry (\`utilities.keys('static')\`) — only
1319
+ // an explicit probe surfaces them:
1320
+ // - \`@container-size\` (\`container-type: size\`) — sibling of the enumerated
1321
+ // \`@container\` / \`@container-normal\`; was flagged as a typo of \`contain-size\`.
1322
+ // - \`filter-none\` / \`backdrop-filter-none\` (\`filter: none\`) — the reset
1323
+ // utilities; their functional bases enumerate values but omit \`none\`.
1324
+ // - \`max-w-screen\` (\`max-width: 100vw\`).
1325
+ // Validated via candidatesToCss (self-prunes on any Tailwind version that doesn't
1326
+ // emit them) and their CSS is captured so the cssProps phase below treats them
1327
+ // exactly like their getClassList siblings — otherwise no-conflicting-classes
1328
+ // would flag \`@container @container-normal\` but silently accept
1329
+ // \`@container @container-size\`. Named forms (\`@container-size/main\`) are covered
1330
+ // by the slash-modifier path in cache.isValid once the base lands in validClasses.
1331
+ const staticExtras = [
1332
+ '@container-size',
1333
+ 'filter-none',
1334
+ 'backdrop-filter-none',
1335
+ 'max-w-screen',
1336
+ ].filter((c) => !validSet.has(c));
1337
+ const staticExtraCss = {};
1338
+ if (staticExtras.length > 0) {
1339
+ const staticResults = ds.candidatesToCss(staticExtras.map(pfx));
1340
+ for (let i = 0; i < staticExtras.length; i++) {
1341
+ if (staticResults[i] != null) {
1342
+ validClasses.push(staticExtras[i]);
1343
+ validSet.add(staticExtras[i]);
1344
+ staticExtraCss[staticExtras[i]] = staticResults[i];
1345
+ }
1346
+ }
1347
+ }
1348
+
1316
1349
  const extraCandidates = [];
1317
1350
  const breakpoints = ['sm', 'md', 'lg', 'xl', '2xl'];
1318
1351
  for (const prefix of knownPrefixes) {
@@ -1334,6 +1367,27 @@ async function main() {
1334
1367
  }
1335
1368
  }
1336
1369
 
1370
+ // Negative variants of utilities that support them (#37). getClassList()
1371
+ // enumerates negatives for most (\`-m-4\`, \`-translate-x-2\`) but omits a few
1372
+ // (\`-col-1\`, \`-row-1\`, \`-hue-rotate-45\`, \`-backdrop-hue-rotate-45\`). Probe
1373
+ // \`-<prefix>-1\` for every known prefix lacking negative coverage; candidatesToCss
1374
+ // self-prunes utilities that reject negatives (\`-p-1\` → null), so only genuinely
1375
+ // negative-capable prefixes land in validClasses, giving isValid's / getOrder's
1376
+ // numeric-prefix heuristic the \`-<prefix>\` it needs to accept any \`-<prefix>-<n>\`.
1377
+ const negativeProbes = [];
1378
+ for (const prefix of knownPrefixes) {
1379
+ if (!knownPrefixes.has('-' + prefix)) negativeProbes.push('-' + prefix + '-1');
1380
+ }
1381
+ if (negativeProbes.length > 0) {
1382
+ const negResults = ds.candidatesToCss(negativeProbes.map(pfx));
1383
+ for (let i = 0; i < negativeProbes.length; i++) {
1384
+ if (negResults[i] != null && !validSet.has(negativeProbes[i])) {
1385
+ validClasses.push(negativeProbes[i]);
1386
+ validSet.add(negativeProbes[i]);
1387
+ }
1388
+ }
1389
+ }
1390
+
1337
1391
  // Marker classes: group/peer don't produce CSS but enable group-hover:/peer-checked: variants
1338
1392
  const allVariants = ds.getVariants();
1339
1393
  for (const v of allVariants) {
@@ -1380,6 +1434,11 @@ async function main() {
1380
1434
  'decoration-clone', 'decoration-slice',
1381
1435
  'bg-gradient-to-t', 'bg-gradient-to-tr', 'bg-gradient-to-r', 'bg-gradient-to-br',
1382
1436
  'bg-gradient-to-b', 'bg-gradient-to-bl', 'bg-gradient-to-l', 'bg-gradient-to-tl',
1437
+ // v3 background/object-position spellings reordered in v4 (#37):
1438
+ // \`bg-left-top\` -> \`bg-top-left\`. canonicalizeCandidates rewrites them, so
1439
+ // enforce-canonical suggests the v4 form and no-unknown-classes accepts them.
1440
+ 'bg-left-top', 'bg-right-top', 'bg-left-bottom', 'bg-right-bottom',
1441
+ 'object-left-top', 'object-right-top', 'object-left-bottom', 'object-right-bottom',
1383
1442
  ];
1384
1443
  for (const cls of validClasses) {
1385
1444
  if (cls.startsWith('inset-s-')) legacyCandidates.push('start-' + cls.slice(8));
@@ -1508,6 +1567,14 @@ async function main() {
1508
1567
  }
1509
1568
  }
1510
1569
 
1570
+ // cssProps for the curated static extras (#37) so they participate in conflict
1571
+ // detection exactly like their getClassList siblings (e.g. \`@container-size\` and
1572
+ // \`@container\` both declaring \`container-type\`).
1573
+ for (const name in staticExtraCss) {
1574
+ const props = extractRootCssProps(staticExtraCss[name], pfx(name));
1575
+ if (props.length > 0) cssProps[name] = props;
1576
+ }
1577
+
1511
1578
  // Variant ordering from the design system
1512
1579
  const variantOrder = {};
1513
1580
  const variants = ds.getVariants();
@@ -1928,6 +1995,19 @@ function safeFilename(context) {
1928
1995
  }
1929
1996
  }
1930
1997
  /**
1998
+ * Safely read `context.cwd`, falling back to `process.cwd()`. Same try/catch
1999
+ * pattern as the other accessors (the getter throws in `createOnce` on older
2000
+ * oxlint). The fallback keeps relative-path resolution working even when the
2001
+ * linter never populates `cwd`.
2002
+ */
2003
+ function safeCwd(context) {
2004
+ try {
2005
+ return context.cwd ?? process.cwd();
2006
+ } catch {
2007
+ return process.cwd();
2008
+ }
2009
+ }
2010
+ /**
1931
2011
  * Lazily memoize a compiled options object across visitor calls.
1932
2012
  *
1933
2013
  * Every rule with options reinvents:
@@ -2043,6 +2123,76 @@ function resolveByGlobMapping(mappings, filePath, baseDir) {
2043
2123
  return null;
2044
2124
  }
2045
2125
  /**
2126
+ * oxlint discovers nested configuration by walking up from each linted file
2127
+ * looking for files with these names. We mirror that walk to find the config
2128
+ * directory a relative `entryPoint` should be anchored to.
2129
+ */
2130
+ const OXLINT_CONFIG_NAMES = [".oxlintrc.json"];
2131
+ /** Memoizes the nearest-config walk per starting directory (cleared in tests). */
2132
+ const nearestConfigDirCache = /* @__PURE__ */ new Map();
2133
+ /**
2134
+ * Find the directory of the **nearest** enclosing oxlint config, walking up
2135
+ * from `filePath` toward the filesystem root. Returns `undefined` if none is
2136
+ * found. This is the config oxlint applies to the file under its default
2137
+ * nested-config discovery, so a relative `entryPoint` declared in it is meant
2138
+ * to resolve relative to that directory — not the process CWD, which differs
2139
+ * between the CLI (`cd package && oxlint`) and an editor (CWD = workspace
2140
+ * root). See issue #39.
2141
+ *
2142
+ * Stops at the first match (early exit), so in the common case it touches only
2143
+ * the file's package, not the whole path to root.
2144
+ */
2145
+ function nearestConfigDir(filePath) {
2146
+ const start = dirname(resolve(filePath));
2147
+ const cached = nearestConfigDirCache.get(start);
2148
+ if (cached !== void 0) return cached ?? void 0;
2149
+ let dir = start;
2150
+ for (;;) {
2151
+ if (OXLINT_CONFIG_NAMES.some((name) => existsSync(resolve(dir, name)))) {
2152
+ nearestConfigDirCache.set(start, dir);
2153
+ return dir;
2154
+ }
2155
+ const parent = dirname(dir);
2156
+ if (parent === dir) break;
2157
+ dir = parent;
2158
+ }
2159
+ nearestConfigDirCache.set(start, null);
2160
+ }
2161
+ /**
2162
+ * Resolve a string `entryPoint` (from `settings` or a rule option) to an
2163
+ * absolute path.
2164
+ *
2165
+ * Absolute paths are returned normalized and untouched. A **relative** path is
2166
+ * anchored to the directory of the nearest enclosing `.oxlintrc.json` (the
2167
+ * config oxlint applies to the file), with the CWD as a single fallback:
2168
+ *
2169
+ * 1. nearest config dir — if its candidate file exists, use it;
2170
+ * 2. CWD — if its candidate file exists, use it;
2171
+ * 3. otherwise resolve against the nearest config dir (else CWD) so the
2172
+ * downstream "could not stat" diagnostic names the package-local path the
2173
+ * user most likely intended — i.e. fail loud rather than silently reach
2174
+ * past the nearest config into an unrelated ancestor.
2175
+ *
2176
+ * Deliberately a two-step [config dir → CWD] resolution, NOT a walk through
2177
+ * every ancestor config: the v1 charter is deterministic + fail-loud, and a
2178
+ * multi-ancestor existence probe would let a coincidentally same-named CSS in
2179
+ * an unrelated parent silently shadow a genuine misconfiguration.
2180
+ *
2181
+ * This makes resolution independent of where oxlint is launched from: the
2182
+ * editor (CWD = workspace root) and the CLI (CWD = package dir) now agree on
2183
+ * the same CSS file in a Pattern-B monorepo (issue #39).
2184
+ */
2185
+ function resolveStringEntryPoint(entry, filePath, cwd) {
2186
+ if (isAbsolute(entry)) return resolve(entry);
2187
+ const configDir = filePath ? nearestConfigDir(filePath) : void 0;
2188
+ const bases = configDir && configDir !== cwd ? [configDir, cwd] : [cwd];
2189
+ for (const base of bases) {
2190
+ const candidate = resolve(base, entry);
2191
+ if (existsSync(candidate)) return candidate;
2192
+ }
2193
+ return resolve(bases[0], entry);
2194
+ }
2195
+ /**
2046
2196
  * Extract `rootFontSize` from `settings.tailwindcss` (default: 16).
2047
2197
  */
2048
2198
  function rootFontSizeFromSettings(settings) {
@@ -2076,7 +2226,7 @@ function getLoadedDesignSystem(cssPath, settings) {
2076
2226
  try {
2077
2227
  mtime = statSync(resolvedPath).mtimeMs;
2078
2228
  } catch (cause) {
2079
- throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable. The path is resolved relative to the oxlint working directory.", { cause: cause instanceof Error ? cause : void 0 });
2229
+ throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable. A relative `entryPoint` is resolved against the nearest `.oxlintrc.json` directory, falling back to the oxlint working directory.", { cause: cause instanceof Error ? cause : void 0 });
2080
2230
  }
2081
2231
  const cached = dsCache.get(resolvedPath);
2082
2232
  if (cached && cached.mtime === mtime) return {
@@ -2115,6 +2265,10 @@ function getLoadedDesignSystem(cssPath, settings) {
2115
2265
  * 3. `settings.tailwindcss.entryPoint` as an `EntryPointMapping[]` —
2116
2266
  * first matching glob (relative to CWD) wins.
2117
2267
  *
2268
+ * A relative string entry (1 or 2) is anchored to the nearest enclosing
2269
+ * `.oxlintrc.json` directory rather than the CWD, so editor and CLI runs agree
2270
+ * in Pattern-B monorepos (issue #39); see `resolveStringEntryPoint`.
2271
+ *
2118
2272
  * If none of those produce an entry point for the current file, throws
2119
2273
  * `MissingEntryPointError`. If the resolved CSS fails to load, throws
2120
2274
  * `DesignSystemLoadError`. Both extend `OxlintTailwindError` and are
@@ -2145,7 +2299,7 @@ function createLazyLoader(context) {
2145
2299
  lastResult = void 0;
2146
2300
  lastError = void 0;
2147
2301
  try {
2148
- lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath), settings);
2302
+ lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath, safeCwd(context)), settings);
2149
2303
  } catch (err) {
2150
2304
  if (isFatalError(err) && err instanceof Error) lastError = err;
2151
2305
  throw err;
@@ -2155,18 +2309,21 @@ function createLazyLoader(context) {
2155
2309
  };
2156
2310
  }
2157
2311
  /**
2158
- * Pure resolution from (rule option, settings entry, file path) to a CSS
2159
- * entry-point path. Exported for testability.
2312
+ * Pure resolution from (rule option, settings entry, file path, cwd) to an
2313
+ * absolute CSS entry-point path. Exported for testability.
2314
+ *
2315
+ * Relative string entries are anchored via `resolveStringEntryPoint` (nearest
2316
+ * `.oxlintrc.json` dir, then `cwd`); mapping arrays match relative to `cwd`.
2160
2317
  *
2161
2318
  * Throws `MissingEntryPointError` if nothing resolves. The error message
2162
2319
  * names the file so the user knows which one tripped the configuration.
2163
2320
  */
2164
- function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath) {
2165
- if (ruleOptionEntry) return ruleOptionEntry;
2166
- if (typeof settingsEntry === "string") return settingsEntry;
2321
+ function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath, cwd = process.cwd()) {
2322
+ if (ruleOptionEntry) return resolveStringEntryPoint(ruleOptionEntry, filePath, cwd);
2323
+ if (typeof settingsEntry === "string") return resolveStringEntryPoint(settingsEntry, filePath, cwd);
2167
2324
  if (Array.isArray(settingsEntry)) {
2168
2325
  if (!filePath) throw new MissingEntryPointError("`settings.tailwindcss.entryPoint` is a mapping array but no file path is available to match against.", "This usually means the rule ran outside the linter context. Open an issue if you see this in a real lint run.");
2169
- const matched = resolveByGlobMapping(settingsEntry, filePath, process.cwd());
2326
+ const matched = resolveByGlobMapping(settingsEntry, filePath, cwd);
2170
2327
  if (matched) return matched;
2171
2328
  throw new MissingEntryPointError(`No \`entryPoint\` mapping matched \`${filePath}\`.`, "Add a mapping covering this file to `settings.tailwindcss.entryPoint`, or use a `\"**\"` fallback entry.");
2172
2329
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxlint-tailwindcss",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Tailwind CSS linting rules for oxlint",
5
5
  "keywords": [
6
6
  "css",
@@ -51,13 +51,13 @@
51
51
  "prepublishOnly": "pnpm run build"
52
52
  },
53
53
  "dependencies": {
54
- "@tailwindcss/node": "^4.3.0",
55
- "tailwindcss": "^4.3.0"
54
+ "@tailwindcss/node": "^4.3.1",
55
+ "tailwindcss": "^4.3.1"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@oxlint/plugins": "catalog:",
59
59
  "@tailwindcss/typography": "^0.5.20",
60
- "@types/node": "^25.9.2",
60
+ "@types/node": "^25.9.3",
61
61
  "@typescript/native-preview": "7.0.0-dev.20260608.1",
62
62
  "oxlint": "catalog:",
63
63
  "tailwindcss-animate": "^1.0.7",