mega-linter-runner 9.4.0 → 9.5.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.
@@ -0,0 +1,100 @@
1
+ import { default as fs } from "fs-extra";
2
+ import * as path from "path";
3
+ import { dirname } from "path";
4
+ import { fileURLToPath } from "url";
5
+
6
+ const VARS_FILE = path.join(
7
+ dirname(fileURLToPath(import.meta.url)),
8
+ "megalinter-vars.json",
9
+ );
10
+
11
+ function loadVars() {
12
+ if (!fs.existsSync(VARS_FILE)) {
13
+ throw new Error(
14
+ `Bundled variables file not found at ${VARS_FILE}. Re-run \`make megalinter-build\` to regenerate it.`,
15
+ );
16
+ }
17
+ return fs.readJsonSync(VARS_FILE);
18
+ }
19
+
20
+ function matches(variable, pattern) {
21
+ if (!pattern) return true;
22
+ const p = pattern.toLowerCase();
23
+ return (
24
+ variable.name.toLowerCase().includes(p) ||
25
+ (variable.category || "").toLowerCase().includes(p) ||
26
+ (variable.section || "").toLowerCase().includes(p) ||
27
+ (variable.title || "").toLowerCase().includes(p)
28
+ );
29
+ }
30
+
31
+ function formatType(variable) {
32
+ const t = variable.type;
33
+ if (Array.isArray(t)) return t.join(" | ");
34
+ return t || "string";
35
+ }
36
+
37
+ function renderHuman(variables, pattern, meta) {
38
+ const lines = [];
39
+ if (pattern) {
40
+ lines.push(
41
+ `MegaLinter variables matching "${pattern}" (${variables.length}/${meta.variable_count}):`,
42
+ );
43
+ } else {
44
+ lines.push(`MegaLinter variables (${variables.length} total):`);
45
+ }
46
+ lines.push("");
47
+ for (const v of variables) {
48
+ lines.push(` ${v.name} [${formatType(v)}] (${v.category || "GENERAL"})`);
49
+ if (v.title) {
50
+ lines.push(` ${v.title}`);
51
+ }
52
+ if (v.description && v.description !== v.title) {
53
+ lines.push(` ${v.description}`);
54
+ }
55
+ if (v.default !== undefined) {
56
+ lines.push(` default: ${JSON.stringify(v.default)}`);
57
+ }
58
+ if (Array.isArray(v.enum) && v.enum.length > 0) {
59
+ lines.push(` allowed: ${v.enum.join(", ")}`);
60
+ }
61
+ if (Array.isArray(v.items_enum) && v.items_enum.length > 0) {
62
+ const preview = v.items_enum.slice(0, 6).join(", ");
63
+ const suffix =
64
+ v.items_enum.length > 6
65
+ ? `, … (${v.items_enum.length} values)`
66
+ : "";
67
+ lines.push(` item values: ${preview}${suffix}`);
68
+ }
69
+ if (Array.isArray(v.examples) && v.examples.length > 0) {
70
+ lines.push(` examples: ${v.examples.map((e) => JSON.stringify(e)).join(", ")}`);
71
+ }
72
+ lines.push("");
73
+ }
74
+ lines.push(`Reference: ${meta.doc_url}`);
75
+ lines.push(
76
+ pattern
77
+ ? "Pass variables with: mega-linter-runner -e KEY=VALUE"
78
+ : "Filter results: mega-linter-runner --list-vars <pattern>",
79
+ );
80
+ return lines.join("\n");
81
+ }
82
+
83
+ export function listVars({ pattern, asJson } = {}) {
84
+ const data = loadVars();
85
+ const all = Object.values(data.variables);
86
+ const filtered = all.filter((v) => matches(v, pattern));
87
+ if (asJson) {
88
+ return {
89
+ stdout: JSON.stringify(
90
+ {
91
+ _meta: { ...data._meta, pattern: pattern || null, returned: filtered.length },
92
+ variables: filtered,
93
+ },
94
+ null,
95
+ 2,
96
+ ),
97
+ };
98
+ }
99
+ return { stdout: renderHuman(filtered, pattern, data._meta) };
100
+ }