Skip to content

Commit

Permalink
Reportingdescriptor name to string change (#1309)
Browse files Browse the repository at this point in the history
* solution builds!

* updating compatTransformer and updating failing TCs

* cleanup

* rc++

* fixing typo in name

* rc++

* fixing UTCs

* removing comment
  • Loading branch information
harleenkohli authored and michaelcfanning committed Mar 1, 2019
1 parent e4dd617 commit bd72a8d
Show file tree
Hide file tree
Showing 30 changed files with 389 additions and 65 deletions.
8 changes: 4 additions & 4 deletions src/Samples/Sarif.Sdk.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static int CreateSarifLogFile(CreateOptions options)
new ReportingDescriptor
{
Id ="CA1819",
Name = new Message { Text = "Properties should not return arrays" },
Name = "Properties should not return arrays",
FullDescription = new Message { Text = "Arrays returned by properties are not write-protected, even if the property is read-only. To keep the array tamper-proof, the property must return a copy of the array. Typically, users will not understand the adverse performance implications of calling such a property." },
MessageStrings = new Dictionary<string, MultiformatMessageString>
{
Expand All @@ -76,7 +76,7 @@ static int CreateSarifLogFile(CreateOptions options)
new ReportingDescriptor
{
Id ="CA1820",
Name = new Message { Text = "Test for empty strings using string length" },
Name = "Test for empty strings using string length",
FullDescription = new Message { Text = "Comparing strings by using the String.Length property or the String.IsNullOrEmpty method is significantly faster than using Equals." },
MessageStrings = new Dictionary<string, MultiformatMessageString>
{
Expand All @@ -92,7 +92,7 @@ static int CreateSarifLogFile(CreateOptions options)
new ReportingDescriptor
{
Id ="CA2105",
Name = new Message { Text = "Array fields should not be read only" },
Name = "Array fields should not be read only",
FullDescription = new Message { Text = "When you apply the read-only (ReadOnly in Visual Basic) modifier to a field that contains an array, the field cannot be changed to reference a different array. However, the elements of the array stored in a read-only field can be changed." },
MessageStrings = new Dictionary<string, MultiformatMessageString>
{
Expand All @@ -108,7 +108,7 @@ static int CreateSarifLogFile(CreateOptions options)
new ReportingDescriptor
{
Id ="CA2215",
Name = new Message { Text = "Dispose methods should call base class dispose" },
Name = "Dispose methods should call base class dispose",
FullDescription = new Message { Text = "If a type inherits from a disposable type, it must call the Dispose method of the base type from its own Dispose method." },
MessageStrings = new Dictionary<string, MultiformatMessageString>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif.Converters/FxCopConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal ReportingDescriptor CreateRule(FxCopLogReader.Context context)
var rule = new ReportingDescriptor
{
Id = context.CheckId,
Name = context.RuleTypeName.ToMessage(),
Name = context.RuleTypeName,
MessageStrings = context.Resolutions.ConvertToMultiformatMessageStringsDictionary()
};

Expand Down
4 changes: 2 additions & 2 deletions src/Sarif.Driver.UnitTests/ExceptionRaisingRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public override string Id
}


public override Message Name
public override string Name
{
get
{
if (_exceptionCondition == ExceptionCondition.AccessingName)
{
throw new InvalidOperationException(nameof(ExceptionCondition.AccessingName));
}
return new Message { Text = nameof(ExceptionRaisingRule) };
return nameof(ExceptionRaisingRule);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class FormatForVisualStudioTests
private static readonly ReportingDescriptor TestRule = new ReportingDescriptor
{
Id = TestRuleId,
Name = new Message { Text = "ThisIsATest" },
Name = "ThisIsATest",
ShortDescription = new Message { Text = "short description" },
FullDescription = new Message { Text = "full description" },
MessageStrings = new Dictionary<string, MultiformatMessageString>
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif.Driver.UnitTests/TestRuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override SupportedPlatform SupportedPlatforms

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

public override Message Name { get { return new Message { Text = this.GetType().Name }; } }
public override string Name => this.GetType().Name;

public override Message FullDescription { get { return new Message { Text = this.GetType().Name + " full description." }; } }

Expand Down
2 changes: 1 addition & 1 deletion src/Sarif.Driver/Sdk/AnalyzeCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private HashSet<Skimmer<TContext>> CreateSkimmers(TContext context)
}
else
{
Warnings.LogUnsupportedPlatformForRule(context, skimmer.Name.Text, skimmer.SupportedPlatforms, currentOS);
Warnings.LogUnsupportedPlatformForRule(context, skimmer.Name, skimmer.SupportedPlatforms, currentOS);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif.Driver/Sdk/DefaultDriverOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static PerLanguageOption<T> CreateRuleSpecificOption<T>(ReportingDescript
// from an arbitrary rule instance. This allows users to create a generic property descriptor
// that is further qualified (by feature name) to be associated with a different check.
return new PerLanguageOption<T>(
feature: rule.Id + "." + rule.Name.Text,
feature: rule.Id + "." + rule.Name,
name: option.Name,
defaultValue: option.DefaultValue,
description: option.Description );
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif.Driver/Sdk/ExportConfigurationCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override int Run(ExportConfigurationOptions exportOptions)
object objectResult;
PropertiesDictionary properties;

string ruleOptionsKey = rule.Id + "." + rule.Name.Text + ".Options";
string ruleOptionsKey = rule.Id + "." + rule.Name + ".Options";

if (!allOptions.TryGetValue(ruleOptionsKey, out objectResult))
{
Expand Down
4 changes: 2 additions & 2 deletions src/Sarif.Driver/Sdk/Skimmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ internal static string FirstSentence(string fullDescription)
int length = Math.Min(fullDescription.Length, 80);
bool truncated = length < fullDescription.Length;
return fullDescription.Substring(0, length) + (truncated ? "..." : "");
}
}

public override Message Name { get { return new Message { Text = this.GetType().Name }; } }
public override string Name => this.GetType().Name;

public IDictionary<string, string> Options { get; }

Expand Down
3 changes: 1 addition & 2 deletions src/Sarif.Multitool/Rules/DoNotUseFriendlyNameAsRuleId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ protected override void Analyze(ReportingDescriptor reportingDescriptor, string
{
if (reportingDescriptor.Id != null &&
reportingDescriptor.Name != null &&
reportingDescriptor.Name.Text != null &&
reportingDescriptor.Id.Equals(reportingDescriptor.Name.Text, StringComparison.OrdinalIgnoreCase))
reportingDescriptor.Id.Equals(reportingDescriptor.Name, StringComparison.OrdinalIgnoreCase))
{
LogResult(
reportingDescriptorPointer,
Expand Down
4 changes: 4 additions & 0 deletions src/Sarif.UnitTests/Sarif.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
<None Remove="TestData\PrereleaseCompatibilityTransformer\Inputs\ToolWithLanguage.sarif" />
<None Remove="TestData\SarifVersionOneToCurrentVisitor\ExpectedOutputs\MinimumWithLanguage.sarif" />
<None Remove="TestData\SarifVersionOneToCurrentVisitor\ExpectedOutputs\NestedInnerExceptionsInNotifications.sarif" />
<None Remove="TestData\SarifVersionOneToCurrentVisitor\ExpectedOutputs\OneRunWithAllReportingDescriptors.sarif" />
<None Remove="TestData\SarifVersionOneToCurrentVisitor\Inputs\MinimumWithLanguage.sarif" />
<None Remove="TestData\SarifVersionOneToCurrentVisitor\Inputs\NestedInnerExceptionsInNotifications.sarif" />
<None Remove="TestData\SarifVersionOneToCurrentVisitor\Inputs\OneRunWithAllReportingDescriptors.sarif" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -93,6 +95,7 @@
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\TwoResultsWithFixes.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\ExpectedOutputs\MinimumWithLanguage.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\ExpectedOutputs\NestedInnerExceptionsInNotifications.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\ExpectedOutputs\OneRunWithAllReportingDescriptors.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\Inputs\BasicResult.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\Inputs\CodeFlows.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\Inputs\Minimum.sarif" />
Expand All @@ -102,6 +105,7 @@
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\Inputs\NestedFiles.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\Inputs\NestedInnerExceptionsInNotifications.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\Inputs\NotificationExceptionWithStack.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\Inputs\OneRunWithAllReportingDescriptors.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\Inputs\OneRunWithBasicInvocation.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\Inputs\OneRunWithFiles.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\Inputs\OneRunWithInvocationAndNotifications.sarif" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
}
},
"defaultConfiguration": {
"level": "error",
"rank": -1.0
"level": "error"
}
},
{
Expand All @@ -42,8 +41,7 @@
},
"defaultConfiguration": {
"enabled": false,
"level": "note",
"rank": -1.0
"level": "note"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"$schema": "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2019-02-20",
"version": "2.0.0-csd.2.beta.2019-02-20",
"runs": [
{
"tool": {
"driver": {
"name": "CodeScanner",
"semanticVersion": "2.1.0",
"ruleDescriptors": [
{
"id": "C2003",
"name": "Rule C2003",
"shortDescription": {
"text": "Rules were meant to be broken."
},
"fullDescription": {
"text": "This is a test for validating modification of tool.driver.ruleDescriptors"
},
"defaultConfiguration": {
"enabled": false,
"level": "error"
}
},
{
"id": "C2004",
"name": "Rule C2004",
"shortDescription": {
"text": "Another rule meant to be broken."
},
"fullDescription": {
"text": "This is a test for validating modification of tool.driver.ruleDescriptors"
},
"defaultConfiguration": {
"enabled": false,
"level": "error"
}
}
]
}
},
"results": [
{
"ruleId": "C2003",
"ruleIndex": 0,
"message": {
"text": "Some testing occurred."
}
},
{
"ruleId": "C2004",
"ruleIndex": 1,
"message": {
"text": "Some testing occurred."
}
}
],
"columnKind": "utf16CodeUnits"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@
"text": "Catfish season continuous hen lamb include dose copy grant."
},
"defaultConfiguration": {
"level": "error",
"rank": -1.0
"level": "error"
},
"helpUri": "http://www.domain.com/rules/c2002.html"
},
{
"id": "C2003",
"name": {
"text": "Rule C2003"
},
"name": "Rule C2003",
"shortDescription": {
"text": "Rules were meant to be broken."
},
Expand All @@ -46,8 +43,7 @@
},
"defaultConfiguration": {
"enabled": false,
"level": "note",
"rank": -1.0
"level": "error"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$schema": "http://json.schemastore.org/sarif-1.0.0",
"version": "1.0.0",
"runs": [
{
"rules": {
"C2003": {
"id": "C2003",
"name": "Rule C2003",
"shortDescription": "Rules were meant to be broken.",
"fullDescription": "This is a test for validating modification of tool.driver.ruleDescriptors",
"configuration": "disabled",
"defaultLevel": "error"
},
"C2004": {
"id": "C2004",
"name": "Rule C2004",
"shortDescription": "Another rule meant to be broken.",
"fullDescription": "This is a test for validating modification of tool.driver.ruleDescriptors",
"configuration": "disabled",
"defaultLevel": "error"
}
},
"tool": {
"name": "CodeScanner",
"semanticVersion": "2.1.0",
"notificationDescriptors": [
{
"id": "MSG0001",
"helpUri": "www.example.com/notifications/msg0001.html"
},
{
"id": "MSG0002",
"helpUri": "www.example.com/notifications/msg0002.html"
}
]
},
"results": [
{
"ruleId": "C2003",
"ruleKey": "C2003",
"message": "Some testing occurred."
},
{
"ruleId": "C2004",
"ruleKey": "C2004",
"message": "Some testing occurred."
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"shortDescription": "Rules were meant to be broken.",
"fullDescription": "Rent internal rebellion competence biography photograph.",
"configuration": "disabled",
"defaultLevel": "pass"
"defaultLevel": "error"
}
},
"tool": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ public void SarifTransformerTests_ToCurrent_OneRunWithFiles()
=> RunTest("OneRunWithFiles.sarif");

[Fact]
public void SarifTransformerTests_ToCurrent_OneRunWitRules()
public void SarifTransformerTests_ToCurrent_OneRunWithRules()
=> RunTest("OneRunWithRules.sarif");

[Fact]
public void SarifTransformerTests_ToCurrent_OneRunWithAllReportingDescriptors()
=> RunTest("OneRunWithAllReportingDescriptors.sarif");

[Fact]
public void SarifTransformerTests_ToCurrent_OneRunWithBasicInvocation()
=> RunTest("OneRunWithBasicInvocation.sarif");
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/ReportingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public SarifNodeKind SarifNodeKind
/// Specifies the relative priority of the report. Used for analysis output only.
/// </summary>
[DataMember(Name = "rank", IsRequired = false, EmitDefaultValue = false)]
[DefaultValue(-1)]
[DefaultValue(-1.0)] // NOTYETAUTOGENERATED: required until https://github.com/Microsoft/jschema/issues/88 is fixed
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
public double Rank { get; set; }

Expand Down
Loading

0 comments on commit bd72a8d

Please sign in to comment.