-
Notifications
You must be signed in to change notification settings - Fork 394
Add wildcard support when include/exclude rules #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
List<KeyValuePair<CommandInfo, IScriptExtent>> cmdInfoTable = new List<KeyValuePair<CommandInfo, IScriptExtent>>(); | ||
List<KeyValuePair<CommandInfo, IScriptExtent>> cmdInfoTable = new List<KeyValuePair<CommandInfo, IScriptExtent>>(); | ||
|
||
//Check wild card input for the Include/ExcludRules and create regex match patterns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Typo: ExcludeRule
Can you add tests for the changes? |
Thanks Raghu. Corrected typo and added tests of Invoke-ScriptAnalyzer |
{ | ||
foreach (string rule in includeRule) | ||
{ | ||
Regex includeRegex = new Regex(rule.Replace("*", ".*?"), RegexOptions.IgnoreCase); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want non-greedy matching here? Also I think this may fail if the user input something with special characters (for example, if he/she wants to search something like MyModule.Blah then the dot will be considered as any character).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using this:
Regex reg = new Regex(String.Format("^{0}$", Regex.Escape(rule).Replace(@"*", ".*")))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Quoc. I've changed the expression to be non-greedy.
rest looks good.. |
Also remove the redundant checking.
Looks good to me. |
Add wildcard support when include/exclude rules
Thanks! |
With this change, users can do something like Invoke-ScriptAnalyzer -IncludeRule PSAvoid_, PSUse_
This feature does not apply to customized rules.