eslint-plugin-postgresql-security 1.5.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/CHANGELOG.md +150 -0
- package/LICENSE +23 -0
- package/README.md +169 -0
- package/dist/AGENTS.md +118 -0
- package/dist/CHANGELOG.md +150 -0
- package/dist/LICENSE +23 -0
- package/dist/README.md +169 -0
- package/dist/package.json +99 -0
- package/dist/src/constants.d.ts +6 -0
- package/dist/src/constants.js +13 -0
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.js +116 -0
- package/dist/src/oxlint.d.ts +20 -0
- package/dist/src/oxlint.js +21 -0
- package/dist/src/rules/check-query-params/index.d.ts +8 -0
- package/dist/src/rules/check-query-params/index.js +90 -0
- package/dist/src/rules/no-batch-insert-loop/index.d.ts +8 -0
- package/dist/src/rules/no-batch-insert-loop/index.js +90 -0
- package/dist/src/rules/no-floating-query/index.d.ts +8 -0
- package/dist/src/rules/no-floating-query/index.js +74 -0
- package/dist/src/rules/no-hardcoded-credentials/index.d.ts +8 -0
- package/dist/src/rules/no-hardcoded-credentials/index.js +86 -0
- package/dist/src/rules/no-insecure-ssl/index.d.ts +8 -0
- package/dist/src/rules/no-insecure-ssl/index.js +66 -0
- package/dist/src/rules/no-missing-client-release/index.d.ts +8 -0
- package/dist/src/rules/no-missing-client-release/index.js +85 -0
- package/dist/src/rules/no-select-all/index.d.ts +8 -0
- package/dist/src/rules/no-select-all/index.js +79 -0
- package/dist/src/rules/no-transaction-on-pool/index.d.ts +8 -0
- package/dist/src/rules/no-transaction-on-pool/index.js +71 -0
- package/dist/src/rules/no-unsafe-copy-from/index.d.ts +10 -0
- package/dist/src/rules/no-unsafe-copy-from/index.js +205 -0
- package/dist/src/rules/no-unsafe-query/index.d.ts +8 -0
- package/dist/src/rules/no-unsafe-query/index.js +132 -0
- package/dist/src/rules/no-unsafe-search-path/index.d.ts +8 -0
- package/dist/src/rules/no-unsafe-search-path/index.js +144 -0
- package/dist/src/rules/prefer-pool-query/index.d.ts +8 -0
- package/dist/src/rules/prefer-pool-query/index.js +104 -0
- package/dist/src/rules/prevent-double-release/index.d.ts +8 -0
- package/dist/src/rules/prevent-double-release/index.js +456 -0
- package/dist/src/types/index.d.ts +54 -0
- package/dist/src/types/index.js +7 -0
- package/package.json +99 -0
- package/src/__compatibility__/pg-interface.spec.ts +495 -0
- package/src/constants.ts +11 -0
- package/src/index.spec.ts +14 -0
- package/src/index.test.ts +59 -0
- package/src/index.ts +130 -0
- package/src/oxlint.spec.ts +70 -0
- package/src/oxlint.ts +23 -0
- package/src/rules/check-query-params/check-query-params.test.ts +68 -0
- package/src/rules/check-query-params/index.spec.ts +117 -0
- package/src/rules/check-query-params/index.ts +106 -0
- package/src/rules/no-batch-insert-loop/index.spec.ts +105 -0
- package/src/rules/no-batch-insert-loop/index.ts +105 -0
- package/src/rules/no-batch-insert-loop/no-batch-insert-loop.test.ts +68 -0
- package/src/rules/no-floating-query/index.spec.ts +112 -0
- package/src/rules/no-floating-query/index.ts +81 -0
- package/src/rules/no-floating-query/no-floating-query.test.ts +68 -0
- package/src/rules/no-hardcoded-credentials/index.spec.ts +38 -0
- package/src/rules/no-hardcoded-credentials/index.ts +93 -0
- package/src/rules/no-hardcoded-credentials/no-hardcoded-credentials.test.ts +68 -0
- package/src/rules/no-insecure-ssl/index.spec.ts +40 -0
- package/src/rules/no-insecure-ssl/index.ts +81 -0
- package/src/rules/no-insecure-ssl/no-insecure-ssl.test.ts +68 -0
- package/src/rules/no-missing-client-release/coverage-gaps.spec.ts +42 -0
- package/src/rules/no-missing-client-release/index.spec.ts +52 -0
- package/src/rules/no-missing-client-release/index.ts +100 -0
- package/src/rules/no-missing-client-release/no-missing-client-release.test.ts +68 -0
- package/src/rules/no-select-all/index.spec.ts +44 -0
- package/src/rules/no-select-all/index.ts +92 -0
- package/src/rules/no-select-all/no-select-all.test.ts +68 -0
- package/src/rules/no-transaction-on-pool/index.spec.ts +36 -0
- package/src/rules/no-transaction-on-pool/index.ts +85 -0
- package/src/rules/no-transaction-on-pool/no-transaction-on-pool.test.ts +68 -0
- package/src/rules/no-unsafe-copy-from/coverage-gaps.spec.ts +76 -0
- package/src/rules/no-unsafe-copy-from/index.spec.ts +274 -0
- package/src/rules/no-unsafe-copy-from/index.ts +226 -0
- package/src/rules/no-unsafe-copy-from/no-unsafe-copy-from.test.ts +78 -0
- package/src/rules/no-unsafe-query/coverage-gaps.spec.ts +61 -0
- package/src/rules/no-unsafe-query/index.spec.ts +103 -0
- package/src/rules/no-unsafe-query/index.ts +149 -0
- package/src/rules/no-unsafe-query/no-unsafe-query.test.ts +73 -0
- package/src/rules/no-unsafe-search-path/index.spec.ts +46 -0
- package/src/rules/no-unsafe-search-path/index.ts +164 -0
- package/src/rules/no-unsafe-search-path/no-unsafe-search-path.test.ts +68 -0
- package/src/rules/prefer-pool-query/coverage-gaps.spec.ts +76 -0
- package/src/rules/prefer-pool-query/index.spec.ts +97 -0
- package/src/rules/prefer-pool-query/index.ts +118 -0
- package/src/rules/prefer-pool-query/prefer-pool-query.test.ts +68 -0
- package/src/rules/prevent-double-release/coverage-gaps.spec.ts +538 -0
- package/src/rules/prevent-double-release/index.spec.ts +824 -0
- package/src/rules/prevent-double-release/index.ts +534 -0
- package/src/rules/prevent-double-release/prevent-double-release.test.ts +70 -0
- package/src/types/index.ts +58 -0
package/dist/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="90" /></a>
|
|
3
|
+
|
|
4
|
+
<a href="https://eslint.org" target="_blank"><img src="https://eslint.interlace.tools/eslint-logo.svg" alt="ESLint" height="90" /></a>
|
|
5
|
+
|
|
6
|
+
<a href="https://oxc.rs" target="_blank"><img src="https://eslint.interlace.tools/oxlint-logo.svg" alt="oxlint" height="90" /></a>
|
|
7
|
+
|
|
8
|
+
<a href="https://www.npmjs.com/package/pg" target="_blank"><img src="https://eslint.interlace.tools/postgresql-logo.svg" alt="PostgreSQL" height="90" /></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
Security rules for PostgreSQL interaction in Node.js (SQL injection prevention).
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-postgresql-security" target="_blank"><img src="https://img.shields.io/npm/v/eslint-plugin-postgresql-security.svg" alt="NPM Version" /></a>
|
|
17
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-postgresql-security" target="_blank"><img src="https://img.shields.io/npm/dm/eslint-plugin-postgresql-security.svg" alt="NPM Downloads" /></a>
|
|
18
|
+
<a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="Package License" /></a>
|
|
19
|
+
<a href="https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=eslint-plugin-postgresql-security" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?component=eslint-plugin-postgresql-security" alt="Codecov" /></a>
|
|
20
|
+
<a href="https://github.com/ofri-peretz/eslint" target="_blank"><img src="https://img.shields.io/badge/Since-Dec_2025-blue?logo=rocket&logoColor=white" alt="Since Dec 2025" /></a>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
> ⭐ If this plugin caught a real bug for you, [**star the repo**](https://github.com/ofri-peretz/eslint) — it's the signal that keeps these rules maintained.
|
|
24
|
+
|
|
25
|
+
## Description
|
|
26
|
+
|
|
27
|
+
This plugin provides Security rules for PostgreSQL interaction in Node.js (SQL injection prevention).
|
|
28
|
+
|
|
29
|
+
## Why pg-specific?
|
|
30
|
+
|
|
31
|
+
A generic SQL injection linter can flag string concatenation wherever it appears, but it cannot know the parameterization convention for each database client. The `pg` (node-postgres) driver uses `$1, $2, …` positional placeholders with a second-argument array — a pattern no generic rule encodes. `eslint-plugin-postgresql-security` knows this contract: it only fires on `.query()` calls, it stays silent when a second argument (the values array) is present, and it tracks variable taint across assignment statements so that a split-line pattern like `const sql = "SELECT..." + id; client.query(sql)` is flagged even though the concatenation and the query call are on separate lines. The result is a rule with near-zero false positives on legitimate parameterized queries and reliable detection on the patterns that actually lead to SQL injection.
|
|
32
|
+
|
|
33
|
+
## Philosophy
|
|
34
|
+
|
|
35
|
+
**Interlace** fosters **strength through integration**. Instead of stacking isolated rules, we **interlace** security directly into your workflow to create a resilient fabric of code. We believe tools should **guide rather than gatekeep**, providing educational feedback that strengthens the developer with every interaction.
|
|
36
|
+
|
|
37
|
+
## Getting Started
|
|
38
|
+
|
|
39
|
+
- To check out the [guide](https://eslint.interlace.tools/docs/security/plugin-pg?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security), visit [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security). 📚
|
|
40
|
+
- 要查看中文 [指南](https://eslint.interlace.tools/docs/security/plugin-pg?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security), 请访问 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security). 📚
|
|
41
|
+
- [가이드](https://eslint.interlace.tools/docs/security/plugin-pg?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) 문서는 [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security)에서 확인하실 수 있습니다. 📚
|
|
42
|
+
- [ガイド](https://eslint.interlace.tools/docs/security/plugin-pg?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security)は [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security)でご確認ください。 📚
|
|
43
|
+
- Para ver la [guía](https://eslint.interlace.tools/docs/security/plugin-pg?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security), visita [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security). 📚
|
|
44
|
+
- للاطلاع على [الدليل](https://eslint.interlace.tools/docs/security/plugin-pg?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security)، قم بزيارة [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security). 📚
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install eslint-plugin-postgresql-security --save-dev
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## ⚙️ Configuration Presets
|
|
51
|
+
| Preset | Description |
|
|
52
|
+
| :------------ | :------------------------------------------------------- |
|
|
53
|
+
| `recommended` | Recommended preset - balanced security for most projects |
|
|
54
|
+
| `strict` | Strict preset - all rules as errors |
|
|
55
|
+
|
|
56
|
+
## 📚 Supported Libraries
|
|
57
|
+
| Library | npm | Downloads | Detection |
|
|
58
|
+
| -------------------- | ------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | ------------------------------- |
|
|
59
|
+
| `pg` (node-postgres) | [](https://www.npmjs.com/package/pg) | [](https://www.npmjs.com/package/pg) | SQL Injection, Connection Leaks |
|
|
60
|
+
|
|
61
|
+
### Custom Configuration
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
import pg from 'eslint-plugin-postgresql-security';
|
|
65
|
+
|
|
66
|
+
export default [
|
|
67
|
+
{
|
|
68
|
+
plugins: { pg },
|
|
69
|
+
rules: {
|
|
70
|
+
'pg/no-unsafe-query': 'error',
|
|
71
|
+
'pg/no-select-all': 'off', // Disable if needed
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 💡 What You Get
|
|
78
|
+
- **PostgreSQL-specific rules:** Catches pg driver anti-patterns that generic linters miss
|
|
79
|
+
- **LLM-optimized messages:** Structured 2-line errors with CWE + fixes that AI assistants can apply
|
|
80
|
+
- **Connection safety:** Prevents leaks, double releases, and transaction race conditions
|
|
81
|
+
- **SQL security:** SQL injection, search_path hijacking, file access via COPY
|
|
82
|
+
- **Performance patterns:** N+1 queries, SELECT \*, bulk operation suggestions
|
|
83
|
+
|
|
84
|
+
Every rule produces a **structured error message**:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
src/db.ts
|
|
88
|
+
42:15 error 🔒 CWE-89 OWASP:A03-Injection CVSS:9.8 | Unsafe query detected | CRITICAL
|
|
89
|
+
Fix: Use parameterized query: client.query('SELECT * FROM users WHERE id = $1', [userId])
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 📦 Compatibility
|
|
93
|
+
| Package | Version |
|
|
94
|
+
| :--- | :--- |
|
|
95
|
+
| ESLint | `^8.0.0 \|\| ^9.0.0 \|\| ^10.0.0` |
|
|
96
|
+
| Node.js | `>=18.0.0` |
|
|
97
|
+
|
|
98
|
+
See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md) — current ecosystem share data, the 20% gate, and the forward-looking exception that covers v10.
|
|
99
|
+
|
|
100
|
+
## Rules
|
|
101
|
+
|
|
102
|
+
**Legend**
|
|
103
|
+
|
|
104
|
+
| Icon | Description |
|
|
105
|
+
| :---: | :--- |
|
|
106
|
+
| 💼 | **Recommended**: Included in the recommended preset. |
|
|
107
|
+
| ⚠️ | **Warns**: Set to warn in recommended preset. |
|
|
108
|
+
| 🔧 | **Auto-fixable**: Automatically fixable by the `--fix` CLI option. |
|
|
109
|
+
| 💡 | **Suggestions**: Providing code suggestions in IDE. |
|
|
110
|
+
| 🚫 | **Deprecated**: This rule is deprecated. |
|
|
111
|
+
| 🟢 | **Type-unaware**: AST-only, runs in oxlint JS-plugin tier. |
|
|
112
|
+
| 🟡 | **Type-aware (refining)**: pure-AST primary path; types refine precision. |
|
|
113
|
+
| 🟠 | **Type-aware (graceful)**: requires TS program; silent without it. |
|
|
114
|
+
|
|
115
|
+
<!-- AUTO-GENERATED:RULES_TABLE:START - Do not edit manually -->
|
|
116
|
+
| Rule | CWE | OWASP | CVSS | Description | 🧠 | 💼 | ⚠️ | 🔧 | 💡 | 🚫 |
|
|
117
|
+
| :--- | :---: | :---: | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
|
|
118
|
+
| [check-query-params](https://eslint.interlace.tools/docs/security/plugin-pg/rules/check-query-params?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-89 | | | Ensures the number of placeholders in SQL queries matches the provided parameters. | 🟢 | | ⚠️ | | | |
|
|
119
|
+
| [no-batch-insert-loop](https://eslint.interlace.tools/docs/security/plugin-pg/rules/no-batch-insert-loop?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-400 | | | Prevents INSERT/UPDATE/DELETE queries inside loops (N+1 query anti-pattern). | 🟢 | | ⚠️ | | | |
|
|
120
|
+
| [no-floating-query](https://eslint.interlace.tools/docs/security/plugin-pg/rules/no-floating-query?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-252 | | | Ensures query promises are awaited or handled. | 🟢 | 💼 | | | | |
|
|
121
|
+
| [no-hardcoded-credentials](https://eslint.interlace.tools/docs/security/plugin-pg/rules/no-hardcoded-credentials?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-798 | | | Prevents hardcoded passwords and connection strings in PostgreSQL client initialization. | 🟢 | 💼 | | | | |
|
|
122
|
+
| [no-insecure-ssl](https://eslint.interlace.tools/docs/security/plugin-pg/rules/no-insecure-ssl?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-295 | | | Prevents disabling SSL certificate validation in PostgreSQL connections. | 🟢 | 💼 | | | | |
|
|
123
|
+
| [no-missing-client-release](https://eslint.interlace.tools/docs/security/plugin-pg/rules/no-missing-client-release?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-772 | | | Ensures acquired pool clients are released back to the pool. | 🟢 | 💼 | | | | |
|
|
124
|
+
| [no-select-all](https://eslint.interlace.tools/docs/security/plugin-pg/rules/no-select-all?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-693 | | | Discourages SELECT in favor of explicit column lists. | 🟢 | | ⚠️ | | | |
|
|
125
|
+
| [no-transaction-on-pool](https://eslint.interlace.tools/docs/security/plugin-pg/rules/no-transaction-on-pool?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-362 | | | Prevents running transaction commands directly on pool (must use dedicated client). | 🟢 | 💼 | | | | |
|
|
126
|
+
| [no-unsafe-copy-from](https://eslint.interlace.tools/docs/security/plugin-pg/rules/no-unsafe-copy-from?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-73 | A03:2021 | | Prevents COPY FROM with file paths (should use STDIN for safe client-side data loading). | 🟢 | 💼 | | | | |
|
|
127
|
+
| [no-unsafe-query](https://eslint.interlace.tools/docs/security/plugin-pg/rules/no-unsafe-query?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-89 | | | SQL injection is one of the most critical security vulnerabilities | 🟢 | 💼 | | | | |
|
|
128
|
+
| [no-unsafe-search-path](https://eslint.interlace.tools/docs/security/plugin-pg/rules/no-unsafe-search-path?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-426 | | | Prevents dynamic SET searchpath queries that could enable schema hijacking. | 🟢 | 💼 | | | | |
|
|
129
|
+
| [prefer-pool-query](https://eslint.interlace.tools/docs/security/plugin-pg/rules/prefer-pool-query?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-693 | | | Suggests using pool.query() for single-shot queries instead of manual connect/release. | 🟢 | | ⚠️ | | | |
|
|
130
|
+
| [prevent-double-release](https://eslint.interlace.tools/docs/security/plugin-pg/rules/prevent-double-release?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-415 | | | Prevents calling client.release() multiple times on the same client. | 🟢 | 💼 | | | | |
|
|
131
|
+
<!-- AUTO-GENERATED:RULES_TABLE:END -->
|
|
132
|
+
## 🔗 Related ESLint Plugins
|
|
133
|
+
|
|
134
|
+
Part of the **Interlace ESLint Ecosystem** — AI-native security plugins with LLM-optimized error messages:
|
|
135
|
+
|
|
136
|
+
| Plugin | Downloads | Description |
|
|
137
|
+
| :--- | :---: | :--- |
|
|
138
|
+
| [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) | [](https://www.npmjs.com/package/eslint-plugin-secure-coding) | General security rules & OWASP guidelines. |
|
|
139
|
+
| [`eslint-plugin-postgresql-security`](https://www.npmjs.com/package/eslint-plugin-postgresql-security) | [](https://www.npmjs.com/package/eslint-plugin-postgresql-security) | PostgreSQL security & best practices. |
|
|
140
|
+
| [`eslint-plugin-node-security`](https://www.npmjs.com/package/eslint-plugin-node-security) | [](https://www.npmjs.com/package/eslint-plugin-node-security) | Node.js core-module security (fs, child_process, vm, crypto, Buffer). |
|
|
141
|
+
| [`eslint-plugin-jwt`](https://www.npmjs.com/package/eslint-plugin-jwt) | [](https://www.npmjs.com/package/eslint-plugin-jwt) | JWT security & best practices. |
|
|
142
|
+
| [`eslint-plugin-browser-security`](https://www.npmjs.com/package/eslint-plugin-browser-security) | [](https://www.npmjs.com/package/eslint-plugin-browser-security) | Browser-specific security & XSS prevention. |
|
|
143
|
+
| [`eslint-plugin-express-security`](https://www.npmjs.com/package/eslint-plugin-express-security) | [](https://www.npmjs.com/package/eslint-plugin-express-security) | Express.js security hardening rules. |
|
|
144
|
+
| [`eslint-plugin-lambda-security`](https://www.npmjs.com/package/eslint-plugin-lambda-security) | [](https://www.npmjs.com/package/eslint-plugin-lambda-security) | AWS Lambda security best practices. |
|
|
145
|
+
| [`eslint-plugin-nestjs-security`](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | [](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | NestJS security rules & patterns. |
|
|
146
|
+
| [`eslint-plugin-mongodb-security`](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | [](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | MongoDB security best practices. |
|
|
147
|
+
| [`eslint-plugin-vercel-ai-security`](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | [](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | Vercel AI SDK security hardening. |
|
|
148
|
+
| [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [](https://www.npmjs.com/package/eslint-plugin-import-next) | Next-gen import sorting & architecture. |
|
|
149
|
+
|
|
150
|
+
<!-- INTERLACE:STAR_CTA:START -->
|
|
151
|
+
## ⭐ Support & follow
|
|
152
|
+
|
|
153
|
+
If this plugin caught a real bug for you, **[star the repo](https://github.com/ofri-peretz/eslint)** — stars are the signal that keeps the Interlace ESLint ecosystem maintained — and **[follow the writeups on Dev.to](https://dev.to/ofri-peretz)** for the benchmarks and security research behind these rules.
|
|
154
|
+
|
|
155
|
+
[](https://github.com/ofri-peretz/eslint)
|
|
156
|
+
|
|
157
|
+
<!-- INTERLACE:STAR_CTA:END -->
|
|
158
|
+
|
|
159
|
+
## 📄 License
|
|
160
|
+
|
|
161
|
+
MIT © [Ofri Peretz](https://github.com/ofri-peretz)
|
|
162
|
+
|
|
163
|
+
<p align="center">
|
|
164
|
+
<a href="https://eslint.interlace.tools/docs/security/plugin-pg?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security"><img src="https://eslint.interlace.tools/images/og-pg.png" alt="ESLint Interlace Plugin" width="100%" /></a>
|
|
165
|
+
</p>
|
|
166
|
+
|
|
167
|
+
<p align="center">
|
|
168
|
+
<a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="70" /></a>
|
|
169
|
+
</p>
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-postgresql-security",
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "ESLint plugin for the pg PostgreSQL driver — detects SQL injection, unreleased clients, floating queries, unsafe search_path, and insecure SSL.",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"default": "./src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./oxlint": {
|
|
14
|
+
"types": "./src/oxlint.d.ts",
|
|
15
|
+
"default": "./src/oxlint.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"author": "Ofri Peretz <ofriperetzdev@gmail.com>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://eslint.interlace.tools/docs/security/plugin-postgresql-security?utm_source=npm&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/ofri-peretz/eslint",
|
|
24
|
+
"directory": "packages/eslint-plugin-postgresql-security"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/ofri-peretz/eslint/issues"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"src/",
|
|
34
|
+
"dist/",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE",
|
|
37
|
+
"CHANGELOG.md"
|
|
38
|
+
],
|
|
39
|
+
"keywords": [
|
|
40
|
+
"eslint",
|
|
41
|
+
"eslintplugin",
|
|
42
|
+
"eslint-plugin",
|
|
43
|
+
"static-analysis",
|
|
44
|
+
"linting",
|
|
45
|
+
"code-quality",
|
|
46
|
+
"security",
|
|
47
|
+
"sast",
|
|
48
|
+
"appsec",
|
|
49
|
+
"vulnerability",
|
|
50
|
+
"owasp",
|
|
51
|
+
"cwe",
|
|
52
|
+
"interlace-security",
|
|
53
|
+
"pg",
|
|
54
|
+
"postgres",
|
|
55
|
+
"postgresql",
|
|
56
|
+
"node-postgres",
|
|
57
|
+
"sql",
|
|
58
|
+
"sql-injection",
|
|
59
|
+
"cwe-89",
|
|
60
|
+
"database",
|
|
61
|
+
"database-security",
|
|
62
|
+
"connection-pool",
|
|
63
|
+
"best-practices",
|
|
64
|
+
"llm-optimized",
|
|
65
|
+
"ai-assistant",
|
|
66
|
+
"typescript"
|
|
67
|
+
],
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=18.0.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
73
|
+
"pg": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
74
|
+
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"pg": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"dependencies": {
|
|
81
|
+
"tslib": "^2.3.0",
|
|
82
|
+
"@interlace/eslint-devkit": "^1.4.3"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
86
|
+
"@typescript-eslint/rule-tester": "^8.46.2",
|
|
87
|
+
"pg": "^8.22.0"
|
|
88
|
+
},
|
|
89
|
+
"scripts": {
|
|
90
|
+
"build": "tsx ../../scripts/build-package.ts",
|
|
91
|
+
"test": "vitest run",
|
|
92
|
+
"test:coverage": "vitest run --coverage",
|
|
93
|
+
"typecheck": "tsc -p tsconfig.lib.json --noEmit"
|
|
94
|
+
},
|
|
95
|
+
"funding": {
|
|
96
|
+
"type": "github",
|
|
97
|
+
"url": "https://github.com/ofri-peretz/eslint"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.PG_PROTOCOLS = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
* Connection string protocols for PostgreSQL
|
|
12
|
+
*/
|
|
13
|
+
exports.PG_PROTOCOLS = ['postgres://', 'postgresql://'];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* eslint-plugin-postgresql-security
|
|
8
|
+
*
|
|
9
|
+
* ESLint plugin with security and best practices rules for the pg Node.js driver.
|
|
10
|
+
*
|
|
11
|
+
* @see https://github.com/ofri-peretz/eslint/tree/main/packages/eslint-plugin-postgresql-security
|
|
12
|
+
*/
|
|
13
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
14
|
+
/**
|
|
15
|
+
* Collection of all rules
|
|
16
|
+
*/
|
|
17
|
+
export declare const rules: Record<string, TSESLint.RuleModule<string, readonly unknown[]>>;
|
|
18
|
+
/**
|
|
19
|
+
* ESLint Plugin object
|
|
20
|
+
*/
|
|
21
|
+
export declare const plugin: TSESLint.FlatConfig.Plugin;
|
|
22
|
+
/**
|
|
23
|
+
* Preset configurations
|
|
24
|
+
*/
|
|
25
|
+
export declare const configs: Record<string, TSESLint.FlatConfig.Config>;
|
|
26
|
+
export default plugin;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.configs = exports.plugin = exports.rules = void 0;
|
|
9
|
+
const no_unsafe_query_1 = require("./rules/no-unsafe-query");
|
|
10
|
+
const no_insecure_ssl_1 = require("./rules/no-insecure-ssl");
|
|
11
|
+
const no_hardcoded_credentials_1 = require("./rules/no-hardcoded-credentials");
|
|
12
|
+
const check_query_params_1 = require("./rules/check-query-params");
|
|
13
|
+
const no_missing_client_release_1 = require("./rules/no-missing-client-release");
|
|
14
|
+
const no_transaction_on_pool_1 = require("./rules/no-transaction-on-pool");
|
|
15
|
+
const no_floating_query_1 = require("./rules/no-floating-query");
|
|
16
|
+
const no_select_all_1 = require("./rules/no-select-all");
|
|
17
|
+
const prefer_pool_query_1 = require("./rules/prefer-pool-query");
|
|
18
|
+
const no_batch_insert_loop_1 = require("./rules/no-batch-insert-loop");
|
|
19
|
+
const no_unsafe_search_path_1 = require("./rules/no-unsafe-search-path");
|
|
20
|
+
const no_unsafe_copy_from_1 = require("./rules/no-unsafe-copy-from");
|
|
21
|
+
const prevent_double_release_1 = require("./rules/prevent-double-release");
|
|
22
|
+
/**
|
|
23
|
+
* Collection of all rules
|
|
24
|
+
*/
|
|
25
|
+
exports.rules = {
|
|
26
|
+
'no-unsafe-query': no_unsafe_query_1.noUnsafeQuery,
|
|
27
|
+
'no-insecure-ssl': no_insecure_ssl_1.noInsecureSsl,
|
|
28
|
+
'no-hardcoded-credentials': no_hardcoded_credentials_1.noHardcodedCredentials,
|
|
29
|
+
'check-query-params': check_query_params_1.checkQueryParams,
|
|
30
|
+
'no-missing-client-release': no_missing_client_release_1.noMissingClientRelease,
|
|
31
|
+
'no-transaction-on-pool': no_transaction_on_pool_1.noTransactionOnPool,
|
|
32
|
+
'no-floating-query': no_floating_query_1.noFloatingQuery,
|
|
33
|
+
'no-select-all': no_select_all_1.noSelectAll,
|
|
34
|
+
'prefer-pool-query': prefer_pool_query_1.preferPoolQuery,
|
|
35
|
+
'no-batch-insert-loop': no_batch_insert_loop_1.noBatchInsertLoop,
|
|
36
|
+
'no-unsafe-search-path': no_unsafe_search_path_1.noUnsafeSearchPath,
|
|
37
|
+
'no-unsafe-copy-from': no_unsafe_copy_from_1.noUnsafeCopyFrom,
|
|
38
|
+
'prevent-double-release': prevent_double_release_1.preventDoubleRelease,
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* ESLint Plugin object
|
|
42
|
+
*/
|
|
43
|
+
exports.plugin = {
|
|
44
|
+
meta: {
|
|
45
|
+
name: 'eslint-plugin-postgresql-security',
|
|
46
|
+
version: '1.4.9',
|
|
47
|
+
},
|
|
48
|
+
rules: exports.rules,
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Preset configurations
|
|
52
|
+
*/
|
|
53
|
+
exports.configs = {
|
|
54
|
+
/**
|
|
55
|
+
* Flagship preset — exactly the rule(s) from this plugin that appear in
|
|
56
|
+
* the ecosystem-wide flagship list (`.agent/flagship-rules.md`). Use this
|
|
57
|
+
* when you want the highest-signal subset shippable in CI gates without
|
|
58
|
+
* the noise of `recommended`.
|
|
59
|
+
*/
|
|
60
|
+
flagship: {
|
|
61
|
+
plugins: { 'pg': exports.plugin },
|
|
62
|
+
rules: {
|
|
63
|
+
'pg/no-unsafe-query': 'error',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Recommended preset - balanced security for most projects
|
|
68
|
+
*/
|
|
69
|
+
recommended: {
|
|
70
|
+
plugins: {
|
|
71
|
+
'pg': exports.plugin,
|
|
72
|
+
},
|
|
73
|
+
rules: {
|
|
74
|
+
// Security rules (errors)
|
|
75
|
+
'pg/no-unsafe-query': 'error',
|
|
76
|
+
'pg/no-insecure-ssl': 'error',
|
|
77
|
+
'pg/no-hardcoded-credentials': 'error',
|
|
78
|
+
'pg/no-unsafe-search-path': 'error',
|
|
79
|
+
'pg/no-unsafe-copy-from': 'error',
|
|
80
|
+
'pg/no-transaction-on-pool': 'error',
|
|
81
|
+
// Resource management (errors)
|
|
82
|
+
'pg/no-missing-client-release': 'error',
|
|
83
|
+
'pg/prevent-double-release': 'error',
|
|
84
|
+
'pg/no-floating-query': 'error',
|
|
85
|
+
// Quality (warnings)
|
|
86
|
+
'pg/check-query-params': 'warn',
|
|
87
|
+
'pg/no-select-all': 'warn',
|
|
88
|
+
'pg/prefer-pool-query': 'warn',
|
|
89
|
+
'pg/no-batch-insert-loop': 'warn',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Strict preset - all rules as errors
|
|
94
|
+
*/
|
|
95
|
+
strict: {
|
|
96
|
+
plugins: {
|
|
97
|
+
'pg': exports.plugin,
|
|
98
|
+
},
|
|
99
|
+
rules: {
|
|
100
|
+
'pg/no-unsafe-query': 'error',
|
|
101
|
+
'pg/no-insecure-ssl': 'error',
|
|
102
|
+
'pg/no-hardcoded-credentials': 'error',
|
|
103
|
+
'pg/no-unsafe-search-path': 'error',
|
|
104
|
+
'pg/no-unsafe-copy-from': 'error',
|
|
105
|
+
'pg/no-transaction-on-pool': 'error',
|
|
106
|
+
'pg/no-missing-client-release': 'error',
|
|
107
|
+
'pg/prevent-double-release': 'error',
|
|
108
|
+
'pg/no-floating-query': 'error',
|
|
109
|
+
'pg/check-query-params': 'error',
|
|
110
|
+
'pg/no-select-all': 'error',
|
|
111
|
+
'pg/prefer-pool-query': 'error',
|
|
112
|
+
'pg/no-batch-insert-loop': 'error',
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
exports.default = exports.plugin;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* oxlint sub-export.
|
|
8
|
+
*
|
|
9
|
+
* Consumers wire oxlint to this entry via:
|
|
10
|
+
* { "jsPlugins": ["eslint-plugin-postgresql-security/oxlint"] }
|
|
11
|
+
*
|
|
12
|
+
* oxlint's JS plugin loader does `require('eslint-plugin-postgresql-security/oxlint')` and reads
|
|
13
|
+
* `.rules` off the result. The compiled output of `export = plugin` is
|
|
14
|
+
* `module.exports = plugin`, which gives oxlint the plugin object directly
|
|
15
|
+
* (`{ meta, rules }`) — no wrapper, no `.default` indirection.
|
|
16
|
+
*
|
|
17
|
+
* Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
|
|
18
|
+
*/
|
|
19
|
+
import { plugin } from './index';
|
|
20
|
+
export = plugin;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* oxlint sub-export.
|
|
9
|
+
*
|
|
10
|
+
* Consumers wire oxlint to this entry via:
|
|
11
|
+
* { "jsPlugins": ["eslint-plugin-postgresql-security/oxlint"] }
|
|
12
|
+
*
|
|
13
|
+
* oxlint's JS plugin loader does `require('eslint-plugin-postgresql-security/oxlint')` and reads
|
|
14
|
+
* `.rules` off the result. The compiled output of `export = plugin` is
|
|
15
|
+
* `module.exports = plugin`, which gives oxlint the plugin object directly
|
|
16
|
+
* (`{ meta, rules }`) — no wrapper, no `.default` indirection.
|
|
17
|
+
*
|
|
18
|
+
* Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
|
|
19
|
+
*/
|
|
20
|
+
const index_1 = require("./index");
|
|
21
|
+
module.exports = index_1.plugin;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
7
|
+
import { CheckQueryParamsOptions } from '../../types';
|
|
8
|
+
export declare const checkQueryParams: TSESLint.RuleModule<'parameterCountMismatch', CheckQueryParamsOptions>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.checkQueryParams = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
// Pre-compiled regex patterns for performance
|
|
11
|
+
const SINGLE_QUOTE_REGEX = /'(?:[^']|'')*'/g;
|
|
12
|
+
const DOUBLE_QUOTE_REGEX = /"(?:[^"]|"")*"/g;
|
|
13
|
+
const LINE_COMMENT_REGEX = /--.*/g;
|
|
14
|
+
const BLOCK_COMMENT_REGEX = /\/\*[\s\S]*?\*\//g;
|
|
15
|
+
const PARAM_REGEX = /\$\d+/g;
|
|
16
|
+
exports.checkQueryParams = {
|
|
17
|
+
meta: {
|
|
18
|
+
type: 'problem',
|
|
19
|
+
docs: {
|
|
20
|
+
description: 'Ensure the number of query parameters matches the arguments array.',
|
|
21
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/check-query-params.md',
|
|
22
|
+
cwe: 'CWE-20',
|
|
23
|
+
cvss: 7.5,
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
parameterCountMismatch: (0, eslint_devkit_1.formatLLMMessage)({
|
|
27
|
+
icon: eslint_devkit_1.MessageIcons.QUALITY,
|
|
28
|
+
issueName: 'Parameter Count Mismatch',
|
|
29
|
+
description: 'Query parameter count mismatch detected.',
|
|
30
|
+
severity: 'HIGH',
|
|
31
|
+
cwe: 'CWE-20',
|
|
32
|
+
effort: 'low',
|
|
33
|
+
fix: 'Ensure the number of arguments matches the number of placeholders ($1, $2, etc.).',
|
|
34
|
+
documentationLink: 'https://node-postgres.com/features/queries',
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
schema: [],
|
|
38
|
+
},
|
|
39
|
+
defaultOptions: [],
|
|
40
|
+
create(context) {
|
|
41
|
+
return {
|
|
42
|
+
CallExpression(node) {
|
|
43
|
+
if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
|
|
44
|
+
node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
45
|
+
node.callee.property.name !== 'query') {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const args = node.arguments;
|
|
49
|
+
if (args.length < 2)
|
|
50
|
+
return;
|
|
51
|
+
const queryArg = args[0];
|
|
52
|
+
const valuesArg = args[1];
|
|
53
|
+
if (queryArg.type !== eslint_devkit_1.AST_NODE_TYPES.Literal || typeof queryArg.value !== 'string') {
|
|
54
|
+
return; // Can't statically analyze dynamic queries
|
|
55
|
+
}
|
|
56
|
+
if (valuesArg.type !== eslint_devkit_1.AST_NODE_TYPES.ArrayExpression) {
|
|
57
|
+
return; // Can't statically count dynamic arrays
|
|
58
|
+
}
|
|
59
|
+
const queryText = queryArg.value;
|
|
60
|
+
// Remove strings, quoted identifiers, and comments to avoid false positives
|
|
61
|
+
const cleanText = queryText
|
|
62
|
+
.replace(SINGLE_QUOTE_REGEX, '')
|
|
63
|
+
.replace(DOUBLE_QUOTE_REGEX, '')
|
|
64
|
+
.replace(LINE_COMMENT_REGEX, '')
|
|
65
|
+
.replace(BLOCK_COMMENT_REGEX, '');
|
|
66
|
+
const matches = cleanText.match(PARAM_REGEX);
|
|
67
|
+
let maxParamIndex = 0;
|
|
68
|
+
if (matches) {
|
|
69
|
+
const indices = matches.map(m => parseInt(m.substring(1), 10));
|
|
70
|
+
maxParamIndex = Math.max(0, ...indices);
|
|
71
|
+
}
|
|
72
|
+
// PG allows gaps, but essentially the highest index determines needed array length.
|
|
73
|
+
// Actually, strictly speaking, if you use $2, you should provide at least 2 args.
|
|
74
|
+
// But commonly, people mean "number of unique placeholders".
|
|
75
|
+
// Let's enforce that array length >= max param index.
|
|
76
|
+
const providedArgCount = valuesArg.elements.length;
|
|
77
|
+
if (providedArgCount < maxParamIndex) {
|
|
78
|
+
context.report({
|
|
79
|
+
node: valuesArg,
|
|
80
|
+
messageId: 'parameterCountMismatch',
|
|
81
|
+
data: {
|
|
82
|
+
expected: maxParamIndex.toString(),
|
|
83
|
+
actual: providedArgCount.toString(),
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
7
|
+
import { NoBatchInsertLoopOptions } from '../../types';
|
|
8
|
+
export declare const noBatchInsertLoop: TSESLint.RuleModule<'noBatchInsertLoop', NoBatchInsertLoopOptions>;
|