C
C#2w ago
hafthors

Regex Code Analyzer?

I'm looking for a Roslyn code analyzer that checks for proper use of Regex - I cannot use the Regex source generators yet, so I want something that checks that Regex with a const pattern uses .Compiled and that any .Compiled is not leaked (must be static readonly). Also, would like some sort of analyzer to check for dangerous dynamic Regex patterns without timeouts and any other Regex best practices.
6 Replies
Anton
Anton2w ago
It doesn't seem to exist. Write your own With analyzers and source generators, exactly what you want usually wouldn't exist
Unknown User
Unknown User7d ago
Message Not Public
Sign In & Join Server To View
hafthors
hafthorsOP5d ago
stuck on .NET Fx for now so cannot use source generators yet
Unknown User
Unknown User5d ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
Yeah I think it should be possible to reference an analyzer in netfx 4.7+ but I'm not sure
hafthors
hafthorsOP5d ago
netfx 4.7.2 - PackageReference - I can use and make code analyzers, I was just mentioning that I don't believe I can use [GeneratedRegex] in netfx - and ultimately, I'm looking for a code analyzer that checks usages of System.Text.RegularExpressions.Regex

Did you find this page helpful?