-
Notifications
You must be signed in to change notification settings - Fork 394
Fix PSSA for Turkish culture and tests when culture is not en-US #1099
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
Changes from 16 commits
010a862
57ab21c
dcfe1cf
5fea008
a8df05d
c33c38b
479ed3a
227b64f
cee22f9
079b98d
bd97fcb
6d28bcc
7ffbf65
9ae39ba
e6f4ca3
eae7ff0
50e6087
7540baf
db4af7b
e1752bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,61 +202,56 @@ public RuleSuppression(AttributeAst attrAst, int start, int end) | |
break; | ||
} | ||
|
||
switch (name.ArgumentName.ToLower()) | ||
var argumentName = name.ArgumentName; | ||
if (argumentName.Equals("rulename", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
case "rulename": | ||
if (!String.IsNullOrWhiteSpace(RuleName)) | ||
{ | ||
Error = String.Format(Strings.NamedAndPositionalArgumentsConflictError, name); | ||
} | ||
|
||
RuleName = (name.Argument as StringConstantExpressionAst).Value; | ||
goto default; | ||
|
||
case "rulesuppressionid": | ||
if (!String.IsNullOrWhiteSpace(RuleSuppressionID)) | ||
{ | ||
Error = String.Format(Strings.NamedAndPositionalArgumentsConflictError, name); | ||
} | ||
|
||
RuleSuppressionID = (name.Argument as StringConstantExpressionAst).Value; | ||
goto default; | ||
|
||
case "scope": | ||
if (!String.IsNullOrWhiteSpace(Scope)) | ||
{ | ||
Error = String.Format(Strings.NamedAndPositionalArgumentsConflictError, name); | ||
} | ||
|
||
Scope = (name.Argument as StringConstantExpressionAst).Value; | ||
|
||
if (!scopeSet.Contains(Scope)) | ||
{ | ||
Error = Strings.WrongScopeArgumentSuppressionAttributeError; | ||
} | ||
if (!String.IsNullOrWhiteSpace(RuleName)) | ||
{ | ||
Error = String.Format(Strings.NamedAndPositionalArgumentsConflictError, name); | ||
} | ||
|
||
goto default; | ||
RuleName = (name.Argument as StringConstantExpressionAst).Value; | ||
} | ||
else if (argumentName.Equals("rulesuppressionid", StringComparison.OrdinalIgnoreCase)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, one would have to move it into a function and other variables would need to be passed to it and there is no else, meaning the caller of it would need an |
||
{ | ||
if (!String.IsNullOrWhiteSpace(RuleName)) | ||
{ | ||
Error = String.Format(Strings.NamedAndPositionalArgumentsConflictError, name); | ||
} | ||
|
||
case "target": | ||
if (!String.IsNullOrWhiteSpace(Target)) | ||
{ | ||
Error = String.Format(Strings.NamedAndPositionalArgumentsConflictError, name); | ||
} | ||
RuleName = (name.Argument as StringConstantExpressionAst).Value; | ||
} | ||
else if (argumentName.Equals("scope", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (!String.IsNullOrWhiteSpace(Scope)) | ||
{ | ||
Error = String.Format(Strings.NamedAndPositionalArgumentsConflictError, name); | ||
} | ||
|
||
Target = (name.Argument as StringConstantExpressionAst).Value; | ||
goto default; | ||
Scope = (name.Argument as StringConstantExpressionAst).Value; | ||
|
||
case "justification": | ||
if (!String.IsNullOrWhiteSpace(Justification)) | ||
{ | ||
Error = String.Format(Strings.NamedAndPositionalArgumentsConflictError, name); | ||
} | ||
if (!scopeSet.Contains(Scope)) | ||
{ | ||
Error = Strings.WrongScopeArgumentSuppressionAttributeError; | ||
} | ||
} | ||
else if (argumentName.Equals("target", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (!String.IsNullOrWhiteSpace(Target)) | ||
{ | ||
Error = String.Format(Strings.NamedAndPositionalArgumentsConflictError, name); | ||
} | ||
|
||
Justification = (name.Argument as StringConstantExpressionAst).Value; | ||
goto default; | ||
Target = (name.Argument as StringConstantExpressionAst).Value; | ||
} | ||
else if (argumentName.Equals("justification", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (!String.IsNullOrWhiteSpace(Justification)) | ||
{ | ||
Error = String.Format(Strings.NamedAndPositionalArgumentsConflictError, name); | ||
} | ||
|
||
default: | ||
break; | ||
Justification = (name.Argument as StringConstantExpressionAst).Value; | ||
} | ||
} | ||
} | ||
|
@@ -354,23 +349,17 @@ public static List<RuleSuppression> GetSuppressions(IEnumerable<AttributeAst> at | |
Regex reg = new Regex(String.Format("^{0}$", ruleSupp.Target.Replace(@"*", ".*")), RegexOptions.IgnoreCase); | ||
IEnumerable<Ast> targetAsts = null; | ||
|
||
switch (ruleSupp.Scope.ToLower()) | ||
var scope = ruleSupp.Scope; | ||
bergmeister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (scope.Equals("function", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
case "function": | ||
targetAsts = scopeAst.FindAll(item => item is FunctionDefinitionAst && reg.IsMatch((item as FunctionDefinitionAst).Name), true); | ||
goto default; | ||
|
||
#if !(PSV3||PSV4) | ||
|
||
case "class": | ||
targetAsts = scopeAst.FindAll(item => item is TypeDefinitionAst && reg.IsMatch((item as TypeDefinitionAst).Name), true); | ||
goto default; | ||
|
||
#endif | ||
|
||
default: | ||
break; | ||
targetAsts = scopeAst.FindAll(ast => ast is FunctionDefinitionAst && reg.IsMatch((ast as FunctionDefinitionAst).Name), true); | ||
} | ||
#if !(PSV3 || PSV4) | ||
else if (scope.Equals("class", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
targetAsts = scopeAst.FindAll(ast => ast is TypeDefinitionAst && reg.IsMatch((ast as TypeDefinitionAst).Name), true); | ||
} | ||
#endif | ||
|
||
if (targetAsts != null) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,20 +283,19 @@ private bool AddProfileItem( | |
Debug.Assert(includeRuleList != null); | ||
Debug.Assert(excludeRuleList != null); | ||
|
||
switch (key.ToLower()) | ||
if (key.Equals("severity", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
case "severity": | ||
severityList.AddRange(values); | ||
break; | ||
case "includerules": | ||
includeRuleList.AddRange(values); | ||
break; | ||
case "excluderules": | ||
excludeRuleList.AddRange(values); | ||
break; | ||
default: | ||
return false; | ||
severityList.AddRange(values); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It strikes me that it would be simpler to just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I agree, I''ve addressed that in this commit |
||
} | ||
else if (key.Equals("includerules", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
includeRuleList.AddRange(values); | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
@@ -510,75 +509,70 @@ private bool ParseProfileHashtable(Hashtable profile, PathIntrinsics path, IOutp | |
settings.Keys.CopyTo(settingsKeys, 0); | ||
foreach (var settingKey in settingsKeys) | ||
{ | ||
var key = settingKey.ToLower(); | ||
object value = settings[key]; | ||
switch (key) | ||
{ | ||
case "severity": | ||
case "includerules": | ||
case "excluderules": | ||
// value must be either string or collections of string or array | ||
if (value == null | ||
|| !(value is string | ||
|| value is IEnumerable<string> | ||
|| value.GetType().IsArray)) | ||
{ | ||
writer.WriteError( | ||
new ErrorRecord( | ||
new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongValueHashTable, value, key)), | ||
Strings.WrongConfigurationKey, | ||
ErrorCategory.InvalidData, | ||
profile)); | ||
hasError = true; | ||
break; | ||
} | ||
List<string> values = new List<string>(); | ||
if (value is string) | ||
{ | ||
values.Add(value as string); | ||
} | ||
else if (value is IEnumerable<string>) | ||
{ | ||
values.Union(value as IEnumerable<string>); | ||
} | ||
else if (value.GetType().IsArray) | ||
{ | ||
// for array case, sometimes we won't be able to cast it directly to IEnumerable<string> | ||
foreach (var val in value as IEnumerable) | ||
{ | ||
if (val is string) | ||
{ | ||
values.Add(val as string); | ||
} | ||
else | ||
{ | ||
writer.WriteError( | ||
new ErrorRecord( | ||
new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongValueHashTable, val, key)), | ||
Strings.WrongConfigurationKey, | ||
ErrorCategory.InvalidData, | ||
profile)); | ||
hasError = true; | ||
break; | ||
} | ||
} | ||
} | ||
AddProfileItem(key, values, severityList, includeRuleList, excludeRuleList); | ||
settings[key] = values; | ||
break; | ||
object value = settings[settingKey]; | ||
|
||
case "rules": | ||
break; | ||
|
||
default: | ||
if (settingKey.Equals("severity", StringComparison.OrdinalIgnoreCase) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to suggest changes here, but I keep thinking about the rest of the file so I might open a PR instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to defer this. The code works for now, but I'd really like to work on boiling down some common functionality eventually -- something we can work out in the future. |
||
settingKey.Equals("includerules", StringComparison.OrdinalIgnoreCase) || | ||
settingKey.Equals("excluderules", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
// value must be either string or collections of string or array | ||
if (value == null | ||
|| !(value is string | ||
|| value is IEnumerable<string> | ||
|| value.GetType().IsArray)) | ||
{ | ||
writer.WriteError( | ||
new ErrorRecord( | ||
new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongKeyHashTable, key)), | ||
new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongValueHashTable, value, settingKey)), | ||
Strings.WrongConfigurationKey, | ||
ErrorCategory.InvalidData, | ||
profile)); | ||
hasError = true; | ||
break; | ||
} | ||
var values = new List<string>(); | ||
if (value is string) | ||
{ | ||
values.Add(value as string); | ||
} | ||
else if (value is IEnumerable<string>) | ||
{ | ||
values.Union(value as IEnumerable<string>); | ||
} | ||
else if (value.GetType().IsArray) | ||
{ | ||
// for array case, sometimes we won't be able to cast it directly to IEnumerable<string> | ||
foreach (var val in value as IEnumerable) | ||
{ | ||
if (val is string) | ||
{ | ||
values.Add(val as string); | ||
} | ||
else | ||
{ | ||
writer.WriteError( | ||
new ErrorRecord( | ||
new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongValueHashTable, val, settingKey)), | ||
Strings.WrongConfigurationKey, | ||
ErrorCategory.InvalidData, | ||
profile)); | ||
hasError = true; | ||
break; | ||
} | ||
} | ||
} | ||
AddProfileItem(settingKey, values, severityList, includeRuleList, excludeRuleList); | ||
settings[settingKey] = values; | ||
} | ||
else if (settingKey.Equals("excluderules", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
writer.WriteError( | ||
new ErrorRecord( | ||
new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongKeyHashTable, settingKey)), | ||
Strings.WrongConfigurationKey, | ||
ErrorCategory.InvalidData, | ||
profile)); | ||
hasError = true; | ||
} | ||
} | ||
return hasError; | ||
|
Uh oh!
There was an error while loading. Please reload this page.