eslint-plugin-postgresql-security 1.5.0 → 1.5.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.
Files changed (100) hide show
  1. package/README.md +5 -5
  2. package/package.json +9 -23
  3. package/src/constants.js +4 -0
  4. package/src/index.d.ts +17 -0
  5. package/src/index.js +75 -0
  6. package/src/oxlint.d.ts +17 -0
  7. package/src/oxlint.js +3 -0
  8. package/{dist/src → src}/rules/check-query-params/index.js +2 -13
  9. package/{dist/src → src}/rules/no-batch-insert-loop/index.js +1 -14
  10. package/{dist/src → src}/rules/no-floating-query/index.js +1 -16
  11. package/{dist/src → src}/rules/no-hardcoded-credentials/index.js +1 -10
  12. package/{dist/src → src}/rules/no-insecure-ssl/index.js +0 -6
  13. package/{dist/src → src}/rules/no-missing-client-release/index.js +0 -17
  14. package/{dist/src → src}/rules/no-select-all/index.js +0 -13
  15. package/{dist/src → src}/rules/no-transaction-on-pool/index.js +0 -12
  16. package/{dist/src → src}/rules/no-unsafe-copy-from/index.js +2 -28
  17. package/{dist/src → src}/rules/no-unsafe-query/index.js +0 -26
  18. package/{dist/src → src}/rules/no-unsafe-search-path/index.js +0 -43
  19. package/{dist/src → src}/rules/prefer-pool-query/index.js +3 -20
  20. package/{dist/src → src}/rules/prevent-double-release/index.js +0 -75
  21. package/src/types/index.js +2 -0
  22. package/CHANGELOG.md +0 -150
  23. package/dist/AGENTS.md +0 -118
  24. package/dist/CHANGELOG.md +0 -150
  25. package/dist/LICENSE +0 -23
  26. package/dist/README.md +0 -169
  27. package/dist/package.json +0 -99
  28. package/dist/src/constants.d.ts +0 -6
  29. package/dist/src/constants.js +0 -13
  30. package/dist/src/index.d.ts +0 -26
  31. package/dist/src/index.js +0 -116
  32. package/dist/src/oxlint.d.ts +0 -20
  33. package/dist/src/oxlint.js +0 -21
  34. package/dist/src/rules/check-query-params/index.d.ts +0 -8
  35. package/dist/src/rules/no-batch-insert-loop/index.d.ts +0 -8
  36. package/dist/src/rules/no-floating-query/index.d.ts +0 -8
  37. package/dist/src/rules/no-hardcoded-credentials/index.d.ts +0 -8
  38. package/dist/src/rules/no-insecure-ssl/index.d.ts +0 -8
  39. package/dist/src/rules/no-missing-client-release/index.d.ts +0 -8
  40. package/dist/src/rules/no-select-all/index.d.ts +0 -8
  41. package/dist/src/rules/no-transaction-on-pool/index.d.ts +0 -8
  42. package/dist/src/rules/no-unsafe-copy-from/index.d.ts +0 -10
  43. package/dist/src/rules/no-unsafe-query/index.d.ts +0 -8
  44. package/dist/src/rules/no-unsafe-search-path/index.d.ts +0 -8
  45. package/dist/src/rules/prefer-pool-query/index.d.ts +0 -8
  46. package/dist/src/rules/prevent-double-release/index.d.ts +0 -8
  47. package/dist/src/types/index.js +0 -7
  48. package/src/__compatibility__/pg-interface.spec.ts +0 -495
  49. package/src/constants.ts +0 -11
  50. package/src/index.spec.ts +0 -14
  51. package/src/index.test.ts +0 -59
  52. package/src/index.ts +0 -130
  53. package/src/oxlint.spec.ts +0 -70
  54. package/src/oxlint.ts +0 -23
  55. package/src/rules/check-query-params/check-query-params.test.ts +0 -68
  56. package/src/rules/check-query-params/index.spec.ts +0 -117
  57. package/src/rules/check-query-params/index.ts +0 -106
  58. package/src/rules/no-batch-insert-loop/index.spec.ts +0 -105
  59. package/src/rules/no-batch-insert-loop/index.ts +0 -105
  60. package/src/rules/no-batch-insert-loop/no-batch-insert-loop.test.ts +0 -68
  61. package/src/rules/no-floating-query/index.spec.ts +0 -112
  62. package/src/rules/no-floating-query/index.ts +0 -81
  63. package/src/rules/no-floating-query/no-floating-query.test.ts +0 -68
  64. package/src/rules/no-hardcoded-credentials/index.spec.ts +0 -38
  65. package/src/rules/no-hardcoded-credentials/index.ts +0 -93
  66. package/src/rules/no-hardcoded-credentials/no-hardcoded-credentials.test.ts +0 -68
  67. package/src/rules/no-insecure-ssl/index.spec.ts +0 -40
  68. package/src/rules/no-insecure-ssl/index.ts +0 -81
  69. package/src/rules/no-insecure-ssl/no-insecure-ssl.test.ts +0 -68
  70. package/src/rules/no-missing-client-release/coverage-gaps.spec.ts +0 -42
  71. package/src/rules/no-missing-client-release/index.spec.ts +0 -52
  72. package/src/rules/no-missing-client-release/index.ts +0 -100
  73. package/src/rules/no-missing-client-release/no-missing-client-release.test.ts +0 -68
  74. package/src/rules/no-select-all/index.spec.ts +0 -44
  75. package/src/rules/no-select-all/index.ts +0 -92
  76. package/src/rules/no-select-all/no-select-all.test.ts +0 -68
  77. package/src/rules/no-transaction-on-pool/index.spec.ts +0 -36
  78. package/src/rules/no-transaction-on-pool/index.ts +0 -85
  79. package/src/rules/no-transaction-on-pool/no-transaction-on-pool.test.ts +0 -68
  80. package/src/rules/no-unsafe-copy-from/coverage-gaps.spec.ts +0 -76
  81. package/src/rules/no-unsafe-copy-from/index.spec.ts +0 -274
  82. package/src/rules/no-unsafe-copy-from/index.ts +0 -226
  83. package/src/rules/no-unsafe-copy-from/no-unsafe-copy-from.test.ts +0 -78
  84. package/src/rules/no-unsafe-query/coverage-gaps.spec.ts +0 -61
  85. package/src/rules/no-unsafe-query/index.spec.ts +0 -103
  86. package/src/rules/no-unsafe-query/index.ts +0 -149
  87. package/src/rules/no-unsafe-query/no-unsafe-query.test.ts +0 -73
  88. package/src/rules/no-unsafe-search-path/index.spec.ts +0 -46
  89. package/src/rules/no-unsafe-search-path/index.ts +0 -164
  90. package/src/rules/no-unsafe-search-path/no-unsafe-search-path.test.ts +0 -68
  91. package/src/rules/prefer-pool-query/coverage-gaps.spec.ts +0 -76
  92. package/src/rules/prefer-pool-query/index.spec.ts +0 -97
  93. package/src/rules/prefer-pool-query/index.ts +0 -118
  94. package/src/rules/prefer-pool-query/prefer-pool-query.test.ts +0 -68
  95. package/src/rules/prevent-double-release/coverage-gaps.spec.ts +0 -538
  96. package/src/rules/prevent-double-release/index.spec.ts +0 -824
  97. package/src/rules/prevent-double-release/index.ts +0 -534
  98. package/src/rules/prevent-double-release/prevent-double-release.test.ts +0 -70
  99. package/src/types/index.ts +0 -58
  100. /package/{dist/src → src}/types/index.d.ts +0 -0
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
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>
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/logos/interlace.svg" alt="Interlace" height="90" /></a>
3
3
  &nbsp;&nbsp;
4
- <a href="https://eslint.org" target="_blank"><img src="https://eslint.interlace.tools/eslint-logo.svg" alt="ESLint" height="90" /></a>
4
+ <a href="https://www.postgresql.org" target="_blank"><img src="https://eslint.interlace.tools/logos/postgresql.svg" alt="PostgreSQL" height="90" /></a>
5
5
  &nbsp;&nbsp;
6
- <a href="https://oxc.rs" target="_blank"><img src="https://eslint.interlace.tools/oxlint-logo.svg" alt="oxlint" height="90" /></a>
6
+ <a href="https://oxc.rs" target="_blank"><img src="https://eslint.interlace.tools/logos/oxlint.svg" alt="oxlint" height="90" /></a>
7
7
  &nbsp;&nbsp;
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>
8
+ <a href="https://eslint.org" target="_blank"><img src="https://eslint.interlace.tools/logos/eslint.svg" alt="ESLint" height="90" /></a>
9
9
  </p>
10
10
 
11
11
  <p align="center">
@@ -161,7 +161,7 @@ If this plugin caught a real bug for you, **[star the repo](https://github.com/o
161
161
  MIT © [Ofri Peretz](https://github.com/ofri-peretz)
162
162
 
163
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>
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-postgresql-security.png" alt="ESLint Interlace Plugin" width="100%" /></a>
165
165
  </p>
166
166
 
167
167
  <p align="center">
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "eslint-plugin-postgresql-security",
3
- "version": "1.5.0",
4
- "description": "ESLint plugin for the pg PostgreSQL driver \u2014 detects SQL injection, unreleased clients, floating queries, unsafe search_path, and insecure SSL.",
3
+ "version": "1.5.1",
4
+ "description": "ESLint plugin for the pg PostgreSQL driver — detects SQL injection, unreleased clients, floating queries, unsafe search_path, and insecure SSL.",
5
5
  "type": "commonjs",
6
- "main": "./dist/src/index.js",
7
- "types": "./dist/src/index.d.ts",
6
+ "main": "./src/index.js",
7
+ "types": "./src/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/src/index.d.ts",
11
- "default": "./dist/src/index.js"
10
+ "types": "./src/index.d.ts",
11
+ "default": "./src/index.js"
12
12
  },
13
13
  "./oxlint": {
14
14
  "types": "./src/oxlint.d.ts",
@@ -20,7 +20,7 @@
20
20
  "homepage": "https://eslint.interlace.tools/docs/security/plugin-postgresql-security?utm_source=npm&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security",
21
21
  "repository": {
22
22
  "type": "git",
23
- "url": "https://github.com/ofri-peretz/eslint",
23
+ "url": "git+https://github.com/ofri-peretz/eslint.git",
24
24
  "directory": "packages/eslint-plugin-postgresql-security"
25
25
  },
26
26
  "bugs": {
@@ -31,10 +31,8 @@
31
31
  },
32
32
  "files": [
33
33
  "src/",
34
- "dist/",
35
34
  "README.md",
36
- "LICENSE",
37
- "CHANGELOG.md"
35
+ "LICENSE"
38
36
  ],
39
37
  "keywords": [
40
38
  "eslint",
@@ -78,19 +76,7 @@
78
76
  }
79
77
  },
80
78
  "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"
79
+ "@interlace/eslint-devkit": "^1.8.0"
94
80
  },
95
81
  "funding": {
96
82
  "type": "github",
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PG_PROTOCOLS = void 0;
4
+ exports.PG_PROTOCOLS = ['postgres://', 'postgresql://'];
package/src/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ // Minimal declaration written by scripts/build-package.ts.
2
+ //
3
+ // tsc's generated entry declaration inlined every inferred rule-option type
4
+ // (up to 166 kB per plugin) for an API no consumer calls directly. This types
5
+ // what a flat config actually touches. Per-rule option types remain available
6
+ // from the "./types" subpath export where a plugin provides one.
7
+ import type { Linter, Rule } from 'eslint';
8
+
9
+ export declare const rules: Record<string, Rule.RuleModule>;
10
+ export declare const configs: Record<string, Linter.Config>;
11
+ export declare const plugin: {
12
+ meta: { name: string; version: string };
13
+ rules: Record<string, Rule.RuleModule>;
14
+ };
15
+
16
+ declare const _default: typeof plugin;
17
+ export default _default;
package/src/index.js ADDED
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configs = exports.plugin = exports.rules = void 0;
4
+ exports.rules = {
5
+ get 'no-unsafe-query'() { return require("./rules/no-unsafe-query").noUnsafeQuery; },
6
+ get 'no-insecure-ssl'() { return require("./rules/no-insecure-ssl").noInsecureSsl; },
7
+ get 'no-hardcoded-credentials'() { return require("./rules/no-hardcoded-credentials").noHardcodedCredentials; },
8
+ get 'check-query-params'() { return require("./rules/check-query-params").checkQueryParams; },
9
+ get 'no-missing-client-release'() { return require("./rules/no-missing-client-release").noMissingClientRelease; },
10
+ get 'no-transaction-on-pool'() { return require("./rules/no-transaction-on-pool").noTransactionOnPool; },
11
+ get 'no-floating-query'() { return require("./rules/no-floating-query").noFloatingQuery; },
12
+ get 'no-select-all'() { return require("./rules/no-select-all").noSelectAll; },
13
+ get 'prefer-pool-query'() { return require("./rules/prefer-pool-query").preferPoolQuery; },
14
+ get 'no-batch-insert-loop'() { return require("./rules/no-batch-insert-loop").noBatchInsertLoop; },
15
+ get 'no-unsafe-search-path'() { return require("./rules/no-unsafe-search-path").noUnsafeSearchPath; },
16
+ get 'no-unsafe-copy-from'() { return require("./rules/no-unsafe-copy-from").noUnsafeCopyFrom; },
17
+ get 'prevent-double-release'() { return require("./rules/prevent-double-release").preventDoubleRelease; },
18
+
19
+ };
20
+ exports.plugin = {
21
+ meta: {
22
+ name: 'eslint-plugin-postgresql-security',
23
+ version: '1.5.1',
24
+ },
25
+ rules: exports.rules,
26
+ };
27
+ exports.configs = {
28
+ flagship: {
29
+ plugins: { 'pg': exports.plugin },
30
+ rules: {
31
+ 'pg/no-unsafe-query': 'error',
32
+ },
33
+ },
34
+ recommended: {
35
+ plugins: {
36
+ 'pg': exports.plugin,
37
+ },
38
+ rules: {
39
+ 'pg/no-unsafe-query': 'error',
40
+ 'pg/no-insecure-ssl': 'error',
41
+ 'pg/no-hardcoded-credentials': 'error',
42
+ 'pg/no-unsafe-search-path': 'error',
43
+ 'pg/no-unsafe-copy-from': 'error',
44
+ 'pg/no-transaction-on-pool': 'error',
45
+ 'pg/no-missing-client-release': 'error',
46
+ 'pg/prevent-double-release': 'error',
47
+ 'pg/no-floating-query': 'error',
48
+ 'pg/check-query-params': 'warn',
49
+ 'pg/no-select-all': 'warn',
50
+ 'pg/prefer-pool-query': 'warn',
51
+ 'pg/no-batch-insert-loop': 'warn',
52
+ },
53
+ },
54
+ strict: {
55
+ plugins: {
56
+ 'pg': exports.plugin,
57
+ },
58
+ rules: {
59
+ 'pg/no-unsafe-query': 'error',
60
+ 'pg/no-insecure-ssl': 'error',
61
+ 'pg/no-hardcoded-credentials': 'error',
62
+ 'pg/no-unsafe-search-path': 'error',
63
+ 'pg/no-unsafe-copy-from': 'error',
64
+ 'pg/no-transaction-on-pool': 'error',
65
+ 'pg/no-missing-client-release': 'error',
66
+ 'pg/prevent-double-release': 'error',
67
+ 'pg/no-floating-query': 'error',
68
+ 'pg/check-query-params': 'error',
69
+ 'pg/no-select-all': 'error',
70
+ 'pg/prefer-pool-query': 'error',
71
+ 'pg/no-batch-insert-loop': 'error',
72
+ },
73
+ },
74
+ };
75
+ exports.default = exports.plugin;
@@ -0,0 +1,17 @@
1
+ // Minimal declaration written by scripts/build-package.ts.
2
+ //
3
+ // tsc's generated entry declaration inlined every inferred rule-option type
4
+ // (up to 166 kB per plugin) for an API no consumer calls directly. This types
5
+ // what a flat config actually touches. Per-rule option types remain available
6
+ // from the "./types" subpath export where a plugin provides one.
7
+ import type { Linter, Rule } from 'eslint';
8
+
9
+ export declare const rules: Record<string, Rule.RuleModule>;
10
+ export declare const configs: Record<string, Linter.Config>;
11
+ export declare const plugin: {
12
+ meta: { name: string; version: string };
13
+ rules: Record<string, Rule.RuleModule>;
14
+ };
15
+
16
+ declare const _default: typeof plugin;
17
+ export default _default;
package/src/oxlint.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ const index_1 = require("./index");
3
+ module.exports = index_1.plugin;
@@ -1,13 +1,7 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.checkQueryParams = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- // Pre-compiled regex patterns for performance
11
5
  const SINGLE_QUOTE_REGEX = /'(?:[^']|'')*'/g;
12
6
  const DOUBLE_QUOTE_REGEX = /"(?:[^"]|"")*"/g;
13
7
  const LINE_COMMENT_REGEX = /--.*/g;
@@ -51,13 +45,12 @@ exports.checkQueryParams = {
51
45
  const queryArg = args[0];
52
46
  const valuesArg = args[1];
53
47
  if (queryArg.type !== eslint_devkit_1.AST_NODE_TYPES.Literal || typeof queryArg.value !== 'string') {
54
- return; // Can't statically analyze dynamic queries
48
+ return;
55
49
  }
56
50
  if (valuesArg.type !== eslint_devkit_1.AST_NODE_TYPES.ArrayExpression) {
57
- return; // Can't statically count dynamic arrays
51
+ return;
58
52
  }
59
53
  const queryText = queryArg.value;
60
- // Remove strings, quoted identifiers, and comments to avoid false positives
61
54
  const cleanText = queryText
62
55
  .replace(SINGLE_QUOTE_REGEX, '')
63
56
  .replace(DOUBLE_QUOTE_REGEX, '')
@@ -69,10 +62,6 @@ exports.checkQueryParams = {
69
62
  const indices = matches.map(m => parseInt(m.substring(1), 10));
70
63
  maxParamIndex = Math.max(0, ...indices);
71
64
  }
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
65
  const providedArgCount = valuesArg.elements.length;
77
66
  if (providedArgCount < maxParamIndex) {
78
67
  context.report({
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noBatchInsertLoop = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -43,7 +38,7 @@ exports.noBatchInsertLoop = {
43
38
  if (args.length > 0 && args[0].type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof args[0].value === 'string') {
44
39
  const query = args[0].value.toUpperCase();
45
40
  if (!query.includes('INSERT') && !query.includes('UPDATE')) {
46
- return; // Only care about mutations usually, SELECT N+1 is also bad but maybe 'no-loop-query' is separate
41
+ return;
47
42
  }
48
43
  }
49
44
  let ancestor = node.parent;
@@ -59,7 +54,6 @@ exports.noBatchInsertLoop = {
59
54
  });
60
55
  break;
61
56
  }
62
- // Check for function expressions that are callbacks to array methods
63
57
  if ((ancestor.type === eslint_devkit_1.AST_NODE_TYPES.FunctionExpression || ancestor.type === eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression)) {
64
58
  if (ancestor.parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
65
59
  ancestor.parent.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
@@ -71,14 +65,7 @@ exports.noBatchInsertLoop = {
71
65
  });
72
66
  break;
73
67
  }
74
- // Stop traversal at function boundary unless it's an IIFE?
75
- // Actually if we are in a function, we stop unless that function IS the loop body callback.
76
- // If we are in `function foo() { while(...) { query } }` -> we hit WhileStatement first.
77
- // If we are in `users.map(u => query(u))` -> query -> ArrowFunc -> CallExpression(map).
78
- // So if we hit a function, we must check if it's the specific loop callback.
79
- // If not, we stop (don't flag loop outside of function definition, that's weird).
80
68
  if (ancestor.parent?.type !== eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
81
- // It's a regular function definition, stop going up (don't blame caller's loop).
82
69
  break;
83
70
  }
84
71
  }
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noFloatingQuery = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -39,29 +34,19 @@ exports.noFloatingQuery = {
39
34
  node.callee.property.name !== 'query') {
40
35
  return;
41
36
  }
42
- // Check parent node to see if the promise is handled
43
37
  const parent = node.parent;
44
- // Allowed parents:
45
- // 1. AwaitExpression: await client.query(...)
46
38
  if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.AwaitExpression)
47
39
  return;
48
- // 2. ReturnStatement: return client.query(...)
49
40
  if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)
50
41
  return;
51
- // 3. ArrowFunctionExpression (implicit return): () => client.query(...)
52
42
  if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression)
53
43
  return;
54
- // 4. VariableDeclarator: const p = client.query(...) -> Assumed handled if assigned
55
44
  if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator)
56
45
  return;
57
- // 5. MemberExpression: client.query(...).then(...) or .catch(...)
58
46
  if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
59
- return; // check chains?
60
- // 6. AssignmentExpression: p = client.query(...)
47
+ return;
61
48
  if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression)
62
49
  return;
63
- // If specific to typical void usage:
64
- // ExpressionStatement: client.query(...); -> This is bad!
65
50
  if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.ExpressionStatement) {
66
51
  context.report({
67
52
  node,
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noHardcodedCredentials = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -43,23 +38,20 @@ exports.noHardcodedCredentials = {
43
38
  if (node.arguments.length === 0)
44
39
  return;
45
40
  const configArg = node.arguments[0];
46
- // Case 1: Connection string literal 'postgres://user:pass@localhost:5432/db'
47
41
  if (configArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof configArg.value === 'string') {
48
42
  if (constants_1.PG_PROTOCOLS.some(protocol => configArg.value.includes(protocol))) {
49
43
  context.report({
50
44
  node: configArg,
51
45
  messageId: 'noHardcodedCredentials',
52
46
  });
53
- return; // Return after reporting for Case 1
47
+ return;
54
48
  }
55
49
  }
56
- // Case 2: new Client({ password: 'secret', connectionString: '...' })
57
50
  if (configArg.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
58
51
  for (const prop of configArg.properties) {
59
52
  if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property || prop.key.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier) {
60
53
  continue;
61
54
  }
62
- // Check for 'password' field
63
55
  if (prop.key.name === 'password') {
64
56
  if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
65
57
  context.report({
@@ -69,7 +61,6 @@ exports.noHardcodedCredentials = {
69
61
  }
70
62
  continue;
71
63
  }
72
- // Check for 'connectionString' field
73
64
  if (prop.key.name === 'connectionString') {
74
65
  if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
75
66
  context.report({
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noInsecureSsl = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -46,7 +41,6 @@ exports.noInsecureSsl = {
46
41
  const sslProp = configArg.properties.find((prop) => prop.type === eslint_devkit_1.AST_NODE_TYPES.Property && prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && prop.key.name === 'ssl');
47
42
  if (!sslProp)
48
43
  return;
49
- // ssl: { rejectUnauthorized: false }
50
44
  if (sslProp.value.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
51
45
  const rejectUnauthorized = sslProp.value.properties.find((prop) => prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
52
46
  prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noMissingClientRelease = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -33,17 +28,11 @@ exports.noMissingClientRelease = {
33
28
  create(context) {
34
29
  return {
35
30
  CallExpression(node) {
36
- // Detect: const client = await pool.connect() or pool.connect().then(client => ...)
37
- // For simplicity, we focus on await usage in async functions, which is the modern pattern.
38
31
  if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
39
32
  node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
40
33
  node.callee.property.name !== 'connect') {
41
34
  return;
42
35
  }
43
- // We assume valid code would assign the result: const client = await pool.connect()
44
- // Parent of CallExpression is AwaitExpression (usually)
45
- // Parent of AwaitExpression is VariableDeclarator
46
- // Check ancestry up to VariableDeclarator
47
36
  let currentNode = node;
48
37
  if (node.parent?.type === eslint_devkit_1.AST_NODE_TYPES.AwaitExpression) {
49
38
  currentNode = node.parent;
@@ -53,20 +42,14 @@ exports.noMissingClientRelease = {
53
42
  }
54
43
  const declarator = currentNode.parent;
55
44
  if (declarator.id.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier) {
56
- // Destructuring not supported for basic check yet
57
45
  return;
58
46
  }
59
- // Variable name is available as declarator.id.name if needed for debugging
60
- // Find the scope of the variable
61
47
  const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
62
48
  if (!variable)
63
49
  return;
64
- // Check references to this variable
65
- // We look for client.release() call
66
50
  const references = variable.references;
67
51
  const hasReleaseCall = references.some(ref => {
68
52
  const id = ref.identifier;
69
- // Check if identifier is part of member expression 'client.release()' calls
70
53
  return (id.parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
71
54
  id.parent.object === id &&
72
55
  id.parent.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
@@ -1,13 +1,7 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noSelectAll = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- // Pre-compiled regex patterns for performance
11
5
  const COUNT_STAR_REGEX = /COUNT\s*\(\s*\*\s*\)/g;
12
6
  const SELECT_STAR_REGEX = /\bSELECT\s+\*/;
13
7
  const COMMA_STAR_REGEX = /,\s*\*/;
@@ -54,16 +48,9 @@ exports.noSelectAll = {
54
48
  }
55
49
  const queryText = queryArg.value;
56
50
  const upperQuery = queryText.toUpperCase();
57
- // Exclude count(*) from the check by removing it temporarily
58
51
  const cleanedQuery = upperQuery.replace(COUNT_STAR_REGEX, 'COUNT_ALL');
59
- // Check for "SELECT *"
60
- // 1. SELECT followed immediately by * (with spaces) -> SELECT *
61
- // 2. Comma followed by * -> SELECT a, *
62
- // BUT exclude SELECT * FROM UNNEST which is idiomatic for bulk inserts
63
52
  if (SELECT_STAR_REGEX.test(cleanedQuery) || COMMA_STAR_REGEX.test(cleanedQuery)) {
64
- // Ensure it is actually a SELECT query
65
53
  if (SELECT_KEYWORD_REGEX.test(cleanedQuery)) {
66
- // Exclude SELECT * FROM UNNEST (idiomatic bulk insert pattern)
67
54
  if (UNNEST_PATTERN_REGEX.test(cleanedQuery)) {
68
55
  return;
69
56
  }
@@ -1,13 +1,7 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noTransactionOnPool = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- // Pre-defined set of transaction keywords for fast lookup
11
5
  const TRANSACTION_KEYWORDS = new Set(['BEGIN', 'COMMIT', 'ROLLBACK']);
12
6
  exports.noTransactionOnPool = {
13
7
  meta: {
@@ -45,18 +39,12 @@ exports.noTransactionOnPool = {
45
39
  if (args.length === 0)
46
40
  return;
47
41
  const queryArg = args[0];
48
- // Only check literals
49
42
  if (queryArg.type !== eslint_devkit_1.AST_NODE_TYPES.Literal || typeof queryArg.value !== 'string') {
50
43
  return;
51
44
  }
52
45
  const queryText = queryArg.value.toUpperCase().trim();
53
- // Extract first word (handles "BEGIN", "BEGIN;", "BEGIN TRANSACTION", etc.)
54
46
  const firstWord = queryText.split(/[;\s]/)[0];
55
47
  if (TRANSACTION_KEYWORDS.has(firstWord)) {
56
- // Heuristic: If the variable name is 'pool' or ends with 'Pool', stronger signal.
57
- // However, for safety, if we see pool.query('BEGIN'), it's almost always wrong unless it's a test mock.
58
- // Let's rely on variable name hint for false positive reduction, or just flag it generally.
59
- // The most common error is `pool.query('BEGIN')`.
60
48
  if (node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
61
49
  (node.callee.object.name === 'pool' || node.callee.object.name.toLowerCase().includes('pool'))) {
62
50
  context.report({
@@ -1,20 +1,11 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noUnsafeCopyFrom = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- // Pre-compiled regex patterns for performance
11
5
  const COPY_FROM_REGEX = /\bCOPY\b.*\bFROM\b/i;
12
6
  const STDIN_REGEX = /\bFROM\s+STDIN\b/i;
13
- // Extract file path from COPY FROM 'path' pattern
14
7
  const FILE_PATH_REGEX = /FROM\s+['"]([^'"]+)['"]/i;
15
- // Helper to check for COPY FROM (but not COPY FROM STDIN)
16
8
  const hasCopyFrom = (str) => COPY_FROM_REGEX.test(str) && !STDIN_REGEX.test(str);
17
- // Extract file path from COPY statement
18
9
  const extractFilePath = (str) => {
19
10
  const match = FILE_PATH_REGEX.exec(str);
20
11
  return match ? match[1] : null;
@@ -85,7 +76,6 @@ exports.noUnsafeCopyFrom = {
85
76
  const options = context.options[0] ?? {};
86
77
  const allowHardcodedPaths = options.allowHardcodedPaths ?? false;
87
78
  const allowedPaths = (options.allowedPaths ?? []).map((p) => new RegExp(p));
88
- // Check if a file path matches any allowed pattern
89
79
  const isPathAllowed = (filePath) => {
90
80
  return allowedPaths.some((pattern) => pattern.test(filePath));
91
81
  };
@@ -100,17 +90,14 @@ exports.noUnsafeCopyFrom = {
100
90
  if (args.length === 0)
101
91
  return;
102
92
  const queryArg = args[0];
103
- // Case 1: Literal string - can fully analyze
104
93
  if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof queryArg.value === 'string') {
105
94
  if (hasCopyFrom(queryArg.value)) {
106
95
  const filePath = extractFilePath(queryArg.value);
107
- // Check if path is in allowlist
108
96
  if (filePath && isPathAllowed(filePath)) {
109
- return; // Explicitly allowed
97
+ return;
110
98
  }
111
- // Hardcoded path - report as medium severity (or skip if allowed)
112
99
  if (allowHardcodedPaths) {
113
- return; // User opted to allow hardcoded paths
100
+ return;
114
101
  }
115
102
  context.report({
116
103
  node: queryArg,
@@ -119,11 +106,9 @@ exports.noUnsafeCopyFrom = {
119
106
  }
120
107
  return;
121
108
  }
122
- // Case 2: Template literal - check for dynamic expressions
123
109
  if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
124
110
  const staticText = queryArg.quasis.map(q => q.value.raw).join(' ');
125
111
  if (hasCopyFrom(staticText)) {
126
- // Has expressions = dynamic = CRITICAL
127
112
  if (queryArg.expressions.length > 0) {
128
113
  context.report({
129
114
  node: queryArg,
@@ -131,7 +116,6 @@ exports.noUnsafeCopyFrom = {
131
116
  });
132
117
  }
133
118
  else {
134
- // No expressions = effectively a static string
135
119
  const filePath = extractFilePath(staticText);
136
120
  if (filePath && isPathAllowed(filePath)) {
137
121
  return;
@@ -146,7 +130,6 @@ exports.noUnsafeCopyFrom = {
146
130
  }
147
131
  return;
148
132
  }
149
- // Case 3: Binary expression (string concatenation)
150
133
  if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
151
134
  const parts = [];
152
135
  let hasDynamicPart = false;
@@ -160,7 +143,6 @@ exports.noUnsafeCopyFrom = {
160
143
  parts.push(curr.value);
161
144
  }
162
145
  else {
163
- // Non-literal part = dynamic
164
146
  hasDynamicPart = true;
165
147
  }
166
148
  }
@@ -173,7 +155,6 @@ exports.noUnsafeCopyFrom = {
173
155
  });
174
156
  }
175
157
  else {
176
- // All literals - treat as hardcoded
177
158
  const filePath = extractFilePath(staticText);
178
159
  if (filePath && isPathAllowed(filePath)) {
179
160
  return;
@@ -188,15 +169,8 @@ exports.noUnsafeCopyFrom = {
188
169
  }
189
170
  return;
190
171
  }
191
- // Case 4: Identifier or CallExpression - cannot verify statically
192
172
  if (queryArg.type === eslint_devkit_1.AST_NODE_TYPES.Identifier ||
193
173
  queryArg.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
194
- // We can't see what's in the variable/function - flag as unverifiable
195
- // This catches: client.query(sqlQuery) or client.query(buildQuery())
196
- // We report as medium severity since we can't confirm it's COPY FROM
197
- // Actually, we can't even confirm it's COPY FROM, so let's not report
198
- // unless we want to be very aggressive. For now, skip these.
199
- // The user would need to ensure the source is safe.
200
174
  return;
201
175
  }
202
176
  },