Structural Search and Replace: Pattern for warning when 2nd parameter in ArgumentException isn't string?

Suppose I have code below:

public void Foo(string secretInfo)
{
  if ( string.IsNullOrEmpty(secreteInfo) )
    throw new ArgumentException(@"Info cannot be empty", secretInfo);

  //Even worse scenario
  if (!secretInfo.Contains("secretTokenVerifier"))
    throw new ArgumentException(@"Info is an unknown secret info", secretInfo);
}

This compiles fine since secret info is string. However as you might see this is not the indented behavior; I wanted to include parameter name and not the actual parameter value in the exception.
Is it possible to create a search pattern that warns if 2nd parameter isn't quoted?

I tried the following but I'm out of luck:
Pattern:
$argException$($p1$, $p2$)
argException: "type" System.ArgumentException or derived.
p1: "expression" system.object or derived type
p2: "identifier", regex: [^"]

Thanks.

2 comments
Comment actions Permalink

Try searching for

new $argException$($p1$, $p2$)

0
Comment actions Permalink

Thanks. Worked perfectly.

(except for the replacing part for which I created issue http://youtrack.jetbrains.net/issue/RSRP-183035 )

0

Please sign in to leave a comment.