Skip to content

Fix bugs in importing external rule #90

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 6 commits into from
May 5, 2015
Merged

Fix bugs in importing external rule #90

merged 6 commits into from
May 5, 2015

Conversation

yutingc
Copy link
Contributor

@yutingc yutingc commented May 4, 2015

When importing customized rules, we take Ast type instead of name to
apply rules.
Modify string comparsion
Add check for null diagnosticRecord returned.

When importing customized rules, we take Ast type instead of name to
apply rules.
Modify string comparsion
Add check for null diagnosticRecord returned.
.First<ParameterMetadata>(item => item.Name.ToLower(CultureInfo.CurrentCulture).EndsWith("ast", StringComparison.CurrentCulture) ||
item.Name.ToLower(CultureInfo.CurrentCulture).EndsWith("token", StringComparison.CurrentCulture));
.First<ParameterMetadata>(item => item.Name.EndsWith("ast", StringComparison.OrdinalIgnoreCase) ||
item.Name.EndsWith("token", StringComparison.CurrentCulture));

Choose a reason for hiding this comment

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

Should the check be case insensitive here too?

@@ -251,7 +251,7 @@ public List<ExternalRule> GetExternalRule(string[] moduleNames)
string desc =posh.AddScript(script).Invoke()[0].ImmediateBaseObject.ToString()
.Replace("\r\n", " ").Trim();

rules.Add(new ExternalRule(funcInfo.Name, funcInfo.Name, desc, param.Name,
rules.Add(new ExternalRule(funcInfo.Name, funcInfo.Name, desc, param.ParameterType.Name,

Choose a reason for hiding this comment

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

Have you tested for the case where the type is System.Management.Automation.Language.SomeAst vs just SomeAst? Ideally there should not be any discrepancy I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think parser recognized just someAst...

=Get-ScriptAnalyzerRule : Unable to find type [ScriptBlockAst].

Choose a reason for hiding this comment

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

Okay I guess that is an error on the user's side then?

@raghushantha
Copy link
Member

Can you add unit tests?

Also added try/catch to capture errors in customized rule modules and
throw non-terminating errors
@raghushantha
Copy link
Member

I don't see the Pester test.

*.tests.ps1

@yutingc
Copy link
Contributor Author

yutingc commented May 4, 2015

Yeah I'm adding it right now

@raghushantha
Copy link
Member

Also. please ignore Appveyor errors. I am trying to integrate with ScriptAnalyzer.

Will use my local repro for testing the integration. You must not see these messages anymore

@@ -289,12 +289,12 @@ public IEnumerable<DiagnosticRecord> GetExternalRecord(Ast ast, Token[] token, E

// Groups rules by AstType and Tokens.
Dictionary<string, List<ExternalRule>> astRuleGroups = rules
.Where<ExternalRule>(item => item.GetParameter().EndsWith("ast", true, CultureInfo.CurrentCulture))
.Where<ExternalRule>(item => item.GetParameter().EndsWith("ast", StringComparison.OrdinalIgnoreCase))

Choose a reason for hiding this comment

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

Also the key of this dictionary is still the name of the parameter instead of the type of the parameter.

yutingc added 2 commits May 4, 2015 17:55
Also added parameterType to external rule to separate parameter type and
parameter name
@yutingc
Copy link
Contributor Author

yutingc commented May 5, 2015

Hi Quoc and Raghu, I've made a few changes including adding a new paramType in ExternalRule and new unit tests. Please take a look. Thanks!

@raghushantha
Copy link
Member

looks good. pls merge

yutingc added a commit that referenced this pull request May 5, 2015
Fix bugs in importing external rule
@yutingc yutingc merged commit 5eff3c4 into BugFixes May 5, 2015
@yutingc
Copy link
Contributor Author

yutingc commented May 5, 2015

Thanks!

@yutingc yutingc deleted the customizedRule branch May 6, 2015 17:29
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.

4 participants