eslint-plugin-ai-guard 1.1.2 → 1.1.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/dist/cli/index.js +72 -22
- package/dist/cli/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -2353,8 +2353,12 @@ export default [
|
|
|
2353
2353
|
|
|
2354
2354
|
// ai-guard: catch AI-generated code patterns
|
|
2355
2355
|
{
|
|
2356
|
-
plugins: {
|
|
2357
|
-
|
|
2356
|
+
plugins: {
|
|
2357
|
+
'ai-guard': aiGuard.default,
|
|
2358
|
+
},
|
|
2359
|
+
rules: {
|
|
2360
|
+
...aiGuard.${preset}.rules,
|
|
2361
|
+
},
|
|
2358
2362
|
},
|
|
2359
2363
|
];
|
|
2360
2364
|
`;
|
|
@@ -2384,8 +2388,12 @@ function patchFlatConfig(existing, preset) {
|
|
|
2384
2388
|
const rulesBlock = `
|
|
2385
2389
|
// ai-guard injected by ai-guard CLI
|
|
2386
2390
|
{
|
|
2387
|
-
plugins: {
|
|
2388
|
-
|
|
2391
|
+
plugins: {
|
|
2392
|
+
'ai-guard': aiGuard.default,
|
|
2393
|
+
},
|
|
2394
|
+
rules: {
|
|
2395
|
+
...aiGuard.${preset}.rules,
|
|
2396
|
+
},
|
|
2389
2397
|
},
|
|
2390
2398
|
`;
|
|
2391
2399
|
let patched = existing;
|
|
@@ -2596,14 +2604,14 @@ function registerInitCommand(program2) {
|
|
|
2596
2604
|
} else {
|
|
2597
2605
|
log.info("No ESLint config found \u2014 will generate one");
|
|
2598
2606
|
}
|
|
2599
|
-
|
|
2607
|
+
const eslintNeedsFlat = requiresFlatConfig(env.eslintMajor);
|
|
2608
|
+
if (env.hasConflictingConfigs && !eslintNeedsFlat) {
|
|
2600
2609
|
log.blank();
|
|
2601
2610
|
log.warn("Conflicting configs detected:");
|
|
2602
2611
|
for (const p of env.allConfigPaths) {
|
|
2603
2612
|
log.print(` ${import_chalk3.default.yellow("\u2192")} ${import_chalk3.default.white(import_path3.default.relative(cwd, p))}`);
|
|
2604
2613
|
}
|
|
2605
|
-
log.print(` ${import_chalk3.default.gray("
|
|
2606
|
-
log.print(` ${import_chalk3.default.gray("Consider removing the legacy config to avoid confusion.")}`);
|
|
2614
|
+
log.print(` ${import_chalk3.default.gray("Multiple config formats found \u2014 this can cause unpredictable behavior.")}`);
|
|
2607
2615
|
}
|
|
2608
2616
|
log.blank();
|
|
2609
2617
|
const toInstall = [];
|
|
@@ -2626,8 +2634,21 @@ function registerInitCommand(program2) {
|
|
|
2626
2634
|
process.exit(1);
|
|
2627
2635
|
return;
|
|
2628
2636
|
}
|
|
2637
|
+
try {
|
|
2638
|
+
const { createRequire } = await import("module");
|
|
2639
|
+
const { pathToFileURL } = await import("url");
|
|
2640
|
+
const req = createRequire(import_path3.default.join(cwd, "_probe.js"));
|
|
2641
|
+
const resolvedPath = req.resolve("eslint-plugin-ai-guard");
|
|
2642
|
+
const aiGuard = await import(pathToFileURL(resolvedPath).href);
|
|
2643
|
+
const plugin2 = aiGuard.default || aiGuard;
|
|
2644
|
+
if (!plugin2.default || !plugin2[preset] || !plugin2[preset].rules) {
|
|
2645
|
+
log.error("Invalid plugin export structure. Try reinstalling eslint-plugin-ai-guard.");
|
|
2646
|
+
process.exit(1);
|
|
2647
|
+
return;
|
|
2648
|
+
}
|
|
2649
|
+
} catch (e) {
|
|
2650
|
+
}
|
|
2629
2651
|
const forceFlat = opts.flat === true;
|
|
2630
|
-
const eslintNeedsFlat = requiresFlatConfig(env.eslintMajor);
|
|
2631
2652
|
const existingIsFlat = isFlat(env.configType);
|
|
2632
2653
|
const existingIsLegacy = isLegacy(env.configType);
|
|
2633
2654
|
const useFlat = forceFlat || eslintNeedsFlat || existingIsFlat || env.configType === "none";
|
|
@@ -2636,9 +2657,7 @@ function registerInitCommand(program2) {
|
|
|
2636
2657
|
log.warn(`ESLint v${env.eslintMajor} requires flat config, but a legacy config was found:`);
|
|
2637
2658
|
log.print(` ${import_chalk3.default.white(import_path3.default.relative(cwd, env.configPath))}`);
|
|
2638
2659
|
log.blank();
|
|
2639
|
-
log.print(` ${import_chalk3.default.bold("ai-guard will create a new flat config
|
|
2640
|
-
log.print(` The legacy file will remain; ESLint v9 will automatically`);
|
|
2641
|
-
log.print(` ignore it in favour of the flat config.`);
|
|
2660
|
+
log.print(` ${import_chalk3.default.bold("ai-guard will create a new flat config.")}`);
|
|
2642
2661
|
log.blank();
|
|
2643
2662
|
}
|
|
2644
2663
|
log.section(`Configuring ESLint${isDryRun ? " (dry run)" : ""}`);
|
|
@@ -2713,6 +2732,27 @@ function registerInitCommand(program2) {
|
|
|
2713
2732
|
configWritten = true;
|
|
2714
2733
|
}
|
|
2715
2734
|
}
|
|
2735
|
+
if (eslintNeedsFlat) {
|
|
2736
|
+
const legacyConfigs = env.allConfigPaths.filter((p) => !p.includes("eslint.config."));
|
|
2737
|
+
let cleanedUp = false;
|
|
2738
|
+
for (const p of legacyConfigs) {
|
|
2739
|
+
if (import_fs3.default.existsSync(p)) {
|
|
2740
|
+
if (!isDryRun) {
|
|
2741
|
+
try {
|
|
2742
|
+
import_fs3.default.renameSync(p, `${p}.bak`);
|
|
2743
|
+
cleanedUp = true;
|
|
2744
|
+
} catch (err) {
|
|
2745
|
+
}
|
|
2746
|
+
} else {
|
|
2747
|
+
cleanedUp = true;
|
|
2748
|
+
log.print(` ${import_chalk3.default.gray(`[dry-run] would rename ${import_path3.default.relative(cwd, p)} to ${import_path3.default.basename(p)}.bak`)}`);
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
if (cleanedUp && !isDryRun) {
|
|
2753
|
+
log.success("Legacy config backed up to avoid ESLint conflict");
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2716
2756
|
if (isDryRun) {
|
|
2717
2757
|
log.blank();
|
|
2718
2758
|
log.print(` ${import_chalk3.default.yellow("Dry run complete \u2014 no files written.")}`);
|
|
@@ -2758,6 +2798,10 @@ function registerInitCommand(program2) {
|
|
|
2758
2798
|
log.blank();
|
|
2759
2799
|
log.print(` ${import_chalk3.default.bold("Problem:")}`);
|
|
2760
2800
|
log.print(` ${import_chalk3.default.red(loadError.message)}`);
|
|
2801
|
+
if (loadError.kind === "unknown") {
|
|
2802
|
+
log.blank();
|
|
2803
|
+
log.print(` ${import_chalk3.default.yellow("Generated config may be using incorrect plugin structure.")}`);
|
|
2804
|
+
}
|
|
2761
2805
|
log.blank();
|
|
2762
2806
|
log.print(` ${import_chalk3.default.bold("Fix:")}`);
|
|
2763
2807
|
log.print(` 1. Check the syntax in ${import_chalk3.default.cyan(import_path3.default.relative(cwd, finalConfigPath))}`);
|
|
@@ -2773,7 +2817,15 @@ function registerInitCommand(program2) {
|
|
|
2773
2817
|
log.blank();
|
|
2774
2818
|
log.section("Setup Complete");
|
|
2775
2819
|
log.blank();
|
|
2776
|
-
|
|
2820
|
+
let cleanedUpInfo = false;
|
|
2821
|
+
if (eslintNeedsFlat) {
|
|
2822
|
+
const legacyConfigs = env.allConfigPaths.filter((p) => !p.includes("eslint.config."));
|
|
2823
|
+
cleanedUpInfo = legacyConfigs.some((p) => import_fs3.default.existsSync(`${p}.bak`) && !import_fs3.default.existsSync(p));
|
|
2824
|
+
}
|
|
2825
|
+
const lingeringConflicts = env.hasConflictingConfigs && !eslintNeedsFlat && !cleanedUpInfo;
|
|
2826
|
+
if (loadError === null && !lingeringConflicts) {
|
|
2827
|
+
log.print(` ${import_chalk3.default.green("\u2714")} ${import_chalk3.default.bold.green("Configuration validated successfully")}`);
|
|
2828
|
+
}
|
|
2777
2829
|
log.print(` ${import_chalk3.default.green("\u2714")} ${import_chalk3.default.bold("ESLint config:")} ${import_chalk3.default.cyan(import_path3.default.relative(cwd, finalConfigPath))}`);
|
|
2778
2830
|
log.print(` ${import_chalk3.default.green("\u2714")} ${import_chalk3.default.bold("Mode:")} ${import_chalk3.default.cyan(useFlat ? `Flat config (ESLint v${env.eslintMajor ?? 9})` : `Legacy config (ESLint v${env.eslintMajor ?? 8})`)}`);
|
|
2779
2831
|
log.print(` ${import_chalk3.default.green("\u2714")} ${import_chalk3.default.bold("Preset:")} ${import_chalk3.default.cyan(preset)}`);
|
|
@@ -2861,16 +2913,14 @@ function registerDoctorCommand(program2) {
|
|
|
2861
2913
|
fix: pluginWired ? void 0 : "ai-guard init (will patch your existing config)"
|
|
2862
2914
|
});
|
|
2863
2915
|
}
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
});
|
|
2873
|
-
}
|
|
2916
|
+
checks.push({
|
|
2917
|
+
label: "No conflicting config files",
|
|
2918
|
+
pass: !env.hasConflictingConfigs,
|
|
2919
|
+
detail: env.hasConflictingConfigs ? `Conflicting config detected:
|
|
2920
|
+
${env.allConfigPaths.map((p) => ` ${import_path4.default.relative(cwd, p)}`).join("\n")}` : "Only one config format detected",
|
|
2921
|
+
fix: env.hasConflictingConfigs ? "Remove or backup legacy config" : void 0,
|
|
2922
|
+
note: env.hasConflictingConfigs ? "ESLint v9 silently ignores .eslintrc.* when a flat config exists. This can cause confusion." : void 0
|
|
2923
|
+
});
|
|
2874
2924
|
if (hasConfig && env.hasNukeIgnore) {
|
|
2875
2925
|
checks.push({
|
|
2876
2926
|
label: 'No "ignore everything" pattern',
|