Skip to content

Commit 4232e83

Browse files
bumahkib7claude
andcommitted
fix(typestate): Prevent false positives on Array.prototype.find()
Remove generic `.find(` from JavaScript/TypeScript database query patterns since it conflicts with `Array.prototype.find()`. Add more specific ORM patterns instead: - `.findById(`, `.findUnique(`, `.findFirst(` (Prisma) - `.findByPk(`, `.findOrCreate(` (Sequelize) - `.insertMany(`, `.updateMany(`, `.deleteMany(` (MongoDB) - `.bulkCreate(` (Sequelize) - `collection.find(` (explicit MongoDB collection access) This fixes false positives where `addresses.find(a => a.isDefault)` was incorrectly flagged as "Query executed without establishing connection". Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 0924b06 commit 4232e83

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/analyzer/src/security/typestate_rules.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2848,22 +2848,35 @@ impl DatabaseStateMachine {
28482848
".query(",
28492849
".execute(",
28502850
".run(",
2851-
".find(",
2851+
// Note: .find( is NOT included because it conflicts with Array.prototype.find()
2852+
// Use more specific ORM patterns instead
28522853
".findOne(",
28532854
".findMany(",
2855+
".findById(",
2856+
".findUnique(",
2857+
".findFirst(",
28542858
".insertOne(",
2859+
".insertMany(",
28552860
".updateOne(",
2861+
".updateMany(",
28562862
".deleteOne(",
2863+
".deleteMany(",
28572864
".aggregate(",
28582865
".exec(",
28592866
// Sequelize
28602867
".findAll(",
2868+
".findByPk(",
2869+
".findOrCreate(",
28612870
".create(",
2871+
".bulkCreate(",
28622872
".update(",
28632873
".destroy(",
28642874
// Prisma
28652875
".$queryRaw(",
28662876
".$executeRaw(",
2877+
// MongoDB specific (collection methods)
2878+
"collection.find(",
2879+
".collection(",
28672880
],
28682881
begin_patterns: vec![
28692882
".beginTransaction(",

0 commit comments

Comments
 (0)