Skip to content

Commit bdfe475

Browse files
committed
fix(infrastructure): add module.Method() patterns for Python, Go, Rust
- Python: Add pattern for module.RedisClient() format (e.g., redis.RedisClient()) - Go: Add pattern for module.NewClient() format (e.g., redis.NewClient()) - Rust: Change \w+ to \w* to match bare class names like Client::new() Fixes test failures where patterns only matched direct instantiation, not module-qualified instantiation which is more common in real code.
1 parent 20dbbeb commit bdfe475

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

lib/patterns/slop-analyzers.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -801,27 +801,31 @@ const INSTANTIATION_PATTERNS = {
801801
],
802802
python: [
803803
// Class instantiation: client = SomeClient()
804-
/^(\w+)\s*=\s*(\w+(?:Client|Connection|Pool|Service|Provider|Manager|Factory|Repository|Gateway|Adapter|Handler|Broker|Queue|Cache|Store|Transport|Channel|Socket|Server|Database))\(/gm,
804+
/(\w+)\s*=\s*(\w+(?:Client|Connection|Pool|Service|Provider|Manager|Factory|Repository|Gateway|Adapter|Handler|Broker|Queue|Cache|Store|Transport|Channel|Socket|Server|Database))\(/gm,
805+
// Module.Class pattern: client = module.RedisClient()
806+
/(\w+)\s*=\s*\w+\.(\w+(?:Client|Connection|Pool|Service|Provider|Manager|Factory|Repository|Gateway|Adapter|Handler|Broker|Queue|Cache|Store|Transport|Channel|Socket|Server|Database))\(/gm,
805807
// Factory pattern: client = create_client()
806-
/^(\w+)\s*=\s*(?:create|connect|init|initialize|setup)_(\w+)\(/gm,
808+
/(\w+)\s*=\s*(?:create|connect|init|initialize|setup)_(\w+)\(/gm,
807809
// Async patterns: client = await create_client()
808-
/^(\w+)\s*=\s*await\s+(?:create|connect|init|initialize|setup)_(\w+)\(/gm
810+
/(\w+)\s*=\s*await\s+(?:create|connect|init|initialize|setup)_(\w+)\(/gm
809811
],
810812
go: [
811813
// New* function pattern: client := NewClient()
812814
/(\w+)\s*:=\s*(?:New|Create|Connect|Init|Setup)(\w+)\(/g,
815+
// Module.New* pattern: client := redis.NewClient()
816+
/(\w+)\s*:=\s*\w+\.(?:New|Create|Connect|Init|Setup)(\w+)\(/g,
813817
// Variable declaration: var client = NewClient()
814818
/var\s+(\w+)\s+.*=\s*(?:New|Create|Connect|Init|Setup)(\w+)\(/g,
815819
// Struct literal with suffix: client := &RedisClient{}
816820
/(\w+)\s*:=\s*&(\w+(?:Client|Connection|Pool|Service|Provider|Manager|Factory|Repository|Gateway|Adapter|Handler|Broker|Queue|Cache|Store|Transport|Channel|Socket|Server|Database))\{/g
817821
],
818822
rust: [
819823
// ::new() constructor: let client = Client::new()
820-
/let\s+(?:mut\s+)?(\w+)\s*=\s*(\w+(?:Client|Connection|Pool|Service|Provider|Manager|Factory|Repository|Gateway|Adapter|Handler|Broker|Queue|Cache|Store|Transport|Channel|Socket|Server|Database))::(?:new|create|connect|init|build)\(/g,
824+
/let\s+(?:mut\s+)?(\w+)\s*=\s*(\w*(?:Client|Connection|Pool|Service|Provider|Manager|Factory|Repository|Gateway|Adapter|Handler|Broker|Queue|Cache|Store|Transport|Channel|Socket|Server|Database))::(?:new|create|connect|init|build)\(/g,
821825
// Builder pattern: let client = ClientBuilder::new().build()
822826
/let\s+(?:mut\s+)?(\w+)\s*=\s*(\w+Builder)::new\(\).*\.build\(\)/g,
823827
// From/into patterns: let client = Client::from()
824-
/let\s+(?:mut\s+)?(\w+)\s*=\s*(\w+(?:Client|Connection|Pool|Service|Provider|Manager|Factory|Repository|Gateway|Adapter|Handler|Broker|Queue|Cache|Store|Transport|Channel|Socket|Server|Database))::from/g
828+
/let\s+(?:mut\s+)?(\w+)\s*=\s*(\w*(?:Client|Connection|Pool|Service|Provider|Manager|Factory|Repository|Gateway|Adapter|Handler|Broker|Queue|Cache|Store|Transport|Channel|Socket|Server|Database))::from/g
825829
]
826830
};
827831

0 commit comments

Comments
 (0)