eslint-plugin-ai-guard 1.3.0 โ†’ 1.3.1

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 CHANGED
@@ -1,457 +1,643 @@
1
- <p align="center">
2
- <img src="./assets/logo.png" alt="AI Guard Logo" width="80" />
3
- <h1 align="center">eslint-plugin-ai-guard</h1>
4
- <p align="center">
5
- <strong>๐Ÿ›ก๏ธ GitHub-native guardrails for AI-generated code.</strong>
6
- </p>
7
- <p align="center">
8
- <a href="https://www.npmjs.com/package/eslint-plugin-ai-guard"><img src="https://img.shields.io/npm/v/eslint-plugin-ai-guard.svg?style=flat-square&color=7c3aed" alt="npm version"></a>
9
- <a href="https://github.com/YashJadhav21/eslint-plugin-ai-guard/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/YashJadhav21/eslint-plugin-ai-guard/ci.yml?style=flat-square&label=CI&color=10b981" alt="CI"></a>
10
- <a href="https://www.npmjs.com/package/eslint-plugin-ai-guard"><img src="https://img.shields.io/npm/dm/eslint-plugin-ai-guard.svg?style=flat-square&color=3b82f6" alt="downloads"></a>
11
- <a href="https://github.com/YashJadhav21/eslint-plugin-ai-guard/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/eslint-plugin-ai-guard.svg?style=flat-square&color=64748b" alt="MIT License"></a>
12
- <a href="https://github.com/YashJadhav21/eslint-plugin-ai-guard/blob/main/SECURITY.md"><img src="https://img.shields.io/badge/security-policy-orange?style=flat-square" alt="Security Policy"></a>
13
- </p>
14
- </p>
15
-
16
- ---
17
-
18
- ## What is ai-guard?
19
-
20
- **ai-guard** is an ESLint plugin and GitHub Action that catches reliability and security bugs
21
- specific to AI-generated code โ€” the patterns Copilot, Claude, Cursor, and Gemini consistently get wrong.
22
-
23
- It integrates directly into GitHub pull request workflows: blocking dangerous merges, generating
24
- SARIF reports for GitHub Code Scanning, and posting inline PR annotations at the exact line where
25
- the bug lives.
26
-
27
- ```bash
28
- # Scan immediately โ€” no config needed
29
- npx ai-guard run
30
-
31
- # PR-aware changed-only scan with GitHub Advanced Security
32
- npx ai-guard changed --sarif --sarif-output results.sarif
33
- ```
34
-
35
- <img src="./assets/ss8.jpg" alt="GitHub PR Inline Annotations by AI Guard" width="1000" />
36
-
37
- ---
38
-
39
- ## The Problem
40
-
41
- AI coding assistants generate code that **looks correct but isn't.** The patterns they get wrong
42
- are consistent, predictable, and existing linters don't catch them:
43
-
44
- | Pattern | Why AI Gets It Wrong |
45
- |---------|---------------------|
46
- | `try {} catch (e) {}` | AI adds catch blocks without handling the error |
47
- | `array.map(async ...)` | AI generates async callbacks returning `Promise[]`, not values |
48
- | `fetch(url)` without await | AI forgets to await or handle promise rejection |
49
- | `const apiKey = 'sk-...'` | AI uses placeholder credentials that get committed |
50
- | `eval(userInput)` | AI generates dynamic evaluation without security context |
51
- | `if (true) { ... }` | AI leaves dead scaffolding branches in generated code |
52
-
53
- ai-guard is purpose-built to catch what AI tools consistently get wrong โ€” before those bugs reach production.
54
-
55
- ---
56
-
57
- ## Install
58
-
59
- ```bash
60
- npm install --save-dev eslint-plugin-ai-guard
61
- ```
62
-
63
- **Requirements:** Node.js โ‰ฅ 18 ยท ESLint โ‰ฅ 8
64
-
65
- ---
66
-
67
- ## Quick Start
68
-
69
- ```bash
70
- # Zero-config project scan
71
- npx ai-guard run
72
-
73
- # Security-focused scan
74
- npx ai-guard run --security
75
-
76
- # Strict mode โ€” all 18 rules at error
77
- npx ai-guard run --strict
78
-
79
- # Scan only changed files (PR-aware)
80
- npx ai-guard changed --pr
81
- ```
82
-
83
- **No configuration required.** ai-guard ships with a production-tuned `recommended` preset.
84
-
85
- ---
86
-
87
- ## GitHub Actions Integration
88
-
89
- Drop this into any repository to get PR validation, SARIF-based Code Scanning, and
90
- GitHub Advanced Security integration in under 5 minutes:
91
-
92
- ```yaml
93
- # .github/workflows/ai-guard.yml
94
- name: AI Guard
95
-
96
- on: [pull_request]
97
-
98
- permissions:
99
- security-events: write
100
- contents: read
101
-
102
- jobs:
103
- scan:
104
- runs-on: ubuntu-latest
105
- steps:
106
- - uses: actions/checkout@v4
107
- with:
108
- fetch-depth: 0 # Required for changed-file detection
109
-
110
- - uses: actions/setup-node@v4
111
- with:
112
- node-version: 20
113
- cache: 'npm'
114
-
115
- - run: npm ci
116
-
117
- - name: Scan changed files
118
- run: |
119
- npx ai-guard changed \
120
- --pr \
121
- --strict \
122
- --sarif \
123
- --sarif-output ai-guard-results.sarif \
124
- --fail-on high
125
-
126
- - name: Upload to GitHub Code Scanning
127
- uses: github/codeql-action/upload-sarif@v3
128
- if: always()
129
- with:
130
- sarif_file: ai-guard-results.sarif
131
- category: ai-guard
132
- ```
133
-
134
- This produces:
135
- - โœ… Inline PR annotations at the exact line of each finding
136
- - โœ… GitHub Advanced Security summary ("17 new alerts including 3 high severity")
137
- - โœ… Persistent alerts in `Security โ†’ Code scanning`
138
- - โœ… PR status check that blocks merges on high-severity findings
139
-
140
- ### Inline PR Annotations
141
- <img src="./assets/ss9.jpg" alt="AI Guard PR Inline Annotations" width="1000" />
142
-
143
- ### GitHub Advanced Security Summary
144
- <img src="./assets/ss10.jpg" alt="GitHub Advanced Security Summary for AI Guard" width="1000" />
145
-
146
- ### GitHub Code Scanning Alerts
147
- <img src="./assets/ss11.jpg" alt="GitHub Code Scanning Alerts List" width="1000" />
148
-
149
- See [`docs/github-actions.md`](./docs/github-actions.md) for the complete workflow reference
150
- including full-scan mode, baseline mode, and SARIF debugging.
151
-
152
- ---
153
-
154
- ## CLI Commands
155
-
156
- | Command | Description |
157
- |---------|-------------|
158
- | `ai-guard run` | Scan your project with the recommended preset |
159
- | `ai-guard run --strict` | All 18 rules at error โ€” for CI enforcement |
160
- | `ai-guard run --security` | Security rules only |
161
- | `ai-guard run --sarif` | Output SARIF for GitHub Code Scanning |
162
- | `ai-guard run --json` | Output results as JSON (CI-friendly) |
163
- | `ai-guard changed --pr` | Scan only files changed in this PR |
164
- | `ai-guard changed --staged` | Scan only staged files (pre-commit hook) |
165
- | `ai-guard init` | Auto-configure ESLint + workflow + agent context |
166
- | `ai-guard init --yes` | Zero-prompt setup โ€” recommended for CI/scripts |
167
- | `ai-guard init-context` | Generate AI agent rules (CLAUDE.md, .cursorrules, etc.) |
168
- | `ai-guard baseline` | Save current issues, track only new ones going forward |
169
- | `ai-guard report` | Generate a shareable HTML report |
170
- | `ai-guard doctor` | Diagnose your ESLint and ai-guard setup |
171
-
172
- ### Fail Strategies
173
-
174
- ```bash
175
- --fail-on errors # Fail on any error-level finding (default)
176
- --fail-on high # Fail only on high-severity findings
177
- --fail-on none # Never fail โ€” always continue
178
- --max-warnings 0 # Fail on any warning
179
- ```
180
-
181
- ### Example Output
182
-
183
- ```
184
- AI GUARD
185
-
186
- Files scanned: 142 ยท Issues in: 7 files ยท Duration: 312ms ยท Preset: strict
187
-
188
- โ”€โ”€ Summary by Category โ”€โ”€
189
-
190
- ๐Ÿ”ด Security 3 errors
191
- ๐ŸŸ  Reliability 2 errors
192
- ๐ŸŸก Async Stability 2 warnings
193
-
194
- Total: 5 errors ยท 2 warnings
195
-
196
- โ”€โ”€ By Rule โ”€โ”€
197
- โ€ข no-hardcoded-secret: 3
198
- โ€ข no-empty-catch: 2
199
- โ€ข no-floating-promise: 2
200
-
201
- โ”€โ”€ Next Steps โ”€โ”€
202
- โ„น Run ai-guard baseline to save these issues and track only new ones
203
- โ„น Run ai-guard report to generate a shareable HTML report
204
- ```
205
-
206
- ---
207
-
208
- ## Rules
209
-
210
- ### ๐Ÿ”ด Security
211
-
212
- | Rule | Recommended | What it catches |
213
- |------|------------|------------------|
214
- | [`no-hardcoded-secret`](./docs/rules/no-hardcoded-secret.md) | **error** | API keys, passwords, tokens in source. Autofix: `process.env.*` |
215
- | [`no-eval-dynamic`](./docs/rules/no-eval-dynamic.md) | **error** | `eval()` / `new Function()` with non-literal args |
216
- | [`no-sql-string-concat`](./docs/rules/no-sql-string-concat.md) | warn | SQL built by string concatenation โ€” SQL injection risk |
217
- | [`no-unsafe-deserialize`](./docs/rules/no-unsafe-deserialize.md) | warn | `JSON.parse(req.body)` without validation |
218
- | [`require-auth-middleware`](./docs/rules/require-auth-middleware.md) | warn | Express/Fastify routes without authentication middleware |
219
- | [`require-authz-check`](./docs/rules/require-authz-check.md) | warn | Resource access without ownership checks |
220
-
221
- ### ๐ŸŸ  Reliability
222
-
223
- | Rule | Recommended | What it catches |
224
- |------|------------|------------------|
225
- | [`no-empty-catch`](./docs/rules/no-empty-catch.md) | **error** | `catch (e) {}` โ€” errors silently vanish. Autofix: inserts TODO |
226
- | [`no-broad-exception`](./docs/rules/no-broad-exception.md) | warn | `catch (e: any)` that hides the real error type |
227
- | [`no-catch-log-rethrow`](./docs/rules/no-catch-log-rethrow.md) | off* | Catch blocks that only `console.log` + rethrow |
228
- | [`no-catch-without-use`](./docs/rules/no-catch-without-use.md) | off* | Caught error variable never used |
229
-
230
- ### ๐ŸŸก Async Stability
231
-
232
- | Rule | Recommended | What it catches |
233
- |------|------------|------------------|
234
- | [`no-floating-promise`](./docs/rules/no-floating-promise.md) | **error** | Async calls with no `await`, return, or `.catch()`. Autofix: adds `void` |
235
- | [`no-async-array-callback`](./docs/rules/no-async-array-callback.md) | warn | `array.map(async ...)` โ€” returns `Promise[]` not values |
236
- | [`no-await-in-loop`](./docs/rules/no-await-in-loop.md) | warn | Sequential `await` in loops โ€” use `Promise.all` |
237
- | [`no-async-without-await`](./docs/rules/no-async-without-await.md) | warn | `async` function that never uses `await` |
238
- | [`no-redundant-await`](./docs/rules/no-redundant-await.md) | off* | `return await` outside try/catch |
239
-
240
- ### ๐Ÿ”ต AI Patterns
241
-
242
- | Rule | Recommended | What it catches |
243
- |------|------------|------------------|
244
- | [`no-dead-branch`](./docs/rules/no-dead-branch.md) | warn | `if (true)`, `if (false)`, `x && !x` โ€” scaffolding leftovers |
245
- | [`no-duplicate-logic-block`](./docs/rules/no-duplicate-logic-block.md) | off* | Consecutive duplicate code blocks |
246
- | [`no-console-in-handler`](./docs/rules/no-console-in-handler.md) | off* | `console.log` in route handlers โ€” use a logger |
247
-
248
- *Enabled at `error` in the `strict` preset.
249
-
250
- Full rule documentation: [`docs/rules/`](./docs/rules/)
251
-
252
- ---
253
-
254
- ## Presets
255
-
256
- | Preset | Purpose | Best For |
257
- |--------|---------|----------|
258
- | `recommended` | Critical issues at `error`, context-sensitive at `warn` | All projects on day one |
259
- | `strict` | All 18 rules at `error` | CI enforcement in mature codebases |
260
- | `security` | Security rules only | Security-focused scanning |
261
-
262
- ### ESLint Flat Config
263
-
264
- ```javascript
265
- // eslint.config.mjs
266
- import aiGuard from 'eslint-plugin-ai-guard';
267
-
268
- export default [
269
- {
270
- plugins: { 'ai-guard': aiGuard },
271
- rules: { ...aiGuard.configs.recommended.rules },
272
- },
273
- ];
274
- ```
275
-
276
- ---
277
-
278
- ## AI Agent Integration
279
-
280
- Generate instruction files so **Claude Code, Cursor, and GitHub Copilot** automatically avoid
281
- the 18 most common AI-generated anti-patterns at generation time:
282
-
283
- ```bash
284
- npx ai-guard init-context
285
- ```
286
-
287
- This writes:
288
- - `CLAUDE.md` โ€” loaded automatically by Claude Code
289
- - `.cursorrules` โ€” loaded automatically by Cursor
290
- - `.github/copilot-instructions.md` โ€” loaded automatically by GitHub Copilot
291
-
292
- Your AI tools will avoid these patterns **before you even run the linter.**
293
-
294
- See [`docs/ai-agents.md`](./docs/ai-agents.md) for the complete integration guide.
295
-
296
- ---
297
-
298
- ## Real-World Example
299
-
300
- ```typescript
301
- // โŒ Typical AI-generated code โ€” 4 issues in one function
302
- async function processUserOrders(userId: string) {
303
- const apiKey = 'sk-prod-1234567890abcdef'; // no-hardcoded-secret
304
-
305
- const orders = await db.query(
306
- 'SELECT * FROM orders WHERE id = ' + userId // no-sql-string-concat
307
- );
308
-
309
- for (const order of orders) {
310
- await sendEmail(order.email); // no-await-in-loop
311
- }
312
-
313
- updateAnalytics(userId); // no-floating-promise
314
- }
315
-
316
- // โœ… After ai-guard fixes
317
- async function processUserOrders(userId: string) {
318
- const apiKey = process.env.API_KEY;
319
-
320
- const orders = await db.query(
321
- 'SELECT * FROM orders WHERE id = $1', [userId]
322
- );
323
-
324
- await Promise.all(orders.map(async (order) => sendEmail(order.email)));
325
-
326
- void updateAnalytics(userId);
327
- }
328
- ```
329
-
330
- ---
331
-
332
- ## Autofix Support
333
-
334
- ```bash
335
- npx eslint src --fix
336
- ```
337
-
338
- | Rule | What Gets Fixed |
339
- |------|-----------------|
340
- | `no-hardcoded-secret` | Literal โ†’ `process.env.VAR_NAME` |
341
- | `no-empty-catch` | Inserts `/* TODO: handle error */` |
342
- | `no-floating-promise` | Marks with `void` |
343
- | `no-await-in-loop` | Rewrites simple loops to `Promise.all(...)` |
344
- | `no-async-without-await` | Removes unnecessary `async` keyword |
345
-
346
- ---
347
-
348
- ## Philosophy
349
-
350
- - **Precision over recall** โ€” we'd rather miss a bug than create noise
351
- - **Low false positives** โ€” a rule that fires on valid code goes to `warn` or gets disabled
352
- - **Gradual adoption** โ€” `recommended` is safe for day-one; `strict` is opt-in
353
- - **Self-validating** โ€” ai-guard scans its own source in CI with the strict preset
354
- - **GitHub-native** โ€” SARIF output, Code Scanning, PR annotations are first-class features
355
-
356
- ---
357
-
358
- ## Development
359
-
360
- ```bash
361
- git clone https://github.com/YashJadhav21/eslint-plugin-ai-guard.git
362
- cd eslint-plugin-ai-guard
363
- npm install
364
- npm run test # 678 tests across 39 test files
365
- npm run build # Build CJS + ESM bundles
366
- npm run typecheck # TypeScript strict check
367
- npm run lint:self # Scan own source with ai-guard
368
- npm run lint:full # Strict scan of src/ + cli/
369
- ```
370
-
371
- See [CONTRIBUTING.md](CONTRIBUTING.md) for the full development guide.
372
-
373
- ---
374
-
375
- ## Documentation
376
-
377
- | Doc | Purpose |
378
- |-----|---------|
379
- | [`docs/github-actions.md`](./docs/github-actions.md) | GitHub Actions workflow reference |
380
- | [`docs/ai-agents.md`](./docs/ai-agents.md) | AI agent integration guide |
381
- | [`docs/architecture.md`](./docs/architecture.md) | Architecture and internals |
382
- | [`docs/benchmarks.md`](./docs/benchmarks.md) | Benchmarks vs ESLint, @typescript-eslint |
383
- | [`docs/rules/`](./docs/rules/) | Per-rule documentation |
384
- | [`CONTRIBUTING.md`](./CONTRIBUTING.md) | Contribution guide |
385
- | [`SECURITY.md`](./SECURITY.md) | Security policy |
386
- | [`CHANGELOG.md`](./CHANGELOG.md) | Release history |
387
- | [`ROADMAP.md`](./ROADMAP.md) | Planned features |
388
-
389
- ---
390
-
391
- ## FAQ
392
-
393
- <details>
394
- <summary><strong>Is ai-guard a replacement for ESLint?</strong></summary>
395
-
396
- No. ai-guard runs *on top of* ESLint. It adds 18 rules specifically tuned for AI-generated
397
- code patterns. Your existing ESLint rules continue to work as normal.
398
- </details>
399
-
400
- <details>
401
- <summary><strong>Does ai-guard require TypeScript type information?</strong></summary>
402
-
403
- No. All rules use AST heuristics, not type analysis. This makes ai-guard faster than
404
- type-aware linters and zero-config for JavaScript projects. See
405
- [benchmarks](./docs/benchmarks.md) for performance comparison.
406
- </details>
407
-
408
- <details>
409
- <summary><strong>Will ai-guard slow down my CI?</strong></summary>
410
-
411
- Typically adds 1โ€“2 seconds to a CI run. Changed-only mode (`ai-guard changed --pr`)
412
- is even faster because it only scans files modified in the PR.
413
- </details>
414
-
415
- <details>
416
- <summary><strong>How do I reduce false positives?</strong></summary>
417
-
418
- Start with `recommended` preset (default). The `strict` preset enables all rules,
419
- which may be noisy for some codebases. You can also:
420
- - Use `ai-guard baseline` to ignore pre-existing issues
421
- - Configure per-rule options (e.g., `allowedLoggers` for `no-console-in-handler`)
422
- - Use `// eslint-disable-next-line ai-guard/rule-name` for intentional overrides
423
- </details>
424
-
425
- <details>
426
- <summary><strong>Does ai-guard work with Copilot / Cursor / Claude Code?</strong></summary>
427
-
428
- Yes โ€” in two ways:
429
- 1. **Lint after generation**: ai-guard catches issues after AI generates code
430
- 2. **Prevent before generation**: `ai-guard init-context` creates instruction files
431
- (CLAUDE.md, .cursorrules) that teach AI agents to avoid these patterns
432
- </details>
433
-
434
- ---
435
-
436
- ## Troubleshooting
437
-
438
- | Symptom | Fix |
439
- |---------|-----|
440
- | `Cannot find module 'eslint-plugin-ai-guard'` | Run `npm install --save-dev eslint-plugin-ai-guard` |
441
- | Config parse errors after `init` | Run `ai-guard doctor` to diagnose |
442
- | SARIF upload fails in GitHub Actions | Ensure `permissions: security-events: write` is set |
443
- | Too many findings in strict mode | Switch to `recommended` preset or use `ai-guard baseline` |
444
- | Rules not firing on `.ts` files | Install `@typescript-eslint/parser` |
445
- | `ai-guard init` skips workflow/context | Use `ai-guard init --yes` for zero-prompt setup |
446
-
447
- ---
448
-
449
- ## License
450
-
451
- [MIT](LICENSE) โ€” free forever. No rules behind a paywall.
452
-
453
- ---
454
-
455
- <p align="center">
456
- Built to make AI-assisted development reliable and trustworthy. โšก
457
- </p>
1
+ <p align="center">
2
+ <a href="https://getaiguard.dev">
3
+ <img src="./assets/logo/ai-guard-logo.png" alt="AI Guard Logo" width="260" />
4
+ </a>
5
+ </p>
6
+
7
+ <h1 align="center">AI Guard</h1>
8
+
9
+ <p align="center">
10
+ <strong>Deterministic AST safety layer and CI guardrails for AI-assisted JavaScript and TypeScript code.</strong>
11
+ </p>
12
+
13
+ <p align="center">
14
+ <a href="https://getaiguard.dev"><strong>Website</strong></a> &nbsp;โ€ข&nbsp;
15
+ <a href="https://www.npmjs.com/package/eslint-plugin-ai-guard"><strong>npm Package</strong></a> &nbsp;โ€ข&nbsp;
16
+ <a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard"><strong>GitHub Repository</strong></a> &nbsp;โ€ข&nbsp;
17
+ <a href="./docs/rules/"><strong>Rules Catalog</strong></a> &nbsp;โ€ข&nbsp;
18
+ <a href="./docs/benchmarks.md"><strong>Benchmarks</strong></a> &nbsp;โ€ข&nbsp;
19
+ <a href="./docs/integrations/claude-code.md"><strong>Claude Code</strong></a> &nbsp;โ€ข&nbsp;
20
+ <a href="./docs/getting-started.md"><strong>Documentation</strong></a>
21
+ </p>
22
+
23
+ <p align="center">
24
+ <a href="https://www.npmjs.com/package/eslint-plugin-ai-guard"><img src="https://img.shields.io/npm/v/eslint-plugin-ai-guard.svg?style=flat-square&color=0284c7" alt="npm version"></a>
25
+ <a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/ai-guard-dev/eslint-plugin-ai-guard/ci.yml?style=flat-square&label=CI&color=10b981" alt="CI Status"></a>
26
+ <a href="https://www.npmjs.com/package/eslint-plugin-ai-guard"><img src="https://img.shields.io/npm/dm/eslint-plugin-ai-guard.svg?style=flat-square&color=3b82f6" alt="npm downloads"></a>
27
+ <a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-64748b?style=flat-square" alt="MIT License"></a>
28
+ <a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard/blob/main/SECURITY.md"><img src="https://img.shields.io/badge/security-policy-orange?style=flat-square" alt="Security Policy"></a>
29
+ <a href="https://getaiguard.dev"><img src="https://img.shields.io/badge/website-getaiguard.dev-0ea5e9?style=flat-square" alt="Website"></a>
30
+ </p>
31
+
32
+ ---
33
+
34
+ ## What is AI Guard?
35
+
36
+ **AI Guard** (`eslint-plugin-ai-guard`) is a deterministic ESLint plugin, CLI, and GitHub Action engineered to detect reliability bugs, async hazards, security vulnerabilities, and code-scaffolding defects frequently introduced during AI-assisted development (GitHub Copilot, Cursor, Claude Code, Gemini Code Assist, etc.).
37
+
38
+ AI Guard analyzes Abstract Syntax Trees (AST) using ESLint's native engine. It runs locally in your editor, in your terminal via the zero-config CLI, and in your CI/CD pipelines via native SARIF 2.1.0 integration with GitHub Code Scanning.
39
+
40
+ ### What AI Guard is NOT
41
+
42
+ > [!IMPORTANT]
43
+ > - **AI Guard is NOT an AI detector.** It does not attempt to predict whether code was authored by an LLM or a human.
44
+ > - **AI Guard detects dangerous or fragile code patterns** that LLMs repeatedly introduce due to incomplete context, hallucinated patterns, or probabilistic generation.
45
+ > - **AI Guard does NOT replace ESLint.** It extends ESLint with 18 specialized, high-impact rules that core ESLint and standard configurations omit.
46
+
47
+ ---
48
+
49
+ ## Why AI Guard?
50
+
51
+ AI coding assistants write code at remarkable velocity, but generated code repeatedly suffers from predictable reliability and security anti-patterns that conventional linters miss:
52
+
53
+ | Pattern | Why AI Assistants Generate It | Real-World Impact |
54
+ | :--- | :--- | :--- |
55
+ | **Floating Promises** | Omits `await`, `return`, or `.catch()` on async calls | Unhandled promise rejections, silent failures in background jobs |
56
+ | **Async Array Iteration** | Passes async callbacks into `array.map()` or `.filter()` | Returns unawaited `Promise[]` instead of resolved values |
57
+ | **Sequential Awaits in Loops** | Loops over items with sequential `await` | Significant latency bottlenecks; blocks event loop execution |
58
+ | **Empty Catch Blocks** | Inserts generic `try { ... } catch (e) {}` blocks | Swallows production exceptions silently without telemetry |
59
+ | **Hardcoded Secrets** | Injects placeholder or real API keys/tokens | Credential leakage in version control and deployment bundles |
60
+ | **Dynamic `eval()`** | Generates dynamic function compilation | Arbitrary code execution and code injection |
61
+ | **Raw SQL Concatenation** | Concatenates query strings with variables | Severe SQL injection vulnerabilities |
62
+ | **Unsafe Deserialization** | Calls `JSON.parse(req.body)` directly without schema checks | Denial of service and unhandled runtime crashes |
63
+ | **Missing Route Auth & Authz** | Emits boilerplate endpoints without auth middleware | Unprotected API endpoints and IDOR privilege escalations |
64
+ | **Dead Branches & Scaffolding** | Leaves `if (true)` or conflicting conditions from prompt iterations | Bloated bundles and dead code paths |
65
+
66
+ AI Guard provides an instantaneous, deterministic feedback loop that catches these issues before they reach pull requests or production.
67
+
68
+ ---
69
+
70
+ ## Architecture & Workflow
71
+
72
+ ```mermaid
73
+ flowchart TD
74
+ subgraph Dev["1. Development & Prompt Phase"]
75
+ A["Developer + AI Coding Assistant\n(Copilot, Cursor, Claude Code)"] --> B["JavaScript / TypeScript Code"]
76
+ end
77
+
78
+ subgraph ShiftLeft["Shift Left โ€” Context Injection"]
79
+ SL["npx ai-guard init-context"] -.-> CTX["CLAUDE.md\n.cursorrules\ncopilot-instructions.md"]
80
+ CTX -.-> A
81
+ end
82
+
83
+ subgraph Analysis["2. Deterministic AST Analysis"]
84
+ B --> C["ESLint Parser\n(espree / @typescript-eslint/parser)"]
85
+ C --> D["AST Representation"]
86
+ D --> E["AI Guard Rules Engine\n(18 Deterministic Rules)"]
87
+ end
88
+
89
+ subgraph Tiers["3. Classification & Presets"]
90
+ E --> F{"Active Preset\n(recommended | strict | security)"}
91
+ F --> G["Confidence Tiering & AST Filtering"]
92
+ end
93
+
94
+ subgraph Outputs["4. Output & Remediation"]
95
+ G --> H["Local CLI Scanning\n(ai-guard run / changed)"]
96
+ G --> I["Autofix Remediation\n(eslint --fix)"]
97
+ G --> J["HTML Dashboard\n(ai-guard report)"]
98
+ G --> K["SARIF 2.1.0 Artifact\n(ai-guard --sarif)"]
99
+ end
100
+
101
+ subgraph CI["5. GitHub Pull Request & CI/CD"]
102
+ K --> L["GitHub Action\nai-guard-dev/eslint-plugin-ai-guard@v1"]
103
+ L --> M["GitHub Code Scanning Alerts"]
104
+ L --> N["Inline PR Code Annotations"]
105
+ L --> O["PR Status Check (Blocks Merge)"]
106
+ end
107
+ ```
108
+
109
+ ---
110
+
111
+ ## Rules Catalog
112
+
113
+ AI Guard includes **18 deterministic rules** divided into four specialized categories. Every rule is engineered with low false-positive heuristics and validated against real-world production codebases:
114
+
115
+ ### ๐Ÿ”ด Security (6 Rules)
116
+
117
+ | Rule | Recommended | What It Catches | Fixable? |
118
+ | :--- | :---: | :--- | :---: |
119
+ | [`no-hardcoded-secret`](./docs/rules/no-hardcoded-secret.md) | **`error`** | API keys, bearer tokens, passwords, and private keys committed directly in source code. | **Yes** (`process.env.*`) |
120
+ | [`no-eval-dynamic`](./docs/rules/no-eval-dynamic.md) | **`error`** | `eval()`, `new Function()`, and `setTimeout`/`setInterval` with dynamic/non-literal string expressions. | No |
121
+ | [`no-sql-string-concat`](./docs/rules/no-sql-string-concat.md) | `warn` | SQL queries constructed by string concatenation or raw template literals โ€” SQL injection risks. | No |
122
+ | [`no-unsafe-deserialize`](./docs/rules/no-unsafe-deserialize.md) | `warn` | Unchecked `JSON.parse()` called directly on HTTP request inputs (`req.body`, `req.query`, `req.params`). | No |
123
+ | [`require-auth-middleware`](./docs/rules/require-auth-middleware.md) | `warn` | Express and Fastify route definitions exposed without authentication middleware. | No |
124
+ | [`require-authz-check`](./docs/rules/require-authz-check.md) | `warn` | Endpoints accessing sensitive resources or user IDs without tenant/ownership authorization checks. | No |
125
+
126
+ ### ๐ŸŸ  Reliability (4 Rules)
127
+
128
+ | Rule | Recommended | What It Catches | Fixable? |
129
+ | :--- | :---: | :--- | :---: |
130
+ | [`no-empty-catch`](./docs/rules/no-empty-catch.md) | **`error`** | Empty `catch (e) {}` blocks that silently swallow exceptions without logging or rethrowing. | **Yes** (inserts `/* TODO: handle error */`) |
131
+ | [`no-broad-exception`](./docs/rules/no-broad-exception.md) | `warn` | Catching broad exception types like `catch (e: any)` that mask system faults and typing. | No |
132
+ | [`no-catch-log-rethrow`](./docs/rules/no-catch-log-rethrow.md) | `off`* | Catch blocks that only log to `console` and rethrow without adding context or diagnostic info. | No |
133
+ | [`no-catch-without-use`](./docs/rules/no-catch-without-use.md) | `off`* | Caught error variables that are declared in catch parameters but never referenced. | No |
134
+
135
+ ### ๐ŸŸก Async Stability (5 Rules)
136
+
137
+ | Rule | Recommended | What It Catches | Fixable? |
138
+ | :--- | :---: | :--- | :---: |
139
+ | [`no-floating-promise`](./docs/rules/no-floating-promise.md) | **`error`** | Async function invocations without `await`, `.catch()`, or `return` โ€” leading to silent dropped errors. | **Yes** (marks with `void`) |
140
+ | [`no-async-array-callback`](./docs/rules/no-async-array-callback.md) | `warn` | Async callbacks passed to `map()`, `filter()`, `forEach()`, or `reduce()` returning `Promise[]`. | No |
141
+ | [`no-await-in-loop`](./docs/rules/no-await-in-loop.md) | `warn` | Sequential `await` in loops where iterations can be safely executed concurrently with `Promise.all`. | **Yes** (rewrites to `Promise.all`) |
142
+ | [`no-async-without-await`](./docs/rules/no-async-without-await.md) | `warn` | Functions declared `async` that never execute an `await` expression, adding unnecessary Promise overhead. | No |
143
+ | [`no-redundant-await`](./docs/rules/no-redundant-await.md) | `off`* | Redundant `return await` statements outside of `try...catch` blocks. | No |
144
+
145
+ ### ๐Ÿ”ต AI Patterns (3 Rules)
146
+
147
+ | Rule | Recommended | What It Catches | Fixable? |
148
+ | :--- | :---: | :--- | :---: |
149
+ | [`no-dead-branch`](./docs/rules/no-dead-branch.md) | `warn` | Unreachable or tautological branches (`if (true)`, `if (false)`, `x && !x`) left behind from LLM code synthesis. | No |
150
+ | [`no-duplicate-logic-block`](./docs/rules/no-duplicate-logic-block.md) | `off`* | Consecutive duplicate code blocks or repeated conditional branches duplicated during AI edits. | No |
151
+ | [`no-console-in-handler`](./docs/rules/no-console-in-handler.md) | `off`* | Unstructured `console.log` statements left in HTTP route handlers instead of production loggers. | No |
152
+
153
+ *\* Enabled at `error` level in the `strict` preset.*
154
+
155
+ ---
156
+
157
+ ## Presets
158
+
159
+ AI Guard exports four official configurations ready for flat config or legacy setups:
160
+
161
+ | Preset | Description | Configuration Focus |
162
+ | :--- | :--- | :--- |
163
+ | **`recommended`** | **Default.** Balanced adoption preset. Enables 4 high-confidence critical rules at `error`, 9 context-sensitive rules at `warn`, and disables 5 noisy rules. Zero noise on day one. | Production codebases, new teams |
164
+ | **`strict`** | Enforces **all 18 rules at `error`**. Designed for zero-tolerance CI gates, high-assurance software, and mature teams. | Strict CI/CD quality gates |
165
+ | **`security`** | Focuses exclusively on the **6 security rules** (`no-hardcoded-secret`, `no-eval-dynamic`, `no-sql-string-concat` at `error`; remainder at `warn`). | AppSec auditing & security scans |
166
+ | **`agent`** | **5 high-signal rules at `error`**. Optimized for AI-agent editing workflows where lint feedback runs immediately after each file edit (e.g., PostToolUse hooks). | Claude Code, Cursor, real-time agent loops |
167
+
168
+ ---
169
+
170
+ ## Quick Start & Installation
171
+
172
+ Install the package as a development dependency using your package manager:
173
+
174
+ ```bash
175
+ # npm
176
+ npm install --save-dev eslint-plugin-ai-guard
177
+
178
+ # pnpm
179
+ pnpm add -D eslint-plugin-ai-guard
180
+
181
+ # yarn
182
+ yarn add -D eslint-plugin-ai-guard
183
+
184
+ # bun
185
+ bun add -d eslint-plugin-ai-guard
186
+ ```
187
+
188
+ ### Requirements
189
+
190
+ - **Node.js:** `>= 20.0.0`
191
+ - **ESLint:** `>= 8.0.0` (Supports both Flat Config and legacy configs)
192
+ - **TypeScript (optional):** `@typescript-eslint/parser >= 6.0.0` for TypeScript AST parsing
193
+
194
+ ---
195
+
196
+ ## ESLint Configuration
197
+
198
+ ### 1. Modern Flat Config (`eslint.config.mjs` / `eslint.config.js`)
199
+
200
+ AI Guard exports full native support for modern ESLint Flat Config:
201
+
202
+ ```javascript
203
+ // eslint.config.mjs
204
+ import aiGuard from 'eslint-plugin-ai-guard';
205
+
206
+ export default [
207
+ {
208
+ plugins: {
209
+ 'ai-guard': aiGuard,
210
+ },
211
+ rules: {
212
+ ...aiGuard.configs.recommended.rules,
213
+ // Custom overrides if desired:
214
+ 'ai-guard/no-floating-promise': 'error',
215
+ },
216
+ },
217
+ ];
218
+ ```
219
+
220
+ To use the `strict` or `security` preset in flat config:
221
+
222
+ ```javascript
223
+ // Strict preset โ€” all 18 rules at error
224
+ rules: {
225
+ ...aiGuard.configs.strict.rules,
226
+ }
227
+
228
+ // Security preset โ€” security rules only
229
+ rules: {
230
+ ...aiGuard.configs.security.rules,
231
+ }
232
+ ```
233
+
234
+ ### 2. Legacy Config (`.eslintrc.js` / `.eslintrc.json`)
235
+
236
+ ```javascript
237
+ // .eslintrc.js
238
+ module.exports = {
239
+ plugins: ['ai-guard'],
240
+ extends: ['plugin:ai-guard/recommended'],
241
+ };
242
+ ```
243
+
244
+ ---
245
+
246
+ ## CLI Reference
247
+
248
+ AI Guard includes a full-featured CLI binary (`ai-guard`) that runs out of the box with zero ESLint configuration files required:
249
+
250
+ ```bash
251
+ npx ai-guard <command> [options]
252
+ ```
253
+
254
+ ### Core Commands
255
+
256
+ | Command | Purpose | Common Options |
257
+ | :--- | :--- | :--- |
258
+ | `run` | Scan your workspace using AI Guard AST rules | `--path <dir>`, `--strict`, `--security`, `--json`, `--sarif`, `--fail-on <level>`, `--max-warnings <n>` |
259
+ | `changed` | Fast CI scan โ€” only scans modified files in git | `--pr`, `--staged`, `--base <branch>`, `--strict`, `--sarif`, `--sarif-output <file>`, `--fail-on <level>` |
260
+ | `init` | Automatically detect environment & configure ESLint | `--preset <name>`, `--flat`, `--dry-run`, `-y, --yes` |
261
+ | `init-context` | Generate prompt instruction files for AI coding agents | `-a, --all`, `--force`, `--dry-run`, `--rules <categories>` |
262
+ | `doctor` | Diagnose your ESLint, parser, and plugin environment | (No options needed โ€” prints actionable diagnostic report) |
263
+ | `baseline` | Snapshot current issues to track only new regressions | `--save`, `--check`, `--mode <strict\|stable>`, `--preset <name>` |
264
+ | `report` | Generate an interactive standalone HTML audit report | `--path <dir>`, `--preset <name>`, `--output <file>`, `--no-open`, `--json` |
265
+ | `preset` | Interactively select and switch active preset in config | (Interactive prompt with automatic config patch & backup) |
266
+ | `ignore` | Add standard ignore paths (`.next`, `dist`, `build`) to config | (Patches flat config or legacy ignores safely) |
267
+
268
+ ### CLI Usage Examples
269
+
270
+ ```bash
271
+ # 1. Immediate scan of current directory
272
+ npx ai-guard run
273
+
274
+ # 2. Strict CI scan failing only on high-confidence issues
275
+ npx ai-guard run --strict --fail-on high
276
+
277
+ # 3. Pull Request scan (diffs against PR target branch)
278
+ npx ai-guard changed --pr --sarif --sarif-output results.sarif
279
+
280
+ # 4. Generate AI agent guardrails for Cursor, Claude Code, and Copilot
281
+ npx ai-guard init-context --all
282
+
283
+ # 5. Generate interactive HTML diagnostic report
284
+ npx ai-guard report --output ai-guard-report.html
285
+
286
+ # 6. Save existing issues as baseline and only fail on new regressions
287
+ npx ai-guard baseline --save
288
+ npx ai-guard baseline --check
289
+ ```
290
+
291
+ ---
292
+
293
+ ## AI Agent Integration (`init-context`)
294
+
295
+ Standard linters only run **after** code has already been written. The `init-context` command shifts your guardrails left by embedding AI Guard's rules directly into the instruction files loaded by your AI coding tools:
296
+
297
+ ```bash
298
+ npx ai-guard init-context --all
299
+ ```
300
+
301
+ This generates three targeted context files:
302
+ 1. **`CLAUDE.md`** โ€” Automatically loaded by **Claude Code**
303
+ 2. **`.cursorrules`** โ€” Automatically loaded by **Cursor**
304
+ 3. **`.github/copilot-instructions.md`** โ€” Automatically loaded by **GitHub Copilot**
305
+
306
+ ### How Shift-Left Works
307
+
308
+ ```
309
+ AI Guard (init-context)
310
+ โ†“
311
+ Generates project guardrail files (CLAUDE.md, .cursorrules, copilot-instructions.md)
312
+ โ†“
313
+ AI coding assistant reads safety rules before generating code
314
+ โ†“
315
+ Model avoids floating promises, empty catches, and hardcoded secrets at prompt time
316
+ โ†“
317
+ AI Guard CLI & GitHub Action deterministically verifies the output in CI
318
+ ```
319
+
320
+ This dual-layer defense minimizes review friction and ensures generated code meets your security standard on the first pass.
321
+
322
+ ---
323
+
324
+ ## Claude Code Integration
325
+
326
+ AI Guard integrates directly with [Claude Code](https://docs.anthropic.com/en/docs/claude-code) as a **PostToolUse validation hook**. Every time Claude Code edits or writes a JS/TS file, AI Guard automatically scans it for common issues.
327
+
328
+ ```bash
329
+ # One-command setup
330
+ npx ai-guard init-claude
331
+ ```
332
+
333
+ This configures a PostToolUse hook in `.claude/settings.json` that runs AI Guard's fast `agent` preset (5 high-confidence rules, ~50-200ms per file) after every file edit. Claude Code reads the diagnostics and can fix issues automatically.
334
+
335
+ ```bash
336
+ # Preview before applying
337
+ npx ai-guard init-claude --dry-run
338
+
339
+ # Use per-machine settings (gitignored)
340
+ npx ai-guard init-claude --local
341
+ ```
342
+
343
+ **Agent preset rules:** `no-hardcoded-secret`, `no-eval-dynamic`, `no-empty-catch`, `no-sql-string-concat`, `no-floating-promise`
344
+
345
+ โ†’ [Full documentation](./docs/integrations/claude-code.md)
346
+
347
+ ---
348
+
349
+ ## GitHub Action
350
+
351
+ The official AI Guard GitHub Action runs on PRs, detects changed files, provides step summaries, outputs SARIF 2.1.0, and posts inline PR annotations directly on GitHub:
352
+
353
+ ```yaml
354
+ # .github/workflows/ai-guard.yml
355
+ name: AI Guard
356
+
357
+ on:
358
+ pull_request:
359
+ branches: [main, develop]
360
+ push:
361
+ branches: [main]
362
+
363
+ jobs:
364
+ ai-guard-scan:
365
+ name: AI Guard Code Review
366
+ runs-on: ubuntu-latest
367
+
368
+ permissions:
369
+ contents: read
370
+ security-events: write
371
+ actions: read
372
+
373
+ steps:
374
+ - name: Checkout Code
375
+ uses: actions/checkout@v4
376
+ with:
377
+ fetch-depth: 0 # Required for git diff comparison
378
+
379
+ - name: Setup Node.js
380
+ uses: actions/setup-node@v4
381
+ with:
382
+ node-version: 20
383
+ cache: 'npm'
384
+
385
+ - name: Run AI Guard
386
+ uses: ai-guard-dev/eslint-plugin-ai-guard@v1
387
+ with:
388
+ preset: 'recommended'
389
+ fail-on: 'high'
390
+ changed-only: 'true'
391
+ upload-sarif: 'true'
392
+ ```
393
+
394
+ ### Action Inputs (`action.yml`)
395
+
396
+ | Input | Description | Default |
397
+ | :--- | :--- | :---: |
398
+ | `preset` | Rule preset: `recommended` \| `strict` \| `security` | `'recommended'` |
399
+ | `fail-on` | Severity threshold to fail CI: `high` \| `medium` \| `any` \| `none` | `'high'` |
400
+ | `changed-only` | Scan only files changed in this PR / commit | `'true'` |
401
+ | `path` | Target file or directory to scan | `'.'` |
402
+ | `upload-sarif` | Upload results to GitHub Code Scanning | `'true'` |
403
+ | `github-summary` | Write an execution breakdown to the GitHub Actions Job Summary | `'true'` |
404
+ | `working-directory`| Working directory for scanning (ideal for monorepos) | `'.'` |
405
+ | `package-manager` | Package manager: `auto` \| `npm` \| `pnpm` \| `yarn` | `'auto'` |
406
+ | `sarif-output` | Output filepath for generated SARIF report | `'ai-guard-results.sarif'` |
407
+ | `install-deps` | Install project dependencies prior to scanning | `'true'` |
408
+
409
+ ### Action Outputs
410
+
411
+ | Output | Description |
412
+ | :--- | :--- |
413
+ | `issues-found` | Total number of issues found across scanned files |
414
+ | `high-confidence-count` | Number of high-confidence issues flagged |
415
+ | `medium-confidence-count` | Number of medium-confidence issues flagged |
416
+ | `files-scanned` | Count of files analyzed during the execution |
417
+ | `sarif-file` | Absolute path to the generated SARIF 2.1.0 artifact |
418
+ | `duration-ms` | Total scan execution duration in milliseconds |
419
+
420
+ ---
421
+
422
+ ## SARIF & GitHub Code Scanning
423
+
424
+ AI Guard natively outputs **SARIF 2.1.0** (`Static Analysis Results Interchange Format`). When uploaded via the GitHub Action or `github/codeql-action/upload-sarif@v3`, findings integrate directly with GitHub Advanced Security:
425
+
426
+ - **Inline PR Annotations:** Direct comments on the exact source lines where flaws exist.
427
+ - **Security Dashboard:** Persistent alerts under your repository's `Security โ†’ Code scanning` tab.
428
+ - **Merge Protection:** Block merges automatically when high-confidence security or async bugs are detected.
429
+
430
+ ### Visual Previews
431
+
432
+ #### Inline Pull Request Annotations
433
+ <img src="./assets/ss9.jpg" alt="AI Guard PR Inline Annotations" width="1000" />
434
+
435
+ #### GitHub Advanced Security Summary
436
+ <img src="./assets/ss10.jpg" alt="GitHub Advanced Security Summary for AI Guard" width="1000" />
437
+
438
+ #### Persistent Code Scanning Dashboard
439
+ <img src="./assets/ss11.jpg" alt="GitHub Code Scanning Alerts List" width="1000" />
440
+
441
+ ---
442
+
443
+ ## Rule Examples (Before & After)
444
+
445
+ ### 1. `no-floating-promise` (Unhandled Promises)
446
+
447
+ ```typescript
448
+ // โŒ BAD: Floating promise. Errors are dropped silently.
449
+ async function syncUserProfile(user: User) {
450
+ sendTelemetryEvent('user_sync', user.id);
451
+ database.save(user);
452
+ }
453
+
454
+ // โœ… GOOD: Awaited, explicitly handled, or marked with void
455
+ async function syncUserProfile(user: User) {
456
+ await database.save(user);
457
+ void sendTelemetryEvent('user_sync', user.id); // Explicitly unhandled
458
+ }
459
+ ```
460
+
461
+ ### 2. `no-hardcoded-secret` (Committed Credentials)
462
+
463
+ ```typescript
464
+ // โŒ BAD: Secret committed inline
465
+ const client = new PaymentGateway({
466
+ apiKey: 'sk-prod-983427598273498273948273',
467
+ });
468
+
469
+ // โœ… GOOD: Read from environment variable (Autofixable!)
470
+ const client = new PaymentGateway({
471
+ apiKey: process.env.API_KEY,
472
+ });
473
+ ```
474
+
475
+ ### 3. `no-await-in-loop` (Sequential Latency Trap)
476
+
477
+ ```typescript
478
+ // โŒ BAD: Consecutive awaits block each iteration sequentially
479
+ async function fetchAllUsers(ids: string[]) {
480
+ const users = [];
481
+ for (const id of ids) {
482
+ users.push(await fetchUser(id));
483
+ }
484
+ return users;
485
+ }
486
+
487
+ // โœ… GOOD: Concurrently fetched with Promise.all (Autofixable!)
488
+ async function fetchAllUsers(ids: string[]) {
489
+ return await Promise.all(ids.map((id) => fetchUser(id)));
490
+ }
491
+ ```
492
+
493
+ ### 4. `no-empty-catch` (Swallowed Errors)
494
+
495
+ ```typescript
496
+ // โŒ BAD: Exception swallowed without trace
497
+ try {
498
+ parseConfiguration(rawConfig);
499
+ } catch (e) {}
500
+
501
+ // โœ… GOOD: Logged, rethrown, or documented (Autofixable!)
502
+ try {
503
+ parseConfiguration(rawConfig);
504
+ } catch (e) {
505
+ logger.error('Configuration parsing failed', { error: e });
506
+ throw e;
507
+ }
508
+ ```
509
+
510
+ ### 5. `no-sql-string-concat` (SQL Injection)
511
+
512
+ ```typescript
513
+ // โŒ BAD: Dynamic string interpolation in SQL
514
+ const query = `SELECT * FROM users WHERE organization_id = '${orgId}' AND role = '${role}'`;
515
+ await db.query(query);
516
+
517
+ // โœ… GOOD: Parameterized query binding
518
+ const query = 'SELECT * FROM users WHERE organization_id = $1 AND role = $2';
519
+ await db.query(query, [orgId, role]);
520
+ ```
521
+
522
+ ---
523
+
524
+ ## Automatic Remediation (Autofix)
525
+
526
+ Rules that have deterministic solutions provide automatic autofix handlers. Run ESLint's native `--fix` flag to automatically resolve them:
527
+
528
+ ```bash
529
+ npx eslint . --fix
530
+ ```
531
+
532
+ | Rule | Automatic Fix Behavior |
533
+ | :--- | :--- |
534
+ | `no-hardcoded-secret` | Replaces hardcoded string literal with `process.env.VARIABLE_NAME` |
535
+ | `no-empty-catch` | Inserts `/* TODO: handle error */` comment to prevent silent swallowing |
536
+ | `no-floating-promise` | Prepends `void ` expression to intentionally unawaited calls |
537
+ | `no-await-in-loop` | Rewrites straightforward sequential loops to `await Promise.all(...)` |
538
+
539
+ ---
540
+
541
+ ## Benchmarks & Empirical Evaluation
542
+
543
+ AI Guard has been empirically evaluated across multiple benchmarks comparing runtime scan performance, coverage gaps vs. standard tooling, and detection accuracy across real-world codebases.
544
+
545
+ ### 1. What AI Guard Catches vs. Conventional Linters
546
+
547
+ Conventional linters either omit AI-specific hazards entirely or require heavyweight TypeScript type-checking (`parserOptions.project`) that significantly slows down CI:
548
+
549
+ | Pattern | AI Guard Rule | ESLint Core | `@typescript-eslint` |
550
+ | :--- | :--- | :---: | :--- |
551
+ | **Floating Promises** (unawaited async call) | [`no-floating-promise`](./docs/rules/no-floating-promise.md) | โŒ None | `@typescript-eslint/no-floating-promises` *(requires type info)* |
552
+ | **Async Array Callbacks** (`.map(async ...)`) | [`no-async-array-callback`](./docs/rules/no-async-array-callback.md) | โŒ None | Partial: `no-misused-promises` *(requires type info)* |
553
+ | **Empty Catch Blocks** (swallowed errors) | [`no-empty-catch`](./docs/rules/no-empty-catch.md) | `no-empty` *(weaker)* | โŒ None |
554
+ | **Hardcoded Secrets / API Tokens** | [`no-hardcoded-secret`](./docs/rules/no-hardcoded-secret.md) | โŒ None | โŒ None |
555
+ | **Raw SQL String Concatenation** | [`no-sql-string-concat`](./docs/rules/no-sql-string-concat.md) | โŒ None | โŒ None |
556
+ | **Missing Route Auth Middleware** | [`require-auth-middleware`](./docs/rules/require-auth-middleware.md) | โŒ None | โŒ None |
557
+ | **Missing Route Authorization Checks** | [`require-authz-check`](./docs/rules/require-authz-check.md) | โŒ None | โŒ None |
558
+ | **Dynamic `eval()` / `new Function()`** | [`no-eval-dynamic`](./docs/rules/no-eval-dynamic.md) | `no-eval` *(blanket ban)* | โŒ None |
559
+ | **Unsafe `JSON.parse(req.body)`** | [`no-unsafe-deserialize`](./docs/rules/no-unsafe-deserialize.md) | โŒ None | โŒ None |
560
+ | **Async Without Await** | [`no-async-without-await`](./docs/rules/no-async-without-await.md) | โŒ None | `require-await` |
561
+ | **Sequential Await in Loop** | [`no-await-in-loop`](./docs/rules/no-await-in-loop.md) | `no-await-in-loop` *(no fix)* | โŒ None |
562
+ | **Dead Code Branches (`if (true)`)** | [`no-dead-branch`](./docs/rules/no-dead-branch.md) | โŒ None | โŒ None |
563
+
564
+ > [!TIP]
565
+ > **Minimal Type-Information Dependency:** 17 of 18 AI Guard rules operate in pure syntax/scope-analysis mode without `projectService` or `tsconfig.json`. The `no-floating-promise` rule optionally uses TypeScript parser services for higher recall on cross-module Promise calls, with syntax/scope-based heuristics as a zero-config fallback.
566
+
567
+ ---
568
+
569
+ ### 2. Runtime Performance
570
+
571
+ Benchmark: scanning 196 TypeScript / JavaScript files (`algorithm-automata-simulator`, Windows 11, Node.js 20, median of 3 runs):
572
+
573
+ | Tool / Mode | Scan Time | Configuration Overhead |
574
+ | :--- | :---: | :--- |
575
+ | **`ai-guard run --strict`** | **~1.8s** | **Zero config** (18 AST heuristic rules, no `tsconfig.json` needed) |
576
+ | `eslint .` (recommended) | ~2.5s | Core syntax rules only (misses floating promises & secrets) |
577
+ | `eslint .` (type-aware `@typescript-eslint`) | **~8โ€“12s** | Requires full TS compiler graph binding (**4xโ€“6x slower**) |
578
+
579
+ AI Guard executes **4xโ€“6x faster** than type-aware linting suites because it leverages deterministic AST heuristics rather than reconstructing the full TypeScript symbol graph.
580
+
581
+ ---
582
+
583
+ ### 3. Empirical Bug Detection & Precision Study
584
+
585
+ Two comprehensive empirical benchmark evaluations were conducted to measure real-world precision and detection yields:
586
+
587
+ #### A. Accuracy & False Positive Audit (4 Real-World Repositories, 378 Files)
588
+
589
+ | Category | Findings | True Positives | False Positive Rate |
590
+ | :--- | :---: | :---: | :---: |
591
+ | **Security** (`no-hardcoded-secret`, `no-eval-dynamic`, etc.) | 15 | 15 | **0%** |
592
+ | **Reliability** (`no-empty-catch`, broad exceptions) | 53 | 53 | **0%** |
593
+ | **Async Stability** (`no-floating-promise`, async callbacks) | 43 | ~40 | **~7%** |
594
+ | **AI Patterns** (duplicate logic, dead branches) | 58 | 43 | **26%** *(reduced in v1.2.8+)* |
595
+
596
+ #### B. Dual-Mode Detection Study (48 Call Sites & Real Production Target)
597
+
598
+ Audited across a controlled multi-file test corpus (13 files, 48 call sites) and a real-world Express + MongoDB production application (`Truvita New`):
599
+
600
+ - **High Precision:** **100% precision** on type-aware exclusive findings (26 of 26 verified True Positives; 0 false alarms on synchronous controls).
601
+ - **Critical Detection:** Detected **1 critical database startup race condition** in production (`server/index.ts connectDB()`) where an unawaited connection call allowed requests to hit the database before initialization.
602
+ - **Single-File Actionability:** **100%** of findings were resolvable locally at the call site (`await`, `.catch()`, or `void`).
603
+
604
+ For the complete methodology, raw findings, and benchmark harness, see [**`docs/benchmarks.md`**](./docs/benchmarks.md).
605
+
606
+ ---
607
+
608
+ ## Performance & Philosophy
609
+
610
+ - **Zero LLM Overhead:** AI Guard does not call external APIs, does not incur token costs, and does not add LLM latency. A scan of 100+ files executes in milliseconds.
611
+ - **100% Deterministic:** Every finding is derived strictly from Abstract Syntax Tree analysis. No probabilistic drift, no non-deterministic hallucinated findings.
612
+ - **Low False Positives:** Built with precision-first design. Context-sensitive rules are configured at `warn` or `off` in the recommended preset so developers are never blocked by noise.
613
+ - **Self-Scanning:** AI Guard enforces its own rules on its own codebase in CI using the `strict` preset.
614
+
615
+ ---
616
+
617
+ ## Learn More & Ecosystem
618
+
619
+ Visit [getaiguard.dev](https://getaiguard.dev) to explore interactive documentation, rule catalogs, benchmarks, and deep-dive engineering articles.
620
+
621
+ ### Official Links
622
+
623
+ - **Website:** [https://getaiguard.dev](https://getaiguard.dev)
624
+ - **GitHub Organization:** [https://github.com/ai-guard-dev](https://github.com/ai-guard-dev)
625
+ - **Repository:** [https://github.com/ai-guard-dev/eslint-plugin-ai-guard](https://github.com/ai-guard-dev/eslint-plugin-ai-guard)
626
+ - **npm Registry:** [https://www.npmjs.com/package/eslint-plugin-ai-guard](https://www.npmjs.com/package/eslint-plugin-ai-guard)
627
+ - **GitHub Action:** [ai-guard-dev/eslint-plugin-ai-guard@v1](https://github.com/ai-guard-dev/eslint-plugin-ai-guard)
628
+
629
+ ---
630
+
631
+ ## Contributing
632
+
633
+ We welcome contributions, new rule ideas, bug reports, and false-positive reports!
634
+
635
+ 1. Check out our [Contributing Guide](CONTRIBUTING.md) for local setup and testing standards.
636
+ 2. Review our [Security Policy](SECURITY.md) to report vulnerabilities responsibly.
637
+ 3. Check open issues or submit new ones on our [Issue Tracker](https://github.com/ai-guard-dev/eslint-plugin-ai-guard/issues).
638
+
639
+ ---
640
+
641
+ ## License
642
+
643
+ [MIT](LICENSE) ยฉ AI Guard Authors. Free and open source forever.