eslint-plugin-ai-guard 1.1.8 → 1.1.10
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 +23 -13
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +446 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +446 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/cli/index.js
CHANGED
|
@@ -79,10 +79,10 @@ export default [
|
|
|
79
79
|
// ai-guard: catch AI-generated code patterns
|
|
80
80
|
{
|
|
81
81
|
plugins: {
|
|
82
|
-
'ai-guard': aiGuard
|
|
82
|
+
'ai-guard': aiGuard,
|
|
83
83
|
},
|
|
84
84
|
rules: {
|
|
85
|
-
...aiGuard.${preset}.rules,
|
|
85
|
+
...aiGuard.configs.${preset}.rules,
|
|
86
86
|
},
|
|
87
87
|
},
|
|
88
88
|
];
|
|
@@ -107,15 +107,19 @@ function isInvalidAiGuardConfig(content) {
|
|
|
107
107
|
if (!content.includes("eslint-plugin-ai-guard") && !content.includes("ai-guard")) {
|
|
108
108
|
return false;
|
|
109
109
|
}
|
|
110
|
-
if (
|
|
111
|
-
if (
|
|
110
|
+
if (/['"]ai-guard['"]\s*:\s*aiGuard\.default/.test(content)) return true;
|
|
111
|
+
if (/\.\.\.aiGuard\.(recommended|strict|security)\.rules/.test(content)) return true;
|
|
112
|
+
if (/rules\s*:\s*aiGuard\.(recommended|strict|security)\.rules/.test(content)) return true;
|
|
112
113
|
return false;
|
|
113
114
|
}
|
|
114
115
|
function repairInvalidFlatConfig(content) {
|
|
115
116
|
let repaired = content;
|
|
116
|
-
repaired = repaired.replace(/(['"]ai-guard['"]\s*:\s*aiGuard
|
|
117
|
-
repaired = repaired.replace(
|
|
118
|
-
|
|
117
|
+
repaired = repaired.replace(/(['"]ai-guard['"]\s*:\s*)aiGuard\.default/g, "$1aiGuard");
|
|
118
|
+
repaired = repaired.replace(
|
|
119
|
+
/rules\s*:\s*aiGuard\.([a-zA-Z0-9_]+)\.rules(,?)/g,
|
|
120
|
+
"rules: {\n ...aiGuard.configs.$1.rules,\n }$2"
|
|
121
|
+
);
|
|
122
|
+
repaired = repaired.replace(/\.\.\.aiGuard\.([a-zA-Z0-9_]+)\.rules/g, "...aiGuard.configs.$1.rules");
|
|
119
123
|
return repaired;
|
|
120
124
|
}
|
|
121
125
|
function patchFlatConfig(existing, preset) {
|
|
@@ -131,10 +135,10 @@ function patchFlatConfig(existing, preset) {
|
|
|
131
135
|
// ai-guard injected by ai-guard CLI
|
|
132
136
|
{
|
|
133
137
|
plugins: {
|
|
134
|
-
'ai-guard': aiGuard
|
|
138
|
+
'ai-guard': aiGuard,
|
|
135
139
|
},
|
|
136
140
|
rules: {
|
|
137
|
-
...aiGuard.${preset}.rules,
|
|
141
|
+
...aiGuard.configs.${preset}.rules,
|
|
138
142
|
},
|
|
139
143
|
},
|
|
140
144
|
`;
|
|
@@ -518,6 +522,13 @@ async function runEslint(options) {
|
|
|
518
522
|
{
|
|
519
523
|
files: ["**/*.js", "**/*.jsx", "**/*.mjs", "**/*.cjs"],
|
|
520
524
|
plugins: { "ai-guard": plugin },
|
|
525
|
+
languageOptions: {
|
|
526
|
+
parserOptions: {
|
|
527
|
+
ecmaVersion: "latest",
|
|
528
|
+
sourceType: "module",
|
|
529
|
+
ecmaFeatures: { jsx: true }
|
|
530
|
+
}
|
|
531
|
+
},
|
|
521
532
|
rules
|
|
522
533
|
},
|
|
523
534
|
// Ignore generated directories
|
|
@@ -939,10 +950,9 @@ function registerInitCommand(program2) {
|
|
|
939
950
|
const resolvedPath = req.resolve("eslint-plugin-ai-guard");
|
|
940
951
|
const aiGuard = await import(pathToFileURL2(resolvedPath).href);
|
|
941
952
|
const plugin = aiGuard.default || aiGuard;
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
return;
|
|
953
|
+
const hasPresetRules = !!plugin.configs && !!plugin.configs[preset] && !!plugin.configs[preset].rules;
|
|
954
|
+
if (!hasPresetRules) {
|
|
955
|
+
log.debug("Plugin precheck could not verify configs shape; continuing to validation step.");
|
|
946
956
|
}
|
|
947
957
|
} catch (e) {
|
|
948
958
|
const reason = e instanceof Error ? e.message : String(e);
|