oxlint-tailwindcss 1.3.1 → 1.3.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/README.md +3 -1
- package/dist/index.cjs +233 -80
- package/dist/index.d.cts +4021 -1
- package/dist/index.d.mts +4021 -1
- package/dist/index.mjs +164 -10
- package/package.json +3 -6
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,77 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { definePlugin, defineRule } from "@oxlint/plugins";
|
|
3
2
|
import { Worker, threadId } from "node:worker_threads";
|
|
4
3
|
import { createHash } from "node:crypto";
|
|
5
4
|
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync } from "node:fs";
|
|
6
|
-
import { dirname, join, relative, resolve } from "node:path";
|
|
5
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
7
6
|
import { tmpdir, userInfo } from "node:os";
|
|
8
7
|
//#region \0rolldown/runtime.js
|
|
9
8
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
10
9
|
//#endregion
|
|
10
|
+
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.70.0/node_modules/@oxlint/plugins/index.js
|
|
11
|
+
/**
|
|
12
|
+
* Define a plugin.
|
|
13
|
+
*
|
|
14
|
+
* No-op function, just to provide type safety. Input is passed through unchanged.
|
|
15
|
+
*
|
|
16
|
+
* @param plugin - Plugin to define
|
|
17
|
+
* @returns Same plugin as passed in
|
|
18
|
+
*/
|
|
19
|
+
function definePlugin(plugin) {
|
|
20
|
+
return plugin;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Define a rule.
|
|
24
|
+
*
|
|
25
|
+
* No-op function, just to provide type safety. Input is passed through unchanged.
|
|
26
|
+
*
|
|
27
|
+
* @param rule - Rule to define
|
|
28
|
+
* @returns Same rule as passed in
|
|
29
|
+
*/
|
|
30
|
+
function defineRule(rule) {
|
|
31
|
+
return rule;
|
|
32
|
+
}
|
|
33
|
+
Object.freeze({
|
|
34
|
+
get filename() {
|
|
35
|
+
throw Error("Cannot access `context.filename` in `createOnce`");
|
|
36
|
+
},
|
|
37
|
+
getFilename() {
|
|
38
|
+
throw Error("Cannot call `context.getFilename` in `createOnce`");
|
|
39
|
+
},
|
|
40
|
+
get physicalFilename() {
|
|
41
|
+
throw Error("Cannot access `context.physicalFilename` in `createOnce`");
|
|
42
|
+
},
|
|
43
|
+
getPhysicalFilename() {
|
|
44
|
+
throw Error("Cannot call `context.getPhysicalFilename` in `createOnce`");
|
|
45
|
+
},
|
|
46
|
+
get cwd() {
|
|
47
|
+
throw Error("Cannot access `context.cwd` in `createOnce`");
|
|
48
|
+
},
|
|
49
|
+
getCwd() {
|
|
50
|
+
throw Error("Cannot call `context.getCwd` in `createOnce`");
|
|
51
|
+
},
|
|
52
|
+
get sourceCode() {
|
|
53
|
+
throw Error("Cannot access `context.sourceCode` in `createOnce`");
|
|
54
|
+
},
|
|
55
|
+
getSourceCode() {
|
|
56
|
+
throw Error("Cannot call `context.getSourceCode` in `createOnce`");
|
|
57
|
+
},
|
|
58
|
+
get languageOptions() {
|
|
59
|
+
throw Error("Cannot access `context.languageOptions` in `createOnce`");
|
|
60
|
+
},
|
|
61
|
+
get settings() {
|
|
62
|
+
throw Error("Cannot access `context.settings` in `createOnce`");
|
|
63
|
+
},
|
|
64
|
+
extend(extension) {
|
|
65
|
+
return Object.freeze(Object.assign(Object.create(this), extension));
|
|
66
|
+
},
|
|
67
|
+
get parserOptions() {
|
|
68
|
+
throw Error("Cannot access `context.parserOptions` in `createOnce`");
|
|
69
|
+
},
|
|
70
|
+
get parserPath() {
|
|
71
|
+
throw Error("Cannot access `context.parserPath` in `createOnce`");
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
//#endregion
|
|
11
75
|
//#region src/utils/allowlist.ts
|
|
12
76
|
/**
|
|
13
77
|
* Shared regex-allowlist helpers used by rules that accept an `allowlist`
|
|
@@ -1995,6 +2059,19 @@ function safeFilename(context) {
|
|
|
1995
2059
|
}
|
|
1996
2060
|
}
|
|
1997
2061
|
/**
|
|
2062
|
+
* Safely read `context.cwd`, falling back to `process.cwd()`. Same try/catch
|
|
2063
|
+
* pattern as the other accessors (the getter throws in `createOnce` on older
|
|
2064
|
+
* oxlint). The fallback keeps relative-path resolution working even when the
|
|
2065
|
+
* linter never populates `cwd`.
|
|
2066
|
+
*/
|
|
2067
|
+
function safeCwd(context) {
|
|
2068
|
+
try {
|
|
2069
|
+
return context.cwd ?? process.cwd();
|
|
2070
|
+
} catch {
|
|
2071
|
+
return process.cwd();
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
/**
|
|
1998
2075
|
* Lazily memoize a compiled options object across visitor calls.
|
|
1999
2076
|
*
|
|
2000
2077
|
* Every rule with options reinvents:
|
|
@@ -2110,6 +2187,76 @@ function resolveByGlobMapping(mappings, filePath, baseDir) {
|
|
|
2110
2187
|
return null;
|
|
2111
2188
|
}
|
|
2112
2189
|
/**
|
|
2190
|
+
* oxlint discovers nested configuration by walking up from each linted file
|
|
2191
|
+
* looking for files with these names. We mirror that walk to find the config
|
|
2192
|
+
* directory a relative `entryPoint` should be anchored to.
|
|
2193
|
+
*/
|
|
2194
|
+
const OXLINT_CONFIG_NAMES = [".oxlintrc.json"];
|
|
2195
|
+
/** Memoizes the nearest-config walk per starting directory (cleared in tests). */
|
|
2196
|
+
const nearestConfigDirCache = /* @__PURE__ */ new Map();
|
|
2197
|
+
/**
|
|
2198
|
+
* Find the directory of the **nearest** enclosing oxlint config, walking up
|
|
2199
|
+
* from `filePath` toward the filesystem root. Returns `undefined` if none is
|
|
2200
|
+
* found. This is the config oxlint applies to the file under its default
|
|
2201
|
+
* nested-config discovery, so a relative `entryPoint` declared in it is meant
|
|
2202
|
+
* to resolve relative to that directory — not the process CWD, which differs
|
|
2203
|
+
* between the CLI (`cd package && oxlint`) and an editor (CWD = workspace
|
|
2204
|
+
* root). See issue #39.
|
|
2205
|
+
*
|
|
2206
|
+
* Stops at the first match (early exit), so in the common case it touches only
|
|
2207
|
+
* the file's package, not the whole path to root.
|
|
2208
|
+
*/
|
|
2209
|
+
function nearestConfigDir(filePath) {
|
|
2210
|
+
const start = dirname(resolve(filePath));
|
|
2211
|
+
const cached = nearestConfigDirCache.get(start);
|
|
2212
|
+
if (cached !== void 0) return cached ?? void 0;
|
|
2213
|
+
let dir = start;
|
|
2214
|
+
for (;;) {
|
|
2215
|
+
if (OXLINT_CONFIG_NAMES.some((name) => existsSync(resolve(dir, name)))) {
|
|
2216
|
+
nearestConfigDirCache.set(start, dir);
|
|
2217
|
+
return dir;
|
|
2218
|
+
}
|
|
2219
|
+
const parent = dirname(dir);
|
|
2220
|
+
if (parent === dir) break;
|
|
2221
|
+
dir = parent;
|
|
2222
|
+
}
|
|
2223
|
+
nearestConfigDirCache.set(start, null);
|
|
2224
|
+
}
|
|
2225
|
+
/**
|
|
2226
|
+
* Resolve a string `entryPoint` (from `settings` or a rule option) to an
|
|
2227
|
+
* absolute path.
|
|
2228
|
+
*
|
|
2229
|
+
* Absolute paths are returned normalized and untouched. A **relative** path is
|
|
2230
|
+
* anchored to the directory of the nearest enclosing `.oxlintrc.json` (the
|
|
2231
|
+
* config oxlint applies to the file), with the CWD as a single fallback:
|
|
2232
|
+
*
|
|
2233
|
+
* 1. nearest config dir — if its candidate file exists, use it;
|
|
2234
|
+
* 2. CWD — if its candidate file exists, use it;
|
|
2235
|
+
* 3. otherwise resolve against the nearest config dir (else CWD) so the
|
|
2236
|
+
* downstream "could not stat" diagnostic names the package-local path the
|
|
2237
|
+
* user most likely intended — i.e. fail loud rather than silently reach
|
|
2238
|
+
* past the nearest config into an unrelated ancestor.
|
|
2239
|
+
*
|
|
2240
|
+
* Deliberately a two-step [config dir → CWD] resolution, NOT a walk through
|
|
2241
|
+
* every ancestor config: the v1 charter is deterministic + fail-loud, and a
|
|
2242
|
+
* multi-ancestor existence probe would let a coincidentally same-named CSS in
|
|
2243
|
+
* an unrelated parent silently shadow a genuine misconfiguration.
|
|
2244
|
+
*
|
|
2245
|
+
* This makes resolution independent of where oxlint is launched from: the
|
|
2246
|
+
* editor (CWD = workspace root) and the CLI (CWD = package dir) now agree on
|
|
2247
|
+
* the same CSS file in a Pattern-B monorepo (issue #39).
|
|
2248
|
+
*/
|
|
2249
|
+
function resolveStringEntryPoint(entry, filePath, cwd) {
|
|
2250
|
+
if (isAbsolute(entry)) return resolve(entry);
|
|
2251
|
+
const configDir = filePath ? nearestConfigDir(filePath) : void 0;
|
|
2252
|
+
const bases = configDir && configDir !== cwd ? [configDir, cwd] : [cwd];
|
|
2253
|
+
for (const base of bases) {
|
|
2254
|
+
const candidate = resolve(base, entry);
|
|
2255
|
+
if (existsSync(candidate)) return candidate;
|
|
2256
|
+
}
|
|
2257
|
+
return resolve(bases[0], entry);
|
|
2258
|
+
}
|
|
2259
|
+
/**
|
|
2113
2260
|
* Extract `rootFontSize` from `settings.tailwindcss` (default: 16).
|
|
2114
2261
|
*/
|
|
2115
2262
|
function rootFontSizeFromSettings(settings) {
|
|
@@ -2143,7 +2290,7 @@ function getLoadedDesignSystem(cssPath, settings) {
|
|
|
2143
2290
|
try {
|
|
2144
2291
|
mtime = statSync(resolvedPath).mtimeMs;
|
|
2145
2292
|
} catch (cause) {
|
|
2146
|
-
throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable.
|
|
2293
|
+
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 });
|
|
2147
2294
|
}
|
|
2148
2295
|
const cached = dsCache.get(resolvedPath);
|
|
2149
2296
|
if (cached && cached.mtime === mtime) return {
|
|
@@ -2182,6 +2329,10 @@ function getLoadedDesignSystem(cssPath, settings) {
|
|
|
2182
2329
|
* 3. `settings.tailwindcss.entryPoint` as an `EntryPointMapping[]` —
|
|
2183
2330
|
* first matching glob (relative to CWD) wins.
|
|
2184
2331
|
*
|
|
2332
|
+
* A relative string entry (1 or 2) is anchored to the nearest enclosing
|
|
2333
|
+
* `.oxlintrc.json` directory rather than the CWD, so editor and CLI runs agree
|
|
2334
|
+
* in Pattern-B monorepos (issue #39); see `resolveStringEntryPoint`.
|
|
2335
|
+
*
|
|
2185
2336
|
* If none of those produce an entry point for the current file, throws
|
|
2186
2337
|
* `MissingEntryPointError`. If the resolved CSS fails to load, throws
|
|
2187
2338
|
* `DesignSystemLoadError`. Both extend `OxlintTailwindError` and are
|
|
@@ -2212,7 +2363,7 @@ function createLazyLoader(context) {
|
|
|
2212
2363
|
lastResult = void 0;
|
|
2213
2364
|
lastError = void 0;
|
|
2214
2365
|
try {
|
|
2215
|
-
lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath), settings);
|
|
2366
|
+
lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath, safeCwd(context)), settings);
|
|
2216
2367
|
} catch (err) {
|
|
2217
2368
|
if (isFatalError(err) && err instanceof Error) lastError = err;
|
|
2218
2369
|
throw err;
|
|
@@ -2222,18 +2373,21 @@ function createLazyLoader(context) {
|
|
|
2222
2373
|
};
|
|
2223
2374
|
}
|
|
2224
2375
|
/**
|
|
2225
|
-
* Pure resolution from (rule option, settings entry, file path) to
|
|
2226
|
-
* entry-point path. Exported for testability.
|
|
2376
|
+
* Pure resolution from (rule option, settings entry, file path, cwd) to an
|
|
2377
|
+
* absolute CSS entry-point path. Exported for testability.
|
|
2378
|
+
*
|
|
2379
|
+
* Relative string entries are anchored via `resolveStringEntryPoint` (nearest
|
|
2380
|
+
* `.oxlintrc.json` dir, then `cwd`); mapping arrays match relative to `cwd`.
|
|
2227
2381
|
*
|
|
2228
2382
|
* Throws `MissingEntryPointError` if nothing resolves. The error message
|
|
2229
2383
|
* names the file so the user knows which one tripped the configuration.
|
|
2230
2384
|
*/
|
|
2231
|
-
function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath) {
|
|
2232
|
-
if (ruleOptionEntry) return ruleOptionEntry;
|
|
2233
|
-
if (typeof settingsEntry === "string") return settingsEntry;
|
|
2385
|
+
function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath, cwd = process.cwd()) {
|
|
2386
|
+
if (ruleOptionEntry) return resolveStringEntryPoint(ruleOptionEntry, filePath, cwd);
|
|
2387
|
+
if (typeof settingsEntry === "string") return resolveStringEntryPoint(settingsEntry, filePath, cwd);
|
|
2234
2388
|
if (Array.isArray(settingsEntry)) {
|
|
2235
2389
|
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.");
|
|
2236
|
-
const matched = resolveByGlobMapping(settingsEntry, filePath,
|
|
2390
|
+
const matched = resolveByGlobMapping(settingsEntry, filePath, cwd);
|
|
2237
2391
|
if (matched) return matched;
|
|
2238
2392
|
throw new MissingEntryPointError(`No \`entryPoint\` mapping matched \`${filePath}\`.`, "Add a mapping covering this file to `settings.tailwindcss.entryPoint`, or use a `\"**\"` fallback entry.");
|
|
2239
2393
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxlint-tailwindcss",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Tailwind CSS linting rules for oxlint",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -58,16 +58,13 @@
|
|
|
58
58
|
"@oxlint/plugins": "catalog:",
|
|
59
59
|
"@tailwindcss/typography": "^0.5.20",
|
|
60
60
|
"@types/node": "^25.9.3",
|
|
61
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
61
|
+
"@typescript/native-preview": "7.0.0-dev.20260615.1",
|
|
62
62
|
"oxlint": "catalog:",
|
|
63
63
|
"tailwindcss-animate": "^1.0.7",
|
|
64
64
|
"tsdown": "^0.22.2",
|
|
65
65
|
"tw-animate-css": "^1.4.0",
|
|
66
66
|
"typescript": "^6.0.3",
|
|
67
|
-
"vitest": "^4.1.
|
|
68
|
-
},
|
|
69
|
-
"peerDependencies": {
|
|
70
|
-
"@oxlint/plugins": ">=1.43.0 <2"
|
|
67
|
+
"vitest": "^4.1.9"
|
|
71
68
|
},
|
|
72
69
|
"engines": {
|
|
73
70
|
"node": ">=20"
|