eslint-plugin-ai-guard 1.1.4 → 1.1.5
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/dist/cli/index.js +77 -63
- package/dist/cli/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -2107,6 +2107,73 @@ var import_chalk2 = __toESM(require("chalk"));
|
|
|
2107
2107
|
|
|
2108
2108
|
// cli/utils/eslint-runner.ts
|
|
2109
2109
|
var import_path = __toESM(require("path"));
|
|
2110
|
+
|
|
2111
|
+
// cli/utils/logger.ts
|
|
2112
|
+
var import_chalk = __toESM(require("chalk"));
|
|
2113
|
+
var PREFIX = {
|
|
2114
|
+
success: import_chalk.default.green("\u2714"),
|
|
2115
|
+
error: import_chalk.default.red("\u2716"),
|
|
2116
|
+
warn: import_chalk.default.yellow("\u26A0"),
|
|
2117
|
+
info: import_chalk.default.cyan("\u2139"),
|
|
2118
|
+
section: import_chalk.default.bold.white,
|
|
2119
|
+
bullet: import_chalk.default.gray("\u2022")
|
|
2120
|
+
};
|
|
2121
|
+
var log = {
|
|
2122
|
+
info(msg) {
|
|
2123
|
+
console.log(` ${PREFIX.info} ${import_chalk.default.white(msg)}`);
|
|
2124
|
+
},
|
|
2125
|
+
success(msg) {
|
|
2126
|
+
console.log(` ${PREFIX.success} ${import_chalk.default.green(msg)}`);
|
|
2127
|
+
},
|
|
2128
|
+
warn(msg) {
|
|
2129
|
+
console.log(` ${PREFIX.warn} ${import_chalk.default.yellow(msg)}`);
|
|
2130
|
+
},
|
|
2131
|
+
error(msg) {
|
|
2132
|
+
console.error(` ${PREFIX.error} ${import_chalk.default.red(msg)}`);
|
|
2133
|
+
},
|
|
2134
|
+
section(title) {
|
|
2135
|
+
console.log("");
|
|
2136
|
+
console.log(import_chalk.default.bold.cyan(` \u2500\u2500 ${title} \u2500\u2500`));
|
|
2137
|
+
console.log("");
|
|
2138
|
+
},
|
|
2139
|
+
rule(ruleName, count) {
|
|
2140
|
+
console.log(
|
|
2141
|
+
` ${PREFIX.bullet} ${import_chalk.default.yellow(ruleName)} ${import_chalk.default.gray(`(${count} issue${count !== 1 ? "s" : ""})`)}`
|
|
2142
|
+
);
|
|
2143
|
+
},
|
|
2144
|
+
file(filePath, count) {
|
|
2145
|
+
console.log(
|
|
2146
|
+
` ${PREFIX.bullet} ${import_chalk.default.white(filePath)} ${import_chalk.default.gray(`\u2192 ${count} issue${count !== 1 ? "s" : ""}`)}`
|
|
2147
|
+
);
|
|
2148
|
+
},
|
|
2149
|
+
issue(msg, severity, line, col) {
|
|
2150
|
+
const icon = severity === 2 ? import_chalk.default.red("error") : import_chalk.default.yellow(" warn");
|
|
2151
|
+
console.log(
|
|
2152
|
+
` ${import_chalk.default.gray(`${line}:${col}`).padEnd(12)} ${icon} ${import_chalk.default.white(msg)}`
|
|
2153
|
+
);
|
|
2154
|
+
},
|
|
2155
|
+
divider() {
|
|
2156
|
+
console.log(import_chalk.default.gray(" " + "\u2500".repeat(60)));
|
|
2157
|
+
},
|
|
2158
|
+
blank() {
|
|
2159
|
+
console.log("");
|
|
2160
|
+
},
|
|
2161
|
+
banner(title) {
|
|
2162
|
+
console.log("");
|
|
2163
|
+
console.log(import_chalk.default.bold.bgCyan.black(` ${title} `));
|
|
2164
|
+
console.log("");
|
|
2165
|
+
},
|
|
2166
|
+
print(msg) {
|
|
2167
|
+
console.log(msg);
|
|
2168
|
+
},
|
|
2169
|
+
debug(msg) {
|
|
2170
|
+
if (process.env.AI_GUARD_DEBUG === "1") {
|
|
2171
|
+
console.log(` ${import_chalk.default.gray("\xB7")} ${import_chalk.default.gray(msg)}`);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
|
|
2176
|
+
// cli/utils/eslint-runner.ts
|
|
2110
2177
|
function normalizePlugin(raw) {
|
|
2111
2178
|
if (raw && raw.default && raw.default.rules) return raw.default;
|
|
2112
2179
|
if (raw && raw.rules) return raw;
|
|
@@ -2169,6 +2236,12 @@ var DEFAULT_IGNORE_PATTERNS = [
|
|
|
2169
2236
|
"**/out/**",
|
|
2170
2237
|
"**/.git/**"
|
|
2171
2238
|
];
|
|
2239
|
+
function isSkippablePatternError(error) {
|
|
2240
|
+
const msg = error.message.toLowerCase();
|
|
2241
|
+
const hasNoFilesSignal = msg.includes("no files") || msg.includes("no files matching");
|
|
2242
|
+
const hasIgnoredSignal = msg.includes("ignored") || msg.includes("all files matched by") || msg.includes("are ignored") || msg.includes("was ignored") || msg.includes("file ignored");
|
|
2243
|
+
return hasNoFilesSignal || hasIgnoredSignal;
|
|
2244
|
+
}
|
|
2172
2245
|
async function runEslint(options) {
|
|
2173
2246
|
const { ESLint } = await import("eslint").catch(() => {
|
|
2174
2247
|
throw new Error(
|
|
@@ -2261,11 +2334,12 @@ async function runEslint(options) {
|
|
|
2261
2334
|
const r = await eslint.lintFiles([pattern]);
|
|
2262
2335
|
allRawResults.push(...r);
|
|
2263
2336
|
} catch (err) {
|
|
2264
|
-
const
|
|
2265
|
-
if (
|
|
2337
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
2338
|
+
if (isSkippablePatternError(error)) {
|
|
2339
|
+
log.debug(`Skipping pattern '${pattern}' (no lintable files)`);
|
|
2266
2340
|
continue;
|
|
2267
2341
|
}
|
|
2268
|
-
throw
|
|
2342
|
+
throw error;
|
|
2269
2343
|
}
|
|
2270
2344
|
}
|
|
2271
2345
|
const rawResults = allRawResults;
|
|
@@ -2308,66 +2382,6 @@ async function runEslint(options) {
|
|
|
2308
2382
|
};
|
|
2309
2383
|
}
|
|
2310
2384
|
|
|
2311
|
-
// cli/utils/logger.ts
|
|
2312
|
-
var import_chalk = __toESM(require("chalk"));
|
|
2313
|
-
var PREFIX = {
|
|
2314
|
-
success: import_chalk.default.green("\u2714"),
|
|
2315
|
-
error: import_chalk.default.red("\u2716"),
|
|
2316
|
-
warn: import_chalk.default.yellow("\u26A0"),
|
|
2317
|
-
info: import_chalk.default.cyan("\u2139"),
|
|
2318
|
-
section: import_chalk.default.bold.white,
|
|
2319
|
-
bullet: import_chalk.default.gray("\u2022")
|
|
2320
|
-
};
|
|
2321
|
-
var log = {
|
|
2322
|
-
info(msg) {
|
|
2323
|
-
console.log(` ${PREFIX.info} ${import_chalk.default.white(msg)}`);
|
|
2324
|
-
},
|
|
2325
|
-
success(msg) {
|
|
2326
|
-
console.log(` ${PREFIX.success} ${import_chalk.default.green(msg)}`);
|
|
2327
|
-
},
|
|
2328
|
-
warn(msg) {
|
|
2329
|
-
console.log(` ${PREFIX.warn} ${import_chalk.default.yellow(msg)}`);
|
|
2330
|
-
},
|
|
2331
|
-
error(msg) {
|
|
2332
|
-
console.error(` ${PREFIX.error} ${import_chalk.default.red(msg)}`);
|
|
2333
|
-
},
|
|
2334
|
-
section(title) {
|
|
2335
|
-
console.log("");
|
|
2336
|
-
console.log(import_chalk.default.bold.cyan(` \u2500\u2500 ${title} \u2500\u2500`));
|
|
2337
|
-
console.log("");
|
|
2338
|
-
},
|
|
2339
|
-
rule(ruleName, count) {
|
|
2340
|
-
console.log(
|
|
2341
|
-
` ${PREFIX.bullet} ${import_chalk.default.yellow(ruleName)} ${import_chalk.default.gray(`(${count} issue${count !== 1 ? "s" : ""})`)}`
|
|
2342
|
-
);
|
|
2343
|
-
},
|
|
2344
|
-
file(filePath, count) {
|
|
2345
|
-
console.log(
|
|
2346
|
-
` ${PREFIX.bullet} ${import_chalk.default.white(filePath)} ${import_chalk.default.gray(`\u2192 ${count} issue${count !== 1 ? "s" : ""}`)}`
|
|
2347
|
-
);
|
|
2348
|
-
},
|
|
2349
|
-
issue(msg, severity, line, col) {
|
|
2350
|
-
const icon = severity === 2 ? import_chalk.default.red("error") : import_chalk.default.yellow(" warn");
|
|
2351
|
-
console.log(
|
|
2352
|
-
` ${import_chalk.default.gray(`${line}:${col}`).padEnd(12)} ${icon} ${import_chalk.default.white(msg)}`
|
|
2353
|
-
);
|
|
2354
|
-
},
|
|
2355
|
-
divider() {
|
|
2356
|
-
console.log(import_chalk.default.gray(" " + "\u2500".repeat(60)));
|
|
2357
|
-
},
|
|
2358
|
-
blank() {
|
|
2359
|
-
console.log("");
|
|
2360
|
-
},
|
|
2361
|
-
banner(title) {
|
|
2362
|
-
console.log("");
|
|
2363
|
-
console.log(import_chalk.default.bold.bgCyan.black(` ${title} `));
|
|
2364
|
-
console.log("");
|
|
2365
|
-
},
|
|
2366
|
-
print(msg) {
|
|
2367
|
-
console.log(msg);
|
|
2368
|
-
}
|
|
2369
|
-
};
|
|
2370
|
-
|
|
2371
2385
|
// cli/commands/run.ts
|
|
2372
2386
|
function registerRunCommand(program2) {
|
|
2373
2387
|
program2.command("run").description("Run ai-guard rules on your project (zero ESLint config required)").option("--path <dir>", "Directory or file to scan", ".").option("--strict", "Use the strict rule preset (all rules at error)").option("--security", "Use the security-only rule preset").option("--json", "Output results as JSON").option("--max-warnings <n>", "Fail if warnings exceed this count", parseInt).action(async (opts) => {
|