Skip to content

Commit

Permalink
Add result.rank and ruleConfiguration.defaultRank (#1167)
Browse files Browse the repository at this point in the history
As we discussed offline with @fishoak, the design is good as it stands. The only change is that the default should be -1. I filed oasis-tcs/sarif-spec#303 for that, and put it on the agenda for TC #30.
  • Loading branch information
Larry Golding authored Dec 26, 2018
1 parent 12cbea4 commit 81b8f39
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 deletions.
18 changes: 14 additions & 4 deletions src/Sarif/Autogenerated/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ public SarifNodeKind SarifNodeKind
[JsonConverter(typeof(EnumConverter))]
public BaselineState BaselineState { get; set; }

/// <summary>
/// A number representing the priority or importance of the result.
/// </summary>
[DataMember(Name = "rank", IsRequired = false, EmitDefaultValue = false)]
public double Rank { get; set; }

/// <summary>
/// A set of files relevant to the result.
/// </summary>
Expand Down Expand Up @@ -237,6 +243,9 @@ public Result()
/// <param name="baselineState">
/// An initialization value for the <see cref="P: BaselineState" /> property.
/// </param>
/// <param name="rank">
/// An initialization value for the <see cref="P: Rank" /> property.
/// </param>
/// <param name="attachments">
/// An initialization value for the <see cref="P: Attachments" /> property.
/// </param>
Expand All @@ -255,9 +264,9 @@ public Result()
/// <param name="properties">
/// An initialization value for the <see cref="P: Properties" /> property.
/// </param>
public Result(string ruleId, ResultLevel level, Message message, FileLocation analysisTarget, IEnumerable<Location> locations, string instanceGuid, string correlationGuid, int occurrenceCount, IDictionary<string, string> partialFingerprints, IDictionary<string, string> fingerprints, IEnumerable<Stack> stacks, IEnumerable<CodeFlow> codeFlows, IDictionary<string, Graph> graphs, IEnumerable<GraphTraversal> graphTraversals, IEnumerable<Location> relatedLocations, SuppressionStates suppressionStates, BaselineState baselineState, IEnumerable<Attachment> attachments, Uri hostedViewerUri, IEnumerable<Uri> workItemUris, IEnumerable<PhysicalLocation> conversionProvenance, IEnumerable<Fix> fixes, IDictionary<string, SerializedPropertyInfo> properties)
public Result(string ruleId, ResultLevel level, Message message, FileLocation analysisTarget, IEnumerable<Location> locations, string instanceGuid, string correlationGuid, int occurrenceCount, IDictionary<string, string> partialFingerprints, IDictionary<string, string> fingerprints, IEnumerable<Stack> stacks, IEnumerable<CodeFlow> codeFlows, IDictionary<string, Graph> graphs, IEnumerable<GraphTraversal> graphTraversals, IEnumerable<Location> relatedLocations, SuppressionStates suppressionStates, BaselineState baselineState, double rank, IEnumerable<Attachment> attachments, Uri hostedViewerUri, IEnumerable<Uri> workItemUris, IEnumerable<PhysicalLocation> conversionProvenance, IEnumerable<Fix> fixes, IDictionary<string, SerializedPropertyInfo> properties)
{
Init(ruleId, level, message, analysisTarget, locations, instanceGuid, correlationGuid, occurrenceCount, partialFingerprints, fingerprints, stacks, codeFlows, graphs, graphTraversals, relatedLocations, suppressionStates, baselineState, attachments, hostedViewerUri, workItemUris, conversionProvenance, fixes, properties);
Init(ruleId, level, message, analysisTarget, locations, instanceGuid, correlationGuid, occurrenceCount, partialFingerprints, fingerprints, stacks, codeFlows, graphs, graphTraversals, relatedLocations, suppressionStates, baselineState, rank, attachments, hostedViewerUri, workItemUris, conversionProvenance, fixes, properties);
}

/// <summary>
Expand All @@ -276,7 +285,7 @@ public Result(Result other)
throw new ArgumentNullException(nameof(other));
}

Init(other.RuleId, other.Level, other.Message, other.AnalysisTarget, other.Locations, other.InstanceGuid, other.CorrelationGuid, other.OccurrenceCount, other.PartialFingerprints, other.Fingerprints, other.Stacks, other.CodeFlows, other.Graphs, other.GraphTraversals, other.RelatedLocations, other.SuppressionStates, other.BaselineState, other.Attachments, other.HostedViewerUri, other.WorkItemUris, other.ConversionProvenance, other.Fixes, other.Properties);
Init(other.RuleId, other.Level, other.Message, other.AnalysisTarget, other.Locations, other.InstanceGuid, other.CorrelationGuid, other.OccurrenceCount, other.PartialFingerprints, other.Fingerprints, other.Stacks, other.CodeFlows, other.Graphs, other.GraphTraversals, other.RelatedLocations, other.SuppressionStates, other.BaselineState, other.Rank, other.Attachments, other.HostedViewerUri, other.WorkItemUris, other.ConversionProvenance, other.Fixes, other.Properties);
}

ISarifNode ISarifNode.DeepClone()
Expand All @@ -297,7 +306,7 @@ private ISarifNode DeepCloneCore()
return new Result(this);
}

private void Init(string ruleId, ResultLevel level, Message message, FileLocation analysisTarget, IEnumerable<Location> locations, string instanceGuid, string correlationGuid, int occurrenceCount, IDictionary<string, string> partialFingerprints, IDictionary<string, string> fingerprints, IEnumerable<Stack> stacks, IEnumerable<CodeFlow> codeFlows, IDictionary<string, Graph> graphs, IEnumerable<GraphTraversal> graphTraversals, IEnumerable<Location> relatedLocations, SuppressionStates suppressionStates, BaselineState baselineState, IEnumerable<Attachment> attachments, Uri hostedViewerUri, IEnumerable<Uri> workItemUris, IEnumerable<PhysicalLocation> conversionProvenance, IEnumerable<Fix> fixes, IDictionary<string, SerializedPropertyInfo> properties)
private void Init(string ruleId, ResultLevel level, Message message, FileLocation analysisTarget, IEnumerable<Location> locations, string instanceGuid, string correlationGuid, int occurrenceCount, IDictionary<string, string> partialFingerprints, IDictionary<string, string> fingerprints, IEnumerable<Stack> stacks, IEnumerable<CodeFlow> codeFlows, IDictionary<string, Graph> graphs, IEnumerable<GraphTraversal> graphTraversals, IEnumerable<Location> relatedLocations, SuppressionStates suppressionStates, BaselineState baselineState, double rank, IEnumerable<Attachment> attachments, Uri hostedViewerUri, IEnumerable<Uri> workItemUris, IEnumerable<PhysicalLocation> conversionProvenance, IEnumerable<Fix> fixes, IDictionary<string, SerializedPropertyInfo> properties)
{
RuleId = ruleId;
Level = level;
Expand Down Expand Up @@ -425,6 +434,7 @@ private void Init(string ruleId, ResultLevel level, Message message, FileLocatio

SuppressionStates = suppressionStates;
BaselineState = baselineState;
Rank = rank;
if (attachments != null)
{
var destination_5 = new List<Attachment>();
Expand Down
6 changes: 6 additions & 0 deletions src/Sarif/Autogenerated/ResultEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ public bool Equals(Result left, Result right)
return false;
}

if (left.Rank != right.Rank)
{
return false;
}

if (!object.ReferenceEquals(left.Attachments, right.Attachments))
{
if (left.Attachments == null || right.Attachments == null)
Expand Down Expand Up @@ -520,6 +525,7 @@ public int GetHashCode(Result obj)

result = (result * 31) + obj.SuppressionStates.GetHashCode();
result = (result * 31) + obj.BaselineState.GetHashCode();
result = (result * 31) + obj.Rank.GetHashCode();
if (obj.Attachments != null)
{
foreach (var value_16 in obj.Attachments)
Expand Down
18 changes: 14 additions & 4 deletions src/Sarif/Autogenerated/RuleConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public SarifNodeKind SarifNodeKind
[JsonConverter(typeof(EnumConverter))]
public RuleConfigurationDefaultLevel DefaultLevel { get; set; }

/// <summary>
/// Specifies the default priority or importance of the result.
/// </summary>
[DataMember(Name = "defaultRank", IsRequired = false, EmitDefaultValue = false)]
public double DefaultRank { get; set; }

/// <summary>
/// Contains configuration information specific to this rule.
/// </summary>
Expand Down Expand Up @@ -74,15 +80,18 @@ public RuleConfiguration()
/// <param name="defaultLevel">
/// An initialization value for the <see cref="P: DefaultLevel" /> property.
/// </param>
/// <param name="defaultRank">
/// An initialization value for the <see cref="P: DefaultRank" /> property.
/// </param>
/// <param name="parameters">
/// An initialization value for the <see cref="P: Parameters" /> property.
/// </param>
/// <param name="properties">
/// An initialization value for the <see cref="P: Properties" /> property.
/// </param>
public RuleConfiguration(bool enabled, RuleConfigurationDefaultLevel defaultLevel, IDictionary<string, SerializedPropertyInfo> parameters, IDictionary<string, SerializedPropertyInfo> properties)
public RuleConfiguration(bool enabled, RuleConfigurationDefaultLevel defaultLevel, double defaultRank, IDictionary<string, SerializedPropertyInfo> parameters, IDictionary<string, SerializedPropertyInfo> properties)
{
Init(enabled, defaultLevel, parameters, properties);
Init(enabled, defaultLevel, defaultRank, parameters, properties);
}

/// <summary>
Expand All @@ -101,7 +110,7 @@ public RuleConfiguration(RuleConfiguration other)
throw new ArgumentNullException(nameof(other));
}

Init(other.Enabled, other.DefaultLevel, other.Parameters, other.Properties);
Init(other.Enabled, other.DefaultLevel, other.DefaultRank, other.Parameters, other.Properties);
}

ISarifNode ISarifNode.DeepClone()
Expand All @@ -122,10 +131,11 @@ private ISarifNode DeepCloneCore()
return new RuleConfiguration(this);
}

private void Init(bool enabled, RuleConfigurationDefaultLevel defaultLevel, IDictionary<string, SerializedPropertyInfo> parameters, IDictionary<string, SerializedPropertyInfo> properties)
private void Init(bool enabled, RuleConfigurationDefaultLevel defaultLevel, double defaultRank, IDictionary<string, SerializedPropertyInfo> parameters, IDictionary<string, SerializedPropertyInfo> properties)
{
Enabled = enabled;
DefaultLevel = defaultLevel;
DefaultRank = defaultRank;
if (parameters != null)
{
Parameters = new Dictionary<string, SerializedPropertyInfo>(parameters);
Expand Down
6 changes: 6 additions & 0 deletions src/Sarif/Autogenerated/RuleConfigurationEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public bool Equals(RuleConfiguration left, RuleConfiguration right)
return false;
}

if (left.DefaultRank != right.DefaultRank)
{
return false;
}

if (!object.ReferenceEquals(left.Parameters, right.Parameters))
{
if (left.Parameters == null || right.Parameters == null || left.Parameters.Count != right.Parameters.Count)
Expand Down Expand Up @@ -97,6 +102,7 @@ public int GetHashCode(RuleConfiguration obj)
{
result = (result * 31) + obj.Enabled.GetHashCode();
result = (result * 31) + obj.DefaultLevel.GetHashCode();
result = (result * 31) + obj.DefaultRank.GetHashCode();
if (obj.Parameters != null)
{
// Use xor for dictionaries to be order-independent.
Expand Down
6 changes: 6 additions & 0 deletions src/Sarif/NotYetAutoGenerated/ResultEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ public bool Equals(Result left, Result right)
return false;
}

if (left.Rank != right.Rank)
{
return false;
}

if (!object.ReferenceEquals(left.Attachments, right.Attachments))
{
if (left.Attachments == null || right.Attachments == null)
Expand Down Expand Up @@ -520,6 +525,7 @@ public int GetHashCode(Result obj)

result = (result * 31) + obj.SuppressionStates.GetHashCode();
result = (result * 31) + obj.BaselineState.GetHashCode();
result = (result * 31) + obj.Rank.GetHashCode();
if (obj.Attachments != null)
{
foreach (var value_16 in obj.Attachments)
Expand Down
17 changes: 16 additions & 1 deletion src/Sarif/Schemata/sarif-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,13 @@
]
},

"rank": {
"description": "A number representing the priority or importance of the result.",
"type":"number",
"minimum": 0.0,
"maximum": 100.0
},

"attachments": {
"description": "A set of files relevant to the result.",
"type": "array",
Expand Down Expand Up @@ -1458,11 +1465,19 @@
},

"defaultLevel": {
"description": "Specifies the default severity level of the result.",
"description": "Specifies the default severity level for results generated by this rule.",
"default": "warning",
"enum": [ "note", "warning", "error" ]
},

"defaultRank": {
"description": "Specifies the default priority or importance for results generated by this rule.",
"type":"number",
"minimum": 0.0,
"maximum": 100.0,
"default": 0.0
},

"parameters": {
"description": "Contains configuration information specific to this rule.",
"$ref": "#/definitions/propertyBag"
Expand Down

0 comments on commit 81b8f39

Please sign in to comment.