Skip to content
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 method to create correct short description #1888

Merged
1 commit merged into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 5 additions & 35 deletions src/Sarif.Driver/Sdk/Skimmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ public Skimmer()
{
this.Options = new Dictionary<string, string>();
}

private IDictionary<string, MultiformatMessageString> multiformatMessageStrings;

virtual protected ResourceManager ResourceManager => null;
protected virtual ResourceManager ResourceManager => null;

virtual protected IEnumerable<string> MessageResourceNames => throw new NotImplementedException();
protected virtual IEnumerable<string> MessageResourceNames => throw new NotImplementedException();

virtual public FailureLevel DefaultLevel { get { return FailureLevel.Warning; } }

override public IDictionary<string, MultiformatMessageString> MessageStrings
public override IDictionary<string, MultiformatMessageString> MessageStrings
{
get
{
Expand All @@ -43,38 +44,7 @@ private Dictionary<string, MultiformatMessageString> InitializeMultiformatMessag

public override MultiformatMessageString FullDescription => throw new InvalidOperationException($"The {nameof(FullDescription)} property must be overridden in the SkimmerBase-derived class.");

public override MultiformatMessageString ShortDescription
{
get { return new MultiformatMessageString { Text = FirstSentence(FullDescription.Text) }; }
}

internal static string FirstSentence(string fullDescription)
{
int charCount = 0;
bool withinApostrophe = false;

foreach (char ch in fullDescription)
{
charCount++;
switch (ch)
{
case '\'':
{
withinApostrophe = !withinApostrophe;
continue;
}

case '.':
{
if (withinApostrophe) { continue; }
return fullDescription.Substring(0, charCount);
}
}
}
int length = Math.Min(fullDescription.Length, 80);
bool truncated = length < fullDescription.Length;
return fullDescription.Substring(0, length) + (truncated ? "..." : "");
}
public override MultiformatMessageString ShortDescription => new MultiformatMessageString { Text = ExtensionMethods.GetFirstSentence(FullDescription.Text) };

public override string Name => this.GetType().Name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"id": "SARIF1001",
"name": "DoNotUseFriendlyNameAsRuleId",
"shortDescription": {
"text": "Do not use the same string for a rule's id and name properties. The id property ..."
"text": "Do not use the same string for a rule's id and name properties."
},
"fullDescription": {
"text": "Do not use the same string for a rule's id and name properties. The id property must be a stable, opaque identifer such as \"SARIF1001\". The name property should be a string that is understandable to an end user, such as \"DoNotUserFriendlyNameAsRuleId\"."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"id": "SARIF1018",
"name": "InvalidUriInOriginalUriBaseIds",
"shortDescription": {
"text": "In the artifactLocation objects contained in run."
"text": "In the artifactLocation objects contained in run.originalUriBaseIds, if uriBaseId is absent, then uri must either be an absolute URI or it must be absent."
},
"fullDescription": {
"text": "In the artifactLocation objects contained in run.originalUriBaseIds, if uriBaseId is absent, then uri must either be an absolute URI or it must be absent. Also, uri must end with a slash, so that it can safely be combined with the relative URIs in artifactLocation objects elsewhere in the log file."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"id": "SARIF1019",
"name": "RuleIdMustBePresentAndConsistent",
"shortDescription": {
"text": "In every result, at least one of the properties result."
"text": "In every result, at least one of the properties result.ruleId and result.rule.id must be present."
},
"fullDescription": {
"text": "In every result, at least one of the properties result.ruleId and result.rule.id must be present. If both are present, they must be equal."
Expand Down
1 change: 1 addition & 0 deletions src/Test.UnitTests.Sarif/ExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ public void Extensions_ConsumeElementOfDepth_ConsumesEndElement()
[InlineData("Abbreviations such as approx. don't fool us.", "Abbreviations such as approx. don't fool us.")]
// Expected bad output cases
[InlineData("no space after period.cannot return good sentence.", "no space after period.cannot return good sentence.")]
[InlineData("In every result, at least one of the properties result.ruleId and result.rule.id must be present. If both are present, they must be equal.", "In every result, at least one of the properties result.ruleId and result.rule.id must be present.")]
public void Extensions_ExtractsFirstSentenceProperly(string input, string expected)
{
string actual = ExtensionMethods.GetFirstSentence(input);
Expand Down