eslint-plugin-postgresql-security 1.5.0 → 1.5.2

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 (113) hide show
  1. package/README.md +5 -5
  2. package/package.json +9 -23
  3. package/src/constants.js +1 -0
  4. package/src/index.d.ts +17 -0
  5. package/src/index.js +1 -0
  6. package/src/oxlint.d.ts +17 -0
  7. package/src/oxlint.js +1 -0
  8. package/src/rules/check-query-params/index.js +1 -0
  9. package/src/rules/no-batch-insert-loop/index.js +1 -0
  10. package/src/rules/no-floating-query/index.js +1 -0
  11. package/src/rules/no-hardcoded-credentials/index.js +1 -0
  12. package/src/rules/no-insecure-ssl/index.js +1 -0
  13. package/src/rules/no-missing-client-release/index.js +1 -0
  14. package/src/rules/no-select-all/index.js +1 -0
  15. package/src/rules/no-transaction-on-pool/index.js +1 -0
  16. package/src/rules/no-unsafe-copy-from/index.js +1 -0
  17. package/src/rules/no-unsafe-query/index.js +1 -0
  18. package/src/rules/no-unsafe-search-path/index.js +1 -0
  19. package/src/rules/prefer-pool-query/index.js +1 -0
  20. package/src/rules/prevent-double-release/index.js +1 -0
  21. package/src/types/index.js +1 -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/check-query-params/index.js +0 -90
  36. package/dist/src/rules/no-batch-insert-loop/index.d.ts +0 -8
  37. package/dist/src/rules/no-batch-insert-loop/index.js +0 -90
  38. package/dist/src/rules/no-floating-query/index.d.ts +0 -8
  39. package/dist/src/rules/no-floating-query/index.js +0 -74
  40. package/dist/src/rules/no-hardcoded-credentials/index.d.ts +0 -8
  41. package/dist/src/rules/no-hardcoded-credentials/index.js +0 -86
  42. package/dist/src/rules/no-insecure-ssl/index.d.ts +0 -8
  43. package/dist/src/rules/no-insecure-ssl/index.js +0 -66
  44. package/dist/src/rules/no-missing-client-release/index.d.ts +0 -8
  45. package/dist/src/rules/no-missing-client-release/index.js +0 -85
  46. package/dist/src/rules/no-select-all/index.d.ts +0 -8
  47. package/dist/src/rules/no-select-all/index.js +0 -79
  48. package/dist/src/rules/no-transaction-on-pool/index.d.ts +0 -8
  49. package/dist/src/rules/no-transaction-on-pool/index.js +0 -71
  50. package/dist/src/rules/no-unsafe-copy-from/index.d.ts +0 -10
  51. package/dist/src/rules/no-unsafe-copy-from/index.js +0 -205
  52. package/dist/src/rules/no-unsafe-query/index.d.ts +0 -8
  53. package/dist/src/rules/no-unsafe-query/index.js +0 -132
  54. package/dist/src/rules/no-unsafe-search-path/index.d.ts +0 -8
  55. package/dist/src/rules/no-unsafe-search-path/index.js +0 -144
  56. package/dist/src/rules/prefer-pool-query/index.d.ts +0 -8
  57. package/dist/src/rules/prefer-pool-query/index.js +0 -104
  58. package/dist/src/rules/prevent-double-release/index.d.ts +0 -8
  59. package/dist/src/rules/prevent-double-release/index.js +0 -456
  60. package/dist/src/types/index.js +0 -7
  61. package/src/__compatibility__/pg-interface.spec.ts +0 -495
  62. package/src/constants.ts +0 -11
  63. package/src/index.spec.ts +0 -14
  64. package/src/index.test.ts +0 -59
  65. package/src/index.ts +0 -130
  66. package/src/oxlint.spec.ts +0 -70
  67. package/src/oxlint.ts +0 -23
  68. package/src/rules/check-query-params/check-query-params.test.ts +0 -68
  69. package/src/rules/check-query-params/index.spec.ts +0 -117
  70. package/src/rules/check-query-params/index.ts +0 -106
  71. package/src/rules/no-batch-insert-loop/index.spec.ts +0 -105
  72. package/src/rules/no-batch-insert-loop/index.ts +0 -105
  73. package/src/rules/no-batch-insert-loop/no-batch-insert-loop.test.ts +0 -68
  74. package/src/rules/no-floating-query/index.spec.ts +0 -112
  75. package/src/rules/no-floating-query/index.ts +0 -81
  76. package/src/rules/no-floating-query/no-floating-query.test.ts +0 -68
  77. package/src/rules/no-hardcoded-credentials/index.spec.ts +0 -38
  78. package/src/rules/no-hardcoded-credentials/index.ts +0 -93
  79. package/src/rules/no-hardcoded-credentials/no-hardcoded-credentials.test.ts +0 -68
  80. package/src/rules/no-insecure-ssl/index.spec.ts +0 -40
  81. package/src/rules/no-insecure-ssl/index.ts +0 -81
  82. package/src/rules/no-insecure-ssl/no-insecure-ssl.test.ts +0 -68
  83. package/src/rules/no-missing-client-release/coverage-gaps.spec.ts +0 -42
  84. package/src/rules/no-missing-client-release/index.spec.ts +0 -52
  85. package/src/rules/no-missing-client-release/index.ts +0 -100
  86. package/src/rules/no-missing-client-release/no-missing-client-release.test.ts +0 -68
  87. package/src/rules/no-select-all/index.spec.ts +0 -44
  88. package/src/rules/no-select-all/index.ts +0 -92
  89. package/src/rules/no-select-all/no-select-all.test.ts +0 -68
  90. package/src/rules/no-transaction-on-pool/index.spec.ts +0 -36
  91. package/src/rules/no-transaction-on-pool/index.ts +0 -85
  92. package/src/rules/no-transaction-on-pool/no-transaction-on-pool.test.ts +0 -68
  93. package/src/rules/no-unsafe-copy-from/coverage-gaps.spec.ts +0 -76
  94. package/src/rules/no-unsafe-copy-from/index.spec.ts +0 -274
  95. package/src/rules/no-unsafe-copy-from/index.ts +0 -226
  96. package/src/rules/no-unsafe-copy-from/no-unsafe-copy-from.test.ts +0 -78
  97. package/src/rules/no-unsafe-query/coverage-gaps.spec.ts +0 -61
  98. package/src/rules/no-unsafe-query/index.spec.ts +0 -103
  99. package/src/rules/no-unsafe-query/index.ts +0 -149
  100. package/src/rules/no-unsafe-query/no-unsafe-query.test.ts +0 -73
  101. package/src/rules/no-unsafe-search-path/index.spec.ts +0 -46
  102. package/src/rules/no-unsafe-search-path/index.ts +0 -164
  103. package/src/rules/no-unsafe-search-path/no-unsafe-search-path.test.ts +0 -68
  104. package/src/rules/prefer-pool-query/coverage-gaps.spec.ts +0 -76
  105. package/src/rules/prefer-pool-query/index.spec.ts +0 -97
  106. package/src/rules/prefer-pool-query/index.ts +0 -118
  107. package/src/rules/prefer-pool-query/prefer-pool-query.test.ts +0 -68
  108. package/src/rules/prevent-double-release/coverage-gaps.spec.ts +0 -538
  109. package/src/rules/prevent-double-release/index.spec.ts +0 -824
  110. package/src/rules/prevent-double-release/index.ts +0 -534
  111. package/src/rules/prevent-double-release/prevent-double-release.test.ts +0 -70
  112. package/src/types/index.ts +0 -58
  113. /package/{dist/src → src}/types/index.d.ts +0 -0
@@ -1,456 +0,0 @@
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.preventDoubleRelease = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- /**
11
- * Finds the nearest ancestor of a given type.
12
- */
13
- function findAncestor(node, predicate) {
14
- let current = node?.parent;
15
- while (current) {
16
- if (predicate(current))
17
- return current;
18
- current = current.parent;
19
- }
20
- return null;
21
- }
22
- /**
23
- * Checks if node is inside a TryStatement's catch block
24
- */
25
- function isInCatchBlock(node) {
26
- return findAncestor(node, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.CatchClause);
27
- }
28
- /**
29
- * Checks if node is inside a TryStatement's finally block
30
- */
31
- function isInFinallyBlock(node) {
32
- const tryStmt = findAncestor(node, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.TryStatement);
33
- if (!tryStmt?.finalizer)
34
- return null;
35
- const nodeRange = node.range;
36
- const finalizerRange = tryStmt.finalizer.range;
37
- if (nodeRange[0] >= finalizerRange[0] && nodeRange[1] <= finalizerRange[1]) {
38
- return tryStmt;
39
- }
40
- return null;
41
- }
42
- /**
43
- * Checks if node is inside a TryStatement's try block
44
- */
45
- function isInTryBlock(node) {
46
- const tryStmt = findAncestor(node, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.TryStatement);
47
- if (!tryStmt)
48
- return null;
49
- const nodeRange = node.range;
50
- const blockRange = tryStmt.block.range;
51
- if (nodeRange[0] >= blockRange[0] && nodeRange[1] <= blockRange[1]) {
52
- return tryStmt;
53
- }
54
- return null;
55
- }
56
- /**
57
- * Gets the containing function for a node
58
- */
59
- function getContainingFunction(node) {
60
- return findAncestor(node, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration ||
61
- n.type === eslint_devkit_1.AST_NODE_TYPES.FunctionExpression ||
62
- n.type === eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression);
63
- }
64
- /**
65
- * Checks if node is guarded by a conditional check (e.g., if (!released))
66
- */
67
- function isGuardedByCondition(node) {
68
- const ifStmt = findAncestor(node, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement);
69
- if (!ifStmt)
70
- return false;
71
- const conditionText = ifStmt.test;
72
- // Check for patterns like: !released, released === false, !client.released
73
- if (conditionText.type === eslint_devkit_1.AST_NODE_TYPES.UnaryExpression && conditionText.operator === '!') {
74
- const arg = conditionText.argument;
75
- if (arg.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
76
- const name = arg.name.toLowerCase();
77
- return name.includes('released') || name.includes('done') || name.includes('closed');
78
- }
79
- if (arg.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression && arg.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
80
- const name = arg.property.name.toLowerCase();
81
- return name.includes('released') || name.includes('done') || name.includes('closed');
82
- }
83
- }
84
- return false;
85
- }
86
- /**
87
- * Checks if a node is in an else-if/else branch that's mutually exclusive from another
88
- */
89
- function areMutuallyExclusiveBranches(nodeA, nodeB) {
90
- const ifA = findAncestor(nodeA, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement);
91
- const ifB = findAncestor(nodeB, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement);
92
- if (!ifA || !ifB)
93
- return false;
94
- // Check if both are in the same if/else chain
95
- if (ifA === ifB) {
96
- const nodeARange = nodeA.range;
97
- const nodeBRange = nodeB.range;
98
- const consequentRange = ifA.consequent.range;
99
- const alternateRange = ifA.alternate?.range;
100
- if (!alternateRange)
101
- return false;
102
- const aInConsequent = nodeARange[0] >= consequentRange[0] && nodeARange[1] <= consequentRange[1];
103
- const bInConsequent = nodeBRange[0] >= consequentRange[0] && nodeBRange[1] <= consequentRange[1];
104
- const aInAlternate = nodeARange[0] >= alternateRange[0] && nodeARange[1] <= alternateRange[1];
105
- const bInAlternate = nodeBRange[0] >= alternateRange[0] && nodeBRange[1] <= alternateRange[1];
106
- return (aInConsequent && bInAlternate) || (aInAlternate && bInConsequent);
107
- }
108
- return false;
109
- }
110
- /**
111
- * Checks if there's a return/throw statement between two positions in a block
112
- */
113
- function hasExitBetween(block, startIdx, endIdx) {
114
- for (let k = startIdx + 1; k < endIdx; k++) {
115
- const stmt = block.body[k];
116
- if (stmt.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)
117
- return true;
118
- if (stmt.type === eslint_devkit_1.AST_NODE_TYPES.ThrowStatement)
119
- return true;
120
- }
121
- return false;
122
- }
123
- /**
124
- * Checks if a switch case has a break/return/throw
125
- */
126
- function caseHasExit(switchCase) {
127
- for (const stmt of switchCase.consequent) {
128
- if (stmt.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)
129
- return true;
130
- if (stmt.type === eslint_devkit_1.AST_NODE_TYPES.ThrowStatement)
131
- return true;
132
- if (stmt.type === eslint_devkit_1.AST_NODE_TYPES.BreakStatement)
133
- return true;
134
- }
135
- return false;
136
- }
137
- /**
138
- * Gets the switch case containing a node
139
- */
140
- function getSwitchCase(node) {
141
- return findAncestor(node, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.SwitchCase);
142
- }
143
- /**
144
- * Gets the if statement directly containing a node (not ancestors)
145
- */
146
- function getDirectIfStatement(node) {
147
- return findAncestor(node, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement);
148
- }
149
- /**
150
- * Checks if the if statement's branch containing the release has a return/throw after it
151
- */
152
- function ifBranchHasExitAfterRelease(releaseNode, ifStmt) {
153
- // Find which branch contains the release
154
- const releaseRange = releaseNode.range;
155
- const consequentRange = ifStmt.consequent.range;
156
- const inConsequent = releaseRange[0] >= consequentRange[0] && releaseRange[1] <= consequentRange[1];
157
- let branchBlock = null;
158
- if (inConsequent && ifStmt.consequent.type === eslint_devkit_1.AST_NODE_TYPES.BlockStatement) {
159
- branchBlock = ifStmt.consequent;
160
- }
161
- else if (!inConsequent && ifStmt.alternate?.type === eslint_devkit_1.AST_NODE_TYPES.BlockStatement) {
162
- branchBlock = ifStmt.alternate;
163
- }
164
- if (!branchBlock)
165
- return false;
166
- // Find the release statement index
167
- const releaseParentStmt = releaseNode.parent?.type === eslint_devkit_1.AST_NODE_TYPES.ExpressionStatement
168
- ? releaseNode.parent
169
- : null;
170
- if (!releaseParentStmt)
171
- return false;
172
- const releaseIdx = branchBlock.body.indexOf(releaseParentStmt);
173
- if (releaseIdx === -1)
174
- return false;
175
- // Check if there's a return/throw after the release
176
- for (let i = releaseIdx + 1; i < branchBlock.body.length; i++) {
177
- const stmt = branchBlock.body[i];
178
- if (stmt.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement || stmt.type === eslint_devkit_1.AST_NODE_TYPES.ThrowStatement) {
179
- return true;
180
- }
181
- }
182
- return false;
183
- }
184
- exports.preventDoubleRelease = {
185
- meta: {
186
- type: 'problem',
187
- docs: {
188
- description: 'Prevent releasing a pg client multiple times.',
189
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/prevent-double-release.md',
190
- cwe: 'CWE-415',
191
- cweJustification: 'CWE-415 (Double Free) — semantic equivalent for connection lifecycle: releasing a pooled client twice corrupts the pool\'s internal accounting and can hand the same connection to two callers.',
192
- confidence: 'medium',
193
- },
194
- messages: {
195
- doubleRelease: (0, eslint_devkit_1.formatLLMMessage)({
196
- icon: eslint_devkit_1.MessageIcons.QUALITY,
197
- issueName: 'Double Release',
198
- description: 'Client release() called multiple times on the same object.',
199
- severity: 'HIGH',
200
- effort: 'low',
201
- fix: 'Ensure client.release() is called exactly once per acquisition, preferably in a finally block.',
202
- documentationLink: 'https://node-postgres.com/api/client#clientrelease',
203
- }),
204
- doubleReleaseCallback: (0, eslint_devkit_1.formatLLMMessage)({
205
- icon: eslint_devkit_1.MessageIcons.QUALITY,
206
- issueName: 'Double Release (Callback)',
207
- description: 'Connection release callback (done) called multiple times.',
208
- severity: 'HIGH',
209
- effort: 'low',
210
- fix: 'Ensure done() or release callback is called exactly once per pool.connect() callback.',
211
- documentationLink: 'https://node-postgres.com/api/pool#poolconnect',
212
- }),
213
- },
214
- schema: [],
215
- },
216
- defaultOptions: [],
217
- create(context) {
218
- return {
219
- VariableDeclarator(node) {
220
- const declaredVariables = context.sourceCode.getDeclaredVariables(node);
221
- for (const variable of declaredVariables) {
222
- const def = variable.defs[0];
223
- const isDestructuredRelease = def?.type === 'Variable' &&
224
- def.node.id.type === eslint_devkit_1.AST_NODE_TYPES.ObjectPattern &&
225
- def.name.name === 'release';
226
- const releaseCalls = [];
227
- variable.references.forEach((ref) => {
228
- const id = ref.identifier;
229
- if (isDestructuredRelease) {
230
- if (id.parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
231
- id.parent.callee === id) {
232
- const callNode = id.parent;
233
- const guarded = isGuardedByCondition(callNode);
234
- releaseCalls.push({ node: callNode, guarded });
235
- }
236
- }
237
- else {
238
- if (id.parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
239
- id.parent.object === id &&
240
- id.parent.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
241
- id.parent.property.name === 'release' &&
242
- id.parent.parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
243
- const callNode = id.parent.parent;
244
- const guarded = isGuardedByCondition(callNode);
245
- releaseCalls.push({ node: callNode, guarded });
246
- }
247
- }
248
- });
249
- if (releaseCalls.length > 1) {
250
- releaseCalls.sort((a, b) => a.node.range[0] - b.node.range[0]);
251
- const reported = new Set();
252
- for (let i = 0; i < releaseCalls.length; i++) {
253
- for (let j = i + 1; j < releaseCalls.length; j++) {
254
- const callA = releaseCalls[i];
255
- const callB = releaseCalls[j];
256
- // Skip if already reported
257
- if (reported.has(callB.node))
258
- continue;
259
- // Skip if both are guarded
260
- if (callA.guarded && callB.guarded)
261
- continue;
262
- // Skip if mutually exclusive branches
263
- if (areMutuallyExclusiveBranches(callA.node, callB.node))
264
- continue;
265
- // Same function scope check
266
- const funcA = getContainingFunction(callA.node);
267
- const funcB = getContainingFunction(callB.node);
268
- if (funcA !== funcB)
269
- continue;
270
- // Case 1: Try + Catch (not finally) - both paths release
271
- const tryA = isInTryBlock(callA.node);
272
- const catchB = isInCatchBlock(callB.node);
273
- if (tryA && catchB && catchB.parent === tryA) {
274
- context.report({ node: callB.node, messageId: 'doubleRelease' });
275
- reported.add(callB.node);
276
- continue;
277
- }
278
- // Case 2: Catch + Try (reversed order in source)
279
- const catchA = isInCatchBlock(callA.node);
280
- const tryB = isInTryBlock(callB.node);
281
- if (catchA && tryB && catchA.parent === tryB) {
282
- context.report({ node: callB.node, messageId: 'doubleRelease' });
283
- reported.add(callB.node);
284
- continue;
285
- }
286
- // Case 3: Switch fallthrough
287
- const switchCaseA = getSwitchCase(callA.node);
288
- const switchCaseB = getSwitchCase(callB.node);
289
- if (switchCaseA && switchCaseB && switchCaseA !== switchCaseB) {
290
- // Check if same switch statement
291
- const switchA = findAncestor(switchCaseA, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.SwitchStatement);
292
- const switchB = findAncestor(switchCaseB, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.SwitchStatement);
293
- if (switchA === switchB && switchA) {
294
- // Check if caseA doesn't have break/return/throw (fallthrough)
295
- if (!caseHasExit(switchCaseA)) {
296
- context.report({ node: callB.node, messageId: 'doubleRelease' });
297
- reported.add(callB.node);
298
- continue;
299
- }
300
- }
301
- }
302
- // Case 4: If without else + sequential release
303
- const ifA = getDirectIfStatement(callA.node);
304
- if (ifA && !ifA.alternate) {
305
- // B is after the if statement
306
- if (callB.node.range[0] > ifA.range[1]) {
307
- // Check if B is in same block as the if
308
- const parentBlock = findAncestor(ifA, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.BlockStatement);
309
- if (parentBlock) {
310
- const bParentStmt = callB.node.parent?.type === eslint_devkit_1.AST_NODE_TYPES.ExpressionStatement
311
- ? callB.node.parent : null;
312
- if (bParentStmt && parentBlock.body.includes(bParentStmt)) {
313
- // Check if the if branch has exit after release
314
- if (!ifBranchHasExitAfterRelease(callA.node, ifA)) {
315
- context.report({ node: callB.node, messageId: 'doubleRelease' });
316
- reported.add(callB.node);
317
- continue;
318
- }
319
- }
320
- }
321
- }
322
- }
323
- // Case 5: Two sequential if statements (neither has else)
324
- const ifB = getDirectIfStatement(callB.node);
325
- if (ifA && ifB && ifA !== ifB && !ifA.alternate && !ifB.alternate) {
326
- // Both are different if statements at same level
327
- const parentBlockA = ifA.parent;
328
- const parentBlockB = ifB.parent;
329
- if (parentBlockA === parentBlockB && parentBlockA?.type === eslint_devkit_1.AST_NODE_TYPES.BlockStatement) {
330
- // Check if ifA doesn't exit after release
331
- if (!ifBranchHasExitAfterRelease(callA.node, ifA)) {
332
- context.report({ node: callB.node, messageId: 'doubleRelease' });
333
- reported.add(callB.node);
334
- continue;
335
- }
336
- }
337
- }
338
- const parentA = callA.node.parent?.parent;
339
- const parentB = callB.node.parent?.parent;
340
- // Case 6: Same Block - direct sequential releases
341
- if (parentA &&
342
- parentB &&
343
- parentA === parentB &&
344
- parentA.type === eslint_devkit_1.AST_NODE_TYPES.BlockStatement) {
345
- const block = parentA;
346
- const indexA = block.body.indexOf(callA.node.parent);
347
- const indexB = block.body.indexOf(callB.node.parent);
348
- if (indexB > indexA && !hasExitBetween(block, indexA, indexB)) {
349
- context.report({ node: callB.node, messageId: 'doubleRelease' });
350
- reported.add(callB.node);
351
- continue;
352
- }
353
- }
354
- // Case 7: Try/Catch + Finally pattern
355
- const catchAForFinally = isInCatchBlock(callA.node);
356
- const finallyB = isInFinallyBlock(callB.node);
357
- if (catchAForFinally && finallyB) {
358
- const tryOfCatch = catchAForFinally.parent;
359
- if (tryOfCatch === finallyB) {
360
- context.report({ node: callB.node, messageId: 'doubleRelease' });
361
- reported.add(callB.node);
362
- continue;
363
- }
364
- }
365
- // Case 8: Try block + Finally pattern
366
- const tryAForFinally = isInTryBlock(callA.node);
367
- const finallyB2 = isInFinallyBlock(callB.node);
368
- if (tryAForFinally && finallyB2 && tryAForFinally === finallyB2) {
369
- context.report({ node: callB.node, messageId: 'doubleRelease' });
370
- reported.add(callB.node);
371
- continue;
372
- }
373
- // Case 9: Finally + After try pattern
374
- const finallyA = isInFinallyBlock(callA.node);
375
- if (finallyA) {
376
- const tryEndPos = finallyA.range[1];
377
- if (callB.node.range[0] > tryEndPos) {
378
- context.report({ node: callB.node, messageId: 'doubleRelease' });
379
- reported.add(callB.node);
380
- continue;
381
- }
382
- }
383
- // Case 10: Try block release + after try (with or without finally)
384
- const tryAWithOrWithout = isInTryBlock(callA.node);
385
- if (tryAWithOrWithout) {
386
- // B is after the entire try statement (including any finally)
387
- const tryEndPos = tryAWithOrWithout.range[1];
388
- if (callB.node.range[0] > tryEndPos && !isInFinallyBlock(callB.node)) {
389
- context.report({ node: callB.node, messageId: 'doubleRelease' });
390
- reported.add(callB.node);
391
- continue;
392
- }
393
- }
394
- // Case 11: Early return branch + Finally (without exit)
395
- const ifStmtA = findAncestor(callA.node, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement);
396
- if (ifStmtA && finallyB) {
397
- if (!ifBranchHasExitAfterRelease(callA.node, ifStmtA)) {
398
- context.report({ node: callB.node, messageId: 'doubleRelease' });
399
- reported.add(callB.node);
400
- continue;
401
- }
402
- }
403
- // Case 12: Catch block + after try (no finally, or B is outside finally)
404
- const catchAForAfter = isInCatchBlock(callA.node);
405
- if (catchAForAfter) {
406
- const tryOfCatchA = catchAForAfter.parent;
407
- const tryEndPos = tryOfCatchA.range[1];
408
- if (callB.node.range[0] > tryEndPos) {
409
- context.report({ node: callB.node, messageId: 'doubleRelease' });
410
- reported.add(callB.node);
411
- continue;
412
- }
413
- }
414
- // Case 13: Expression-based release (ternary, short-circuit) + sequential
415
- // Check if A is in a ternary/conditional expression or logical expression
416
- const isInExpression = (exprNode) => {
417
- let current = exprNode.parent;
418
- while (current) {
419
- if (current.type === eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression)
420
- return true;
421
- if (current.type === eslint_devkit_1.AST_NODE_TYPES.LogicalExpression)
422
- return true;
423
- if (current.type === eslint_devkit_1.AST_NODE_TYPES.ExpressionStatement)
424
- break;
425
- if (current.type === eslint_devkit_1.AST_NODE_TYPES.BlockStatement)
426
- break;
427
- current = current.parent;
428
- }
429
- return false;
430
- };
431
- if (isInExpression(callA.node)) {
432
- // A is in a conditional/logical expression, B comes after
433
- // Find the containing expression statement for A
434
- let exprStmtA = callA.node;
435
- while (exprStmtA && exprStmtA.type !== eslint_devkit_1.AST_NODE_TYPES.ExpressionStatement) {
436
- exprStmtA = exprStmtA.parent ?? null;
437
- }
438
- if (exprStmtA && callB.node.range[0] > exprStmtA.range[1]) {
439
- // Check they're in the same block
440
- const blockA = findAncestor(exprStmtA, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.BlockStatement);
441
- const blockB = findAncestor(callB.node, (n) => n.type === eslint_devkit_1.AST_NODE_TYPES.BlockStatement);
442
- if (blockA && blockA === blockB) {
443
- context.report({ node: callB.node, messageId: 'doubleRelease' });
444
- reported.add(callB.node);
445
- continue;
446
- }
447
- }
448
- }
449
- }
450
- }
451
- }
452
- }
453
- },
454
- };
455
- },
456
- };
@@ -1,7 +0,0 @@
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 });