eslint-plugin-ai-guard 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 eslint-plugin-ai-guard contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,166 @@
1
+ <p align="center">
2
+ <h1 align="center">eslint-plugin-ai-guard</h1>
3
+ <p align="center">
4
+ <strong>🛡️ ESLint plugin that catches the code patterns AI tools get wrong most often.</strong>
5
+ </p>
6
+ <p align="center">
7
+ <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" alt="npm version"></a>
8
+ <a href="https://github.com/YashJadhav21/eslint-plugin-ai-guard/actions"><img src="https://img.shields.io/github/actions/workflow/status/YashJadhav21/eslint-plugin-ai-guard/ci.yml?style=flat-square&label=CI" alt="CI"></a>
9
+ <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" alt="downloads"></a>
10
+ <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" alt="license"></a>
11
+ </p>
12
+ </p>
13
+
14
+ ---
15
+
16
+ AI-generated code has **1.7× more issues** and **2.74× more security vulnerabilities** than human code ([CodeRabbit 2025](https://www.coderabbit.ai/)). Existing linters catch human mistakes — `ai-guard` catches the patterns AI tools consistently get wrong: empty catch blocks, floating promises, async array misuse, and more.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install --save-dev eslint-plugin-ai-guard
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ### ESLint 9 (Flat Config) — `eslint.config.js`
27
+
28
+ ```javascript
29
+ import aiGuard from "eslint-plugin-ai-guard";
30
+
31
+ export default [
32
+ {
33
+ plugins: { "ai-guard": aiGuard },
34
+ rules: { ...aiGuard.configs.recommended.rules }
35
+ }
36
+ ];
37
+ ```
38
+
39
+ ### ESLint 8 (Legacy Config) — `.eslintrc.json`
40
+
41
+ ```json
42
+ {
43
+ "plugins": ["ai-guard"],
44
+ "extends": ["plugin:ai-guard/recommended"]
45
+ }
46
+ ```
47
+
48
+ That's it. **Zero configuration required.**
49
+
50
+ ## 🧪 Validated Against Real Repositories
51
+
52
+ We tested `eslint-plugin-ai-guard` against two real-world codebases to ensure high signal-to-noise ratio:
53
+
54
+ 1. **Next.js Portfolio Website:** Found multiple un-escaped entities (caught by native plugins) but **0 false positives** on AI Guard rules, proving it respects human-written React/Next code.
55
+ 2. **CodeCrafters Admin Backend (Express):** Caught exactly the sort of generative flaws the plugin was designed for:
56
+ - **SQL Injections:** Flagged dynamic string templates used to build SQL queries (`ai-guard/no-sql-string-concat`).
57
+ - **Leaked Secrets:** Caught mock/test passwords (`process.env` equivalents not used) (`ai-guard/no-hardcoded-secret`).
58
+ - **O(n) Latency Issues:** Detected sequential awaits inside `for...of` loops parsing database rows (`ai-guard/no-await-in-loop`).
59
+ - **Floating Promises:** Found unhandled promises inside API handlers (`ai-guard/no-floating-promise`).
60
+
61
+ ## 🎬 Real Workspace Demo
62
+
63
+ See how `ai-guard` catches a common AI-generated async bug that silent failures in production:
64
+
65
+ ```typescript
66
+ // ❌ BAD: AI often forgets to await or wrap in Promise.all
67
+ const userIds = [1, 2, 3];
68
+ userIds.map(async (id) => {
69
+ return await fetchUser(id);
70
+ });
71
+ // ⚠️ ai-guard flags: Async callback passed to Array.map(). Returns Promise[], not values.
72
+
73
+ // ✅ GOOD: ai-guard recommended fix
74
+ const users = await Promise.all(userIds.map(async (id) => {
75
+ return await fetchUser(id);
76
+ }));
77
+ // ✨ ai-guard: No issues found.
78
+ ```
79
+
80
+ ### Terminal Output
81
+
82
+ ![ai-guard linting demo](./assets/demo.png)
83
+
84
+ *The terminal output above shows `ai-guard` catching multiple AI-generated anti-patterns in a single run.*
85
+
86
+ ## Rules
87
+
88
+ ### 🎯 Error Handling
89
+
90
+ - **`ai-guard/no-empty-catch`** (Error)
91
+ Disallow empty catch blocks. AI tools frequently generate try/catch with empty bodies that silently swallow errors.
92
+ - **`ai-guard/no-broad-exception`** (Warn)
93
+ Disallow catching `any` or `unknown` without instance narrowing. AI tools default to `catch (e: any)` which obscures the underlying failure.
94
+
95
+ ### ⏱️ Async Stability
96
+
97
+ - **`ai-guard/no-async-array-callback`** (Error)
98
+ Disallow async functions in `.map()`, `.filter()`, etc. AI tools frequently suggest `array.map(async ...)` expecting resolved values, creating silent bugs.
99
+ - **`ai-guard/no-floating-promise`** (Error)
100
+ Require awaiting or handling promises. AI tools frequently generate un-awaited async calls that silently swallow rejections.
101
+ - **`ai-guard/no-await-in-loop`** (Warn)
102
+ Disallow sequential `await` inside loops. AI tools frequently use `for (const x of y) await z(x)` causing O(n) latency instead of parallel `Promise.all()`.
103
+
104
+ ### 🛡️ Security
105
+
106
+ - **`ai-guard/no-hardcoded-secret`** (Error)
107
+ Disallow hardcoded keys/passwords. AI tools frequently provide examples with placeholder secrets that accidentally make it into production.
108
+ - **`ai-guard/no-eval-dynamic`** (Error)
109
+ Disallow dynamic `eval()` or `new Function()`.
110
+ - **`ai-guard/no-sql-string-concat`** (Error)
111
+ Disallow variable concatenation/interpolation in SQL queries. AI tools frequently generate dangerous code enabling SQL injection.
112
+ - **`ai-guard/require-auth-middleware`** (Warn)
113
+ Enforce authentication middleware on Express/Fastify routes. AI tools frequently generate unprotected endpoints exposing sensitive data.
114
+
115
+ ### Configs
116
+
117
+ | Config | Description |
118
+ | --- | --- |
119
+ | `recommended` | Most impactful rules at `error` — works with zero configuration |
120
+ | `strict` | All rules at `error` — for teams that want maximum coverage |
121
+ | `security` | Security-focused rules only — for AppSec teams |
122
+
123
+ ## Why This Exists
124
+
125
+ AI coding assistants generate code that **looks correct** but has subtle structural issues:
126
+
127
+ - 🕳️ **Empty catch blocks** — errors vanish silently
128
+ - ⏳ **`array.map(async ...)`** — returns `Promise[]`, not resolved values
129
+ - 🔥 **Floating promises** — `fetchData()` without `await` = silent failures
130
+
131
+ These patterns pass TypeScript and existing linters. `ai-guard` catches them.
132
+
133
+ ## Supported Environments
134
+
135
+ - **ESLint** 8.x and 9.x (flat config)
136
+ - **Node.js** ≥ 18
137
+ - **TypeScript** and JavaScript
138
+
139
+ ## Development
140
+
141
+ ```bash
142
+ git clone https://github.com/YashJadhav21/eslint-plugin-ai-guard.git
143
+ cd eslint-plugin-ai-guard
144
+ npm install
145
+ npm run test # Run test suite
146
+ npm run build # Build CJS + ESM
147
+ npm run typecheck # TypeScript check
148
+ ```
149
+
150
+ ## Contributing
151
+
152
+ Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
153
+
154
+ **Rule requests:** Open an issue using the [Rule Request template](https://github.com/YashJadhav21/eslint-plugin-ai-guard/issues/new).
155
+
156
+ **False positive reports:** Open an issue using the [False Positive template](https://github.com/YashJadhav21/eslint-plugin-ai-guard/issues/new) — we take zero false positives seriously.
157
+
158
+ ## License
159
+
160
+ [MIT](LICENSE) — free forever. No rules behind a paywall.
161
+
162
+ ---
163
+
164
+ <p align="center">
165
+ Built to make AI-assisted development safer. ⚡
166
+ </p>
@@ -0,0 +1,89 @@
1
+ import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
+ import { TSESLint } from '@typescript-eslint/utils';
3
+
4
+ /**
5
+ * All rules exported by the plugin.
6
+ * Each key is the rule name (without the plugin prefix).
7
+ */
8
+ declare const allRules: {
9
+ readonly 'no-empty-catch': _typescript_eslint_utils_ts_eslint.RuleModule<"emptyCatch", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
10
+ name: string;
11
+ };
12
+ readonly 'no-broad-exception': _typescript_eslint_utils_ts_eslint.RuleModule<"broadException", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
13
+ name: string;
14
+ };
15
+ readonly 'no-async-array-callback': _typescript_eslint_utils_ts_eslint.RuleModule<"asyncArrayCallback", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
16
+ name: string;
17
+ };
18
+ readonly 'no-floating-promise': _typescript_eslint_utils_ts_eslint.RuleModule<"floatingPromise", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
19
+ name: string;
20
+ };
21
+ readonly 'no-await-in-loop': _typescript_eslint_utils_ts_eslint.RuleModule<"awaitInLoop", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
22
+ name: string;
23
+ };
24
+ readonly 'no-hardcoded-secret': _typescript_eslint_utils_ts_eslint.RuleModule<"hardcodedSecret", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
25
+ name: string;
26
+ };
27
+ readonly 'no-eval-dynamic': _typescript_eslint_utils_ts_eslint.RuleModule<"evalDynamic" | "newFunctionDynamic", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
28
+ name: string;
29
+ };
30
+ readonly 'no-sql-string-concat': _typescript_eslint_utils_ts_eslint.RuleModule<"sqlStringConcat", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
31
+ name: string;
32
+ };
33
+ readonly 'require-auth-middleware': _typescript_eslint_utils_ts_eslint.RuleModule<"missingAuth", [{
34
+ authMiddlewareNames?: string[];
35
+ }], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
36
+ name: string;
37
+ };
38
+ };
39
+
40
+ declare const recommended: TSESLint.ClassicConfig.Config;
41
+
42
+ declare const strict: TSESLint.ClassicConfig.Config;
43
+
44
+ declare const security: TSESLint.ClassicConfig.Config;
45
+
46
+ declare const plugin: {
47
+ meta: {
48
+ name: string;
49
+ version: string;
50
+ };
51
+ rules: {
52
+ readonly 'no-empty-catch': _typescript_eslint_utils_ts_eslint.RuleModule<"emptyCatch", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
53
+ name: string;
54
+ };
55
+ readonly 'no-broad-exception': _typescript_eslint_utils_ts_eslint.RuleModule<"broadException", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
56
+ name: string;
57
+ };
58
+ readonly 'no-async-array-callback': _typescript_eslint_utils_ts_eslint.RuleModule<"asyncArrayCallback", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
59
+ name: string;
60
+ };
61
+ readonly 'no-floating-promise': _typescript_eslint_utils_ts_eslint.RuleModule<"floatingPromise", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
62
+ name: string;
63
+ };
64
+ readonly 'no-await-in-loop': _typescript_eslint_utils_ts_eslint.RuleModule<"awaitInLoop", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
65
+ name: string;
66
+ };
67
+ readonly 'no-hardcoded-secret': _typescript_eslint_utils_ts_eslint.RuleModule<"hardcodedSecret", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
68
+ name: string;
69
+ };
70
+ readonly 'no-eval-dynamic': _typescript_eslint_utils_ts_eslint.RuleModule<"evalDynamic" | "newFunctionDynamic", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
71
+ name: string;
72
+ };
73
+ readonly 'no-sql-string-concat': _typescript_eslint_utils_ts_eslint.RuleModule<"sqlStringConcat", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
74
+ name: string;
75
+ };
76
+ readonly 'require-auth-middleware': _typescript_eslint_utils_ts_eslint.RuleModule<"missingAuth", [{
77
+ authMiddlewareNames?: string[];
78
+ }], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
79
+ name: string;
80
+ };
81
+ };
82
+ configs: {
83
+ recommended: _typescript_eslint_utils_ts_eslint.ClassicConfig.Config;
84
+ strict: _typescript_eslint_utils_ts_eslint.ClassicConfig.Config;
85
+ security: _typescript_eslint_utils_ts_eslint.ClassicConfig.Config;
86
+ };
87
+ };
88
+
89
+ export { plugin as default, recommended, allRules as rules, security, strict };
@@ -0,0 +1,89 @@
1
+ import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
+ import { TSESLint } from '@typescript-eslint/utils';
3
+
4
+ /**
5
+ * All rules exported by the plugin.
6
+ * Each key is the rule name (without the plugin prefix).
7
+ */
8
+ declare const allRules: {
9
+ readonly 'no-empty-catch': _typescript_eslint_utils_ts_eslint.RuleModule<"emptyCatch", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
10
+ name: string;
11
+ };
12
+ readonly 'no-broad-exception': _typescript_eslint_utils_ts_eslint.RuleModule<"broadException", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
13
+ name: string;
14
+ };
15
+ readonly 'no-async-array-callback': _typescript_eslint_utils_ts_eslint.RuleModule<"asyncArrayCallback", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
16
+ name: string;
17
+ };
18
+ readonly 'no-floating-promise': _typescript_eslint_utils_ts_eslint.RuleModule<"floatingPromise", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
19
+ name: string;
20
+ };
21
+ readonly 'no-await-in-loop': _typescript_eslint_utils_ts_eslint.RuleModule<"awaitInLoop", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
22
+ name: string;
23
+ };
24
+ readonly 'no-hardcoded-secret': _typescript_eslint_utils_ts_eslint.RuleModule<"hardcodedSecret", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
25
+ name: string;
26
+ };
27
+ readonly 'no-eval-dynamic': _typescript_eslint_utils_ts_eslint.RuleModule<"evalDynamic" | "newFunctionDynamic", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
28
+ name: string;
29
+ };
30
+ readonly 'no-sql-string-concat': _typescript_eslint_utils_ts_eslint.RuleModule<"sqlStringConcat", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
31
+ name: string;
32
+ };
33
+ readonly 'require-auth-middleware': _typescript_eslint_utils_ts_eslint.RuleModule<"missingAuth", [{
34
+ authMiddlewareNames?: string[];
35
+ }], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
36
+ name: string;
37
+ };
38
+ };
39
+
40
+ declare const recommended: TSESLint.ClassicConfig.Config;
41
+
42
+ declare const strict: TSESLint.ClassicConfig.Config;
43
+
44
+ declare const security: TSESLint.ClassicConfig.Config;
45
+
46
+ declare const plugin: {
47
+ meta: {
48
+ name: string;
49
+ version: string;
50
+ };
51
+ rules: {
52
+ readonly 'no-empty-catch': _typescript_eslint_utils_ts_eslint.RuleModule<"emptyCatch", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
53
+ name: string;
54
+ };
55
+ readonly 'no-broad-exception': _typescript_eslint_utils_ts_eslint.RuleModule<"broadException", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
56
+ name: string;
57
+ };
58
+ readonly 'no-async-array-callback': _typescript_eslint_utils_ts_eslint.RuleModule<"asyncArrayCallback", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
59
+ name: string;
60
+ };
61
+ readonly 'no-floating-promise': _typescript_eslint_utils_ts_eslint.RuleModule<"floatingPromise", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
62
+ name: string;
63
+ };
64
+ readonly 'no-await-in-loop': _typescript_eslint_utils_ts_eslint.RuleModule<"awaitInLoop", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
65
+ name: string;
66
+ };
67
+ readonly 'no-hardcoded-secret': _typescript_eslint_utils_ts_eslint.RuleModule<"hardcodedSecret", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
68
+ name: string;
69
+ };
70
+ readonly 'no-eval-dynamic': _typescript_eslint_utils_ts_eslint.RuleModule<"evalDynamic" | "newFunctionDynamic", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
71
+ name: string;
72
+ };
73
+ readonly 'no-sql-string-concat': _typescript_eslint_utils_ts_eslint.RuleModule<"sqlStringConcat", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
74
+ name: string;
75
+ };
76
+ readonly 'require-auth-middleware': _typescript_eslint_utils_ts_eslint.RuleModule<"missingAuth", [{
77
+ authMiddlewareNames?: string[];
78
+ }], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
79
+ name: string;
80
+ };
81
+ };
82
+ configs: {
83
+ recommended: _typescript_eslint_utils_ts_eslint.ClassicConfig.Config;
84
+ strict: _typescript_eslint_utils_ts_eslint.ClassicConfig.Config;
85
+ security: _typescript_eslint_utils_ts_eslint.ClassicConfig.Config;
86
+ };
87
+ };
88
+
89
+ export { plugin as default, recommended, allRules as rules, security, strict };