-
Notifications
You must be signed in to change notification settings - Fork 94
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
Updating Rule SARIF2009 and SARIF2014 #1954
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,23 +34,13 @@ public class ConsiderConventionalIdentifierValues : SarifValidationSkimmerBase | |
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF2009_ConsiderConventionalIdentifierValues_FullDescription_Text }; | ||
|
||
protected override IEnumerable<string> MessageResourceNames => new string[] { | ||
nameof(RuleResources.SARIF2009_ConsiderConventionalIdentifierValues_Note_UseConventionalRuleIds_Text), | ||
nameof(RuleResources.SARIF2009_ConsiderConventionalIdentifierValues_Note_UseConventionalUriBaseIdNames_Text) | ||
nameof(RuleResources.SARIF2009_ConsiderConventionalIdentifierValues_Note_UseConventionalRuleIds_Text) | ||
}; | ||
|
||
public override FailureLevel DefaultLevel => FailureLevel.Note; | ||
|
||
private static readonly string[] s_conventionalSymbols = new string[] { "REPOROOT", "SRCROOT", "TESTROOT", "BINROOT" }; | ||
private static readonly Regex s_conventionalIdRegex = new Regex(@"^[A-Z]{1,5}[0-9]{1,4}$", RegexOptions.Compiled | RegexOptions.CultureInvariant); | ||
|
||
protected override void Analyze(Run run, string runPointer) | ||
{ | ||
if (run.OriginalUriBaseIds != null) | ||
{ | ||
AnalyzeOriginalUriBaseIds(run.OriginalUriBaseIds, runPointer.AtProperty(SarifPropertyName.OriginalUriBaseIds)); | ||
} | ||
} | ||
|
||
protected override void Analyze(Tool tool, string toolPointer) | ||
{ | ||
if (tool.Driver != null) | ||
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.
Guaranteed non-null. #Closed |
||
|
@@ -90,25 +80,5 @@ private void AnalyzeReportingDescriptor(ReportingDescriptor reportingDescriptor, | |
reportingDescriptor.Id); | ||
} | ||
} | ||
|
||
private void AnalyzeOriginalUriBaseIds(IDictionary<string, ArtifactLocation> originalUriBaseIds, string originalUriBaseIdsPointer) | ||
{ | ||
foreach (KeyValuePair<string, ArtifactLocation> originalUriBaseId in originalUriBaseIds) | ||
{ | ||
if (!s_conventionalSymbols.Contains(originalUriBaseId.Key)) | ||
{ | ||
// {0}: The 'originalUriBaseIds' symbol '{1}' is not one of the conventional symbols. | ||
// We suggest 'REPOROOT' for the root of a repository, 'SRCROOT' for the root of the | ||
// directory containing all source code, 'TESTROOT' for the root of the directory | ||
// containing all test code (if your repository is organized in that way), and 'BINROOT' | ||
// for the root of the directory containing build output (if your project places all | ||
// build output in a common directory). | ||
LogResult( | ||
originalUriBaseIdsPointer.AtProperty(originalUriBaseId.Key), | ||
nameof(RuleResources.SARIF2009_ConsiderConventionalIdentifierValues_Note_UseConventionalUriBaseIdNames_Text), | ||
originalUriBaseId.Key); | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,29 +58,31 @@ private void AnalyzeReportingDescriptor(ReportingDescriptor rule, string reporti | |
string messageStringsPointer = reportingDescriptorPointer.AtProperty(SarifPropertyName.MessageStrings); | ||
foreach (KeyValuePair<string, MultiformatMessageString> message in rule.MessageStrings) | ||
{ | ||
AnalyzeMessageString(rule.Id, message.Value.Text, message.Key, messageStringsPointer.AtProperty(message.Key)); | ||
AnalyzeString(rule.Id, message.Value.Text, message.Key, messageStringsPointer.AtProperty(message.Key), SarifPropertyName.Text); | ||
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.
Revert name to |
||
AnalyzeString(rule.Id, message.Value.Markdown, message.Key, messageStringsPointer.AtProperty(message.Key), SarifPropertyName.Markdown); | ||
} | ||
} | ||
} | ||
|
||
private void AnalyzeMessageString(string ruleId, string messageString, string messageKey, string messagePointer) | ||
private void AnalyzeString(string ruleId, string messageString, string messageKey, string messagePointer, string propertyName) | ||
{ | ||
if (string.IsNullOrEmpty(messageString)) | ||
{ | ||
return; | ||
} | ||
|
||
string textPointer = messagePointer.AtProperty(SarifPropertyName.Text); | ||
string pointer = messagePointer.AtProperty(propertyName); | ||
|
||
if (!s_dynamicContentRegex.IsMatch(messageString)) | ||
{ | ||
// {0}: In rule '{1}', the message with id '{2}' does not include any dynamic content. | ||
// Dynamic content makes your messages more specific and avoids the "wall of bugs" | ||
// phenomenon. | ||
// {0}: In rule '{1}', the '{2}' property of the message with id '{3}' does not include | ||
// any dynamic content. Dynamic content makes your messages more specific and avoids the | ||
// "wall of bugs" phenomenon. | ||
LogResult( | ||
textPointer, | ||
pointer, | ||
nameof(RuleResources.SARIF2014_ProvideDynamicMessageContent_Note_Default_Text), | ||
ruleId, | ||
propertyName, | ||
messageKey); | ||
} | ||
} | ||
|
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.
While we're in here, let's back this one up to the
run
level like we did for -- whatever that other rule was earlier today. We are only aboutrun.tool.driver.rules
. #Closed