Skip to content

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

Merged
merged 3 commits into from
Apr 21, 2015
Merged

Conversation

yutingc
Copy link
Contributor

@yutingc yutingc commented Apr 20, 2015

With this change, users can do something like Invoke-ScriptAnalyzer -IncludeRule PSAvoid_, PSUse_

This feature does not apply to customized rules.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Typo: ExcludeRule

@raghushantha
Copy link
Member

Can you add tests for the changes?

@yutingc
Copy link
Contributor Author

yutingc commented Apr 21, 2015

Thanks Raghu. Corrected typo and added tests of Invoke-ScriptAnalyzer

{
foreach (string rule in includeRule)
{
Regex includeRegex = new Regex(rule.Replace("*", ".*?"), RegexOptions.IgnoreCase);

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).

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(@"*", ".*")))

Copy link
Contributor Author

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.

@raghushantha
Copy link
Member

rest looks good..

Also remove the redundant checking.
@quoctruong
Copy link

Looks good to me.

yutingc added a commit that referenced this pull request Apr 21, 2015
Add wildcard support when include/exclude rules
@yutingc yutingc merged commit 2545bfa into BugFixes Apr 21, 2015
@yutingc
Copy link
Contributor Author

yutingc commented Apr 21, 2015

Thanks!

@yutingc yutingc deleted the wildcard branch April 22, 2015 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants