@oxlint-config-inspector/core 1.0.0 → 1.1.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/README.md +1 -0
- package/dist/index.d.mts +12 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +65 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ type GetConfigOptions = {
|
|
|
4
4
|
configFile?: string; /** The directory to search for a config file. Defaults to `process.cwd()`. */
|
|
5
5
|
cwd?: string;
|
|
6
6
|
};
|
|
7
|
-
/** Known Oxlint config file names, searched in order by cosmiconfig. */
|
|
7
|
+
/** Known Oxlint / Vite+ config file names, searched in order by cosmiconfig. */
|
|
8
8
|
declare const searchPlaces: string[];
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/plugins.d.ts
|
|
@@ -168,7 +168,16 @@ type InspectConfigResult = {
|
|
|
168
168
|
declare function inspectConfig(options?: GetConfigOptions): Promise<InspectConfigResult | null>;
|
|
169
169
|
//#endregion
|
|
170
170
|
//#region src/rules.d.ts
|
|
171
|
-
|
|
171
|
+
type GetOxlintRulesOptions = {
|
|
172
|
+
/** When `true`, invokes the Vite+ (`vp`) binary instead of `oxlint`. */useVitePlus?: boolean;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Fetches the list of builtin lint rules by invoking the linter binary.
|
|
176
|
+
*
|
|
177
|
+
* @param options - See {@link GetOxlintRulesOptions}.
|
|
178
|
+
* @returns The parsed rules, or an empty array if the binary is unavailable or the invocation fails.
|
|
179
|
+
*/
|
|
180
|
+
declare function getOxlintRules(options?: GetOxlintRulesOptions): Promise<RuleInfo[]>;
|
|
172
181
|
//#endregion
|
|
173
|
-
export { type GetConfigOptions, type InspectConfigResult, type InspectConfigStats, type InspectedOverrideGroup, type InspectedOverrideGroupRule, type InspectedPlugin, type InspectedPluginLoadError, type InspectedPluginSource, type InspectedRule, type InspectedRuleConfig, type InspectedRuleSource, type InspectedRuleType, type InspectedRuleUsage, type InspectedRuleUsageSeverity, type RuleInfo, type RuleSeverity, getOxlintRules, inspectConfig, searchPlaces };
|
|
182
|
+
export { type GetConfigOptions, type GetOxlintRulesOptions, type InspectConfigResult, type InspectConfigStats, type InspectedOverrideGroup, type InspectedOverrideGroupRule, type InspectedPlugin, type InspectedPluginLoadError, type InspectedPluginSource, type InspectedRule, type InspectedRuleConfig, type InspectedRuleSource, type InspectedRuleType, type InspectedRuleUsage, type InspectedRuleUsageSeverity, type RuleInfo, type RuleSeverity, getOxlintRules, inspectConfig, searchPlaces };
|
|
174
183
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/config.ts","../src/plugins.ts","../src/types.ts","../src/inspect.ts","../src/rules.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/config.ts","../src/plugins.ts","../src/types.ts","../src/inspect.ts","../src/rules.ts"],"mappings":";KAmBY,gBAAA;EAAgB,+EAE1B,KAAA,YAF0B;EAI1B,UAAA;EAEA,GAAA;AAAA;;cAoBW,YAAA;;;;;;KCCD,eAAA;EACV,OAAA;EACA,IAAA;EACA,SAAA;AAAA;;;KCjDU,QAAA;EACV,KAAA;EACA,KAAA;EACA,QAAA;EACA,UAAA;EACA,GAAA;EACA,OAAA;EACA,QAAA;AAAA;;;;;;KCQU,qBAAA;;;AHUP;KGLO,eAAA;EHyB2F,8CGvBrG,SAAA,UHuBqG;EGrBrG,IAAA;EAEA,SAAA;EAEA,MAAA,EAAQ,qBAAqB;AAAA;;;;KAMnB,wBAAA,GAA2B,eAAe;;;AFe3C;KEVC,YAAA;;;ADvCZ;KC4CY,mBAAA;;;;KAKA,iBAAA;;;;KAKA,0BAAA;;;AD/CF;KCoDE,mBAAA;gGAEV,OAAA,a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AA,UA5BI;EA8BJ,OAAA,aAxBoC;EA0BpC,KAAA,EAAO,0BAA0B;AAAA;;;;KAMvB,mBAAA;EAxBA,2DA0BV,WAAA,YAxBQ;EA0BR,cAAA,UA1B2B;EA4B3B,WAAA,UAtBgC;EAwBhC,cAAA,EAAgB,sBAAA,IAdiB;EAgBjC,YAAA,EAAc,wBAAA,IAtBd;EAwBA,OAAA,EAAS,eAAA,IApBT;EAsBA,iBAAA,YApBO;EAsBP,KAAA,EAAO,aAAA,IAtB0B;EAwBjC,KAAA,EAAO,kBAAA,EAlBsB;EAoB7B,YAAA,EAAc,aAAA,IAZE;EAchB,OAAA;AAAA;;;;;;;iBAeoB,aAAA,CAAc,OAAA,GAAS,gBAAA,GAAwB,OAAA,CAAQ,mBAAA;;;KCpOjE,qBAAA;EJagB,wEIX1B,WAAW;AAAA;;;;;AJiBR;AAoBL;iBI5BsB,cAAA,CAAe,OAAA,GAAU,qBAAA,GAAwB,OAAA,CAAQ,QAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { access } from "node:fs/promises";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { cosmiconfig, defaultLoaders } from "cosmiconfig";
|
|
3
4
|
import { createJiti } from "jiti";
|
|
@@ -5,12 +6,14 @@ import { parse, printParseErrorCode } from "jsonc-parser";
|
|
|
5
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
7
|
import { x } from "tinyexec";
|
|
7
8
|
//#region src/config.ts
|
|
8
|
-
/** Known Oxlint config file names, searched in order by cosmiconfig. */
|
|
9
|
+
/** Known Oxlint / Vite+ config file names, searched in order by cosmiconfig. */
|
|
9
10
|
const searchPlaces = [
|
|
11
|
+
"vite.config.ts",
|
|
10
12
|
".oxlintrc.json",
|
|
11
13
|
".oxlintrc.jsonc",
|
|
12
14
|
"oxlint.config.ts"
|
|
13
15
|
];
|
|
16
|
+
const VITE_CONFIG_BASENAME = "vite.config.ts";
|
|
14
17
|
function createExplorer(cache) {
|
|
15
18
|
const loadTs = createTypeScriptLoader(cache);
|
|
16
19
|
return cosmiconfig("oxlint", {
|
|
@@ -36,13 +39,25 @@ function createTypeScriptLoader(cache) {
|
|
|
36
39
|
fsCache: cache,
|
|
37
40
|
moduleCache: cache
|
|
38
41
|
});
|
|
39
|
-
return async (filepath) =>
|
|
42
|
+
return async (filepath) => {
|
|
43
|
+
const exported = await jiti.import(filepath, { default: true });
|
|
44
|
+
if (path.basename(filepath) === VITE_CONFIG_BASENAME) return extractViteLintConfig(exported);
|
|
45
|
+
return exported ?? null;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function extractViteLintConfig(exported) {
|
|
49
|
+
if (!exported || typeof exported !== "object" || Array.isArray(exported)) return null;
|
|
50
|
+
const lint = exported.lint;
|
|
51
|
+
if (!lint || typeof lint !== "object" || Array.isArray(lint)) return null;
|
|
52
|
+
return lint;
|
|
40
53
|
}
|
|
41
54
|
/**
|
|
42
55
|
* Loads and resolves an Oxlint configuration file.
|
|
43
56
|
*
|
|
44
57
|
* Discovers the config via cosmiconfig (searching from `cwd` or loading a
|
|
45
58
|
* specific `configFile`), then recursively resolves all `extends` chains.
|
|
59
|
+
* Within each directory, {@link searchPlaces} are tried in order; empty configs
|
|
60
|
+
* (e.g. a Vite config without a `lint` block) are skipped so later places can win.
|
|
46
61
|
*
|
|
47
62
|
* @param options - See {@link GetConfigOptions}.
|
|
48
63
|
* @returns The resolved config with all extensions flattened, or `null` if no config file is found.
|
|
@@ -50,7 +65,7 @@ function createTypeScriptLoader(cache) {
|
|
|
50
65
|
async function getConfig(options = {}) {
|
|
51
66
|
const cwd = options.cwd ?? process.cwd();
|
|
52
67
|
const explorer = options.cache === false ? createExplorer(false) : defaultExplorer;
|
|
53
|
-
const result = options.configFile ? await explorer.load(path.resolve(cwd, options.configFile)) : await
|
|
68
|
+
const result = options.configFile ? await explorer.load(path.resolve(cwd, options.configFile)) : await searchDirectory(path.resolve(cwd), explorer);
|
|
54
69
|
if (!result || result.isEmpty) return null;
|
|
55
70
|
const files = /* @__PURE__ */ new Set([result.filepath]);
|
|
56
71
|
return {
|
|
@@ -59,6 +74,29 @@ async function getConfig(options = {}) {
|
|
|
59
74
|
filepath: result.filepath
|
|
60
75
|
};
|
|
61
76
|
}
|
|
77
|
+
async function searchDirectory(directory, explorer) {
|
|
78
|
+
const result = await tryLoad(searchPlaces.map((place) => path.join(directory, place)), explorer);
|
|
79
|
+
if (result) return result;
|
|
80
|
+
try {
|
|
81
|
+
await access(path.join(directory, "package.json"));
|
|
82
|
+
return null;
|
|
83
|
+
} catch {}
|
|
84
|
+
const parent = path.dirname(directory);
|
|
85
|
+
return parent === directory ? null : searchDirectory(parent, explorer);
|
|
86
|
+
}
|
|
87
|
+
async function tryLoad([filepath, ...rest], explorer) {
|
|
88
|
+
if (!filepath) return null;
|
|
89
|
+
try {
|
|
90
|
+
const result = await explorer.load(filepath);
|
|
91
|
+
if (result && !result.isEmpty) return result;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (!isFileNotFoundError(error)) throw error;
|
|
94
|
+
}
|
|
95
|
+
return tryLoad(rest, explorer);
|
|
96
|
+
}
|
|
97
|
+
function isFileNotFoundError(error) {
|
|
98
|
+
return error instanceof Error && error.code === "ENOENT";
|
|
99
|
+
}
|
|
62
100
|
/**
|
|
63
101
|
* Recursively resolves a config and all of its `extends`.
|
|
64
102
|
*
|
|
@@ -204,7 +242,7 @@ function mergeArrays(base, override) {
|
|
|
204
242
|
}
|
|
205
243
|
//#endregion
|
|
206
244
|
//#region package.json
|
|
207
|
-
var version = "1.
|
|
245
|
+
var version = "1.1.0";
|
|
208
246
|
//#endregion
|
|
209
247
|
//#region src/generated/builtin-rule-docs.ts
|
|
210
248
|
const builtinRuleDocs = {
|
|
@@ -2775,7 +2813,14 @@ function normalizePackagePluginName(specifier) {
|
|
|
2775
2813
|
//#endregion
|
|
2776
2814
|
//#region src/rules.ts
|
|
2777
2815
|
let oxlintBinaryAvailability;
|
|
2778
|
-
|
|
2816
|
+
/**
|
|
2817
|
+
* Fetches the list of builtin lint rules by invoking the linter binary.
|
|
2818
|
+
*
|
|
2819
|
+
* @param options - See {@link GetOxlintRulesOptions}.
|
|
2820
|
+
* @returns The parsed rules, or an empty array if the binary is unavailable or the invocation fails.
|
|
2821
|
+
*/
|
|
2822
|
+
async function getOxlintRules(options) {
|
|
2823
|
+
if (options?.useVitePlus) return getVitePlusRules();
|
|
2779
2824
|
if (!await isOxlintBinaryAvailable()) {
|
|
2780
2825
|
console.error("Unable to inspect builtin Oxlint rules because the `oxlint` binary is not available on PATH.");
|
|
2781
2826
|
return [];
|
|
@@ -2788,6 +2833,19 @@ async function getOxlintRules() {
|
|
|
2788
2833
|
return [];
|
|
2789
2834
|
}
|
|
2790
2835
|
}
|
|
2836
|
+
async function getVitePlusRules() {
|
|
2837
|
+
try {
|
|
2838
|
+
const rules = await x("vp", [
|
|
2839
|
+
"lint",
|
|
2840
|
+
"--rules",
|
|
2841
|
+
"--format=json"
|
|
2842
|
+
]);
|
|
2843
|
+
return JSON.parse(rules.stdout);
|
|
2844
|
+
} catch (error) {
|
|
2845
|
+
console.error("Error fetching Vite+ rules:", error);
|
|
2846
|
+
return [];
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2791
2849
|
async function isOxlintBinaryAvailable() {
|
|
2792
2850
|
oxlintBinaryAvailability ??= checkOxlintBinaryAvailability();
|
|
2793
2851
|
return oxlintBinaryAvailability;
|
|
@@ -2888,7 +2946,8 @@ function getBuiltinRuleId(rule) {
|
|
|
2888
2946
|
async function inspectConfig(options = {}) {
|
|
2889
2947
|
const config = await getConfig(options);
|
|
2890
2948
|
if (!config) return null;
|
|
2891
|
-
const
|
|
2949
|
+
const isVitePlus = config.filepath.endsWith("vite.config.ts");
|
|
2950
|
+
const [builtinRules, loadedPlugins] = await Promise.all([getOxlintRules({ useVitePlus: isVitePlus }), getPlugins(config)]);
|
|
2892
2951
|
return inspectLoadedConfig(config, builtinRules, loadedPlugins.plugins, loadedPlugins.errors);
|
|
2893
2952
|
}
|
|
2894
2953
|
/**
|