diff --git a/src/Sarif.Converters/PREFastConverter.cs b/src/Sarif.Converters/PREFastConverter.cs index dc0680f88..4314595fe 100644 --- a/src/Sarif.Converters/PREFastConverter.cs +++ b/src/Sarif.Converters/PREFastConverter.cs @@ -85,7 +85,16 @@ private Result CreateResult(Defect defect) }; var resultsFileUri = new Uri($"{defect.SFA.FilePath}{defect.SFA.FileName}", UriKind.Relative); - var physicalLocation = new PhysicalLocation(id: 0, fileLocation: new FileLocation(uri: resultsFileUri, uriBaseId: null, properties: null), region: region, contextRegion: null, properties: null); + + var physicalLocation = new PhysicalLocation + { + FileLocation = new FileLocation + { + Uri = resultsFileUri + }, + Region = region + }; + var location = new Location() { PhysicalLocation = physicalLocation, @@ -169,7 +178,15 @@ private void GenerateCodeFlows(Defect defect, Result result) }; var uri = new Uri($"{sfa.FilePath}{sfa.FileName}", UriKind.Relative); - var fileLocation = new PhysicalLocation(id: 0, fileLocation: new FileLocation(uri: uri, uriBaseId: null, properties: null), region: region, contextRegion: null, properties: null); + var fileLocation = new PhysicalLocation + { + FileLocation = new FileLocation + { + Uri = uri + }, + Region = region + }; + var threadFlowLocation = new ThreadFlowLocation { Location = new Location diff --git a/src/Sarif.Converters/PylintConverter.cs b/src/Sarif.Converters/PylintConverter.cs index 5921def96..21a26d5cd 100644 --- a/src/Sarif.Converters/PylintConverter.cs +++ b/src/Sarif.Converters/PylintConverter.cs @@ -91,7 +91,14 @@ internal Result CreateResult(PylintLogEntry defect) }; var fileUri = new Uri($"{defect.FilePath}", UriKind.RelativeOrAbsolute); - var physicalLocation = new PhysicalLocation(id: 0, fileLocation: new FileLocation(uri: fileUri, uriBaseId: null, properties: null), region: region, contextRegion: null, properties: null); + var physicalLocation = new PhysicalLocation + { + FileLocation = new FileLocation + { + Uri = fileUri + }, + Region = region + }; var location = new Location { diff --git a/src/Sarif.Converters/TSLintConverter.cs b/src/Sarif.Converters/TSLintConverter.cs index cbafadc46..94d29bf50 100644 --- a/src/Sarif.Converters/TSLintConverter.cs +++ b/src/Sarif.Converters/TSLintConverter.cs @@ -99,7 +99,15 @@ internal Result CreateResult(TSLintLogEntry entry) Uri analysisTargetUri = new Uri(entry.Name, UriKind.Relative); - var physicalLocation = new PhysicalLocation(id: 0, fileLocation: new FileLocation(uri: analysisTargetUri, uriBaseId: null, properties: null), region: region, contextRegion: null, properties: null); + var physicalLocation = new PhysicalLocation + { + FileLocation = new FileLocation + { + Uri = analysisTargetUri + }, + Region = region + }; + Location location = new Location() { PhysicalLocation = physicalLocation @@ -135,7 +143,14 @@ internal Result CreateResult(TSLintLogEntry entry) replacements.Add(replacement); } - FileChange sarifFileChange = new FileChange(fileLocation: new FileLocation(uri: analysisTargetUri, uriBaseId: null, properties: null), replacements: replacements, properties: null); + var sarifFileChange = new FileChange + { + FileLocation = new FileLocation + { + Uri = analysisTargetUri + }, + Replacements = replacements + }; Fix sarifFix = new Fix(description: null, fileChanges: new List() { sarifFileChange }, properties: null); result.Fixes = new List { sarifFix }; diff --git a/src/Sarif/Autogenerated/FileLocation.cs b/src/Sarif/Autogenerated/FileLocation.cs index 6a2f91d5c..27b4cf085 100644 --- a/src/Sarif/Autogenerated/FileLocation.cs +++ b/src/Sarif/Autogenerated/FileLocation.cs @@ -46,6 +46,14 @@ public SarifNodeKind SarifNodeKind [DataMember(Name = "uriBaseId", IsRequired = false, EmitDefaultValue = false)] public string UriBaseId { get; set; } + /// + /// The index within the run files array that specifies the file object associated with the file location. + /// + [DataMember(Name = "fileIndex", IsRequired = false, EmitDefaultValue = false)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] + [System.ComponentModel.DefaultValue(-1)] + public int FileIndex { get; set; } + /// /// Key/value pairs that provide additional information about the file location. /// @@ -57,6 +65,7 @@ public SarifNodeKind SarifNodeKind /// public FileLocation() { + FileIndex = -1; } /// @@ -68,12 +77,15 @@ public FileLocation() /// /// An initialization value for the property. /// + /// + /// An initialization value for the property. + /// /// /// An initialization value for the property. /// - public FileLocation(Uri uri, string uriBaseId, IDictionary properties) + public FileLocation(Uri uri, string uriBaseId, int fileIndex, IDictionary properties) { - Init(uri, uriBaseId, properties); + Init(uri, uriBaseId, fileIndex, properties); } /// @@ -92,7 +104,7 @@ public FileLocation(FileLocation other) throw new ArgumentNullException(nameof(other)); } - Init(other.Uri, other.UriBaseId, other.Properties); + Init(other.Uri, other.UriBaseId, other.FileIndex, other.Properties); } ISarifNode ISarifNode.DeepClone() @@ -113,7 +125,7 @@ private ISarifNode DeepCloneCore() return new FileLocation(this); } - private void Init(Uri uri, string uriBaseId, IDictionary properties) + private void Init(Uri uri, string uriBaseId, int fileIndex, IDictionary properties) { if (uri != null) { @@ -121,6 +133,7 @@ private void Init(Uri uri, string uriBaseId, IDictionary(properties); diff --git a/src/Sarif/Autogenerated/FileLocationEqualityComparer.cs b/src/Sarif/Autogenerated/FileLocationEqualityComparer.cs index 1f84a758e..83777757a 100644 --- a/src/Sarif/Autogenerated/FileLocationEqualityComparer.cs +++ b/src/Sarif/Autogenerated/FileLocationEqualityComparer.cs @@ -38,6 +38,11 @@ public bool Equals(FileLocation left, FileLocation right) return false; } + if (left.FileIndex != right.FileIndex) + { + return false; + } + if (!object.ReferenceEquals(left.Properties, right.Properties)) { if (left.Properties == null || right.Properties == null || left.Properties.Count != right.Properties.Count) @@ -83,6 +88,7 @@ public int GetHashCode(FileLocation obj) result = (result * 31) + obj.UriBaseId.GetHashCode(); } + result = (result * 31) + obj.FileIndex.GetHashCode(); if (obj.Properties != null) { // Use xor for dictionaries to be order-independent. diff --git a/src/Sarif/Autogenerated/RuleConfiguration.cs b/src/Sarif/Autogenerated/RuleConfiguration.cs index d1a3ecc4b..58e045b0a 100644 --- a/src/Sarif/Autogenerated/RuleConfiguration.cs +++ b/src/Sarif/Autogenerated/RuleConfiguration.cs @@ -40,14 +40,14 @@ public SarifNodeKind SarifNodeKind public bool Enabled { get; set; } /// - /// Specifies the default severity level of the result. + /// Specifies the default severity level for results generated by this rule. /// [DataMember(Name = "defaultLevel", IsRequired = false, EmitDefaultValue = false)] [JsonConverter(typeof(EnumConverter))] public RuleConfigurationDefaultLevel DefaultLevel { get; set; } /// - /// Specifies the default priority or importance of the result. + /// Specifies the default priority or importance for results generated by this rule. /// [DataMember(Name = "defaultRank", IsRequired = false, EmitDefaultValue = false)] public double DefaultRank { get; set; } diff --git a/src/Sarif/Autogenerated/Run.cs b/src/Sarif/Autogenerated/Run.cs index 2f59c30a9..be1d8455b 100644 --- a/src/Sarif/Autogenerated/Run.cs +++ b/src/Sarif/Autogenerated/Run.cs @@ -64,7 +64,7 @@ public SarifNodeKind SarifNodeKind public IDictionary OriginalUriBaseIds { get; set; } /// - /// A dictionary, each of whose keys is a URI and each of whose values is a file object. + /// An array of file objects relevant to the run. /// [DataMember(Name = "files", IsRequired = false, EmitDefaultValue = false)] public IDictionary Files { get; set; } diff --git a/src/Sarif/CodeGenHints.json b/src/Sarif/CodeGenHints.json index 2fdac55cc..6f6b756fc 100644 --- a/src/Sarif/CodeGenHints.json +++ b/src/Sarif/CodeGenHints.json @@ -209,6 +209,23 @@ } } ], + "FileLocation.FileIndex": [ + { + "kind": "AttributeHint", + "arguments": { + "namespaceName": "Newtonsoft.Json", + "typeName": "JsonProperty", + "arguments": [ "DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate" ] + } + }, + { + "kind": "AttributeHint", + "arguments": { + "typeName": "System.ComponentModel.DefaultValue", + "arguments": [ "-1" ] + } + } + ], "fix": [ { "kind": "BaseTypeHint", @@ -289,6 +306,23 @@ } } ], + "Location.LogicalLocationIndex": [ + { + "kind": "AttributeHint", + "arguments": { + "namespaceName": "Newtonsoft.Json", + "typeName": "JsonProperty", + "arguments": [ "DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate" ] + } + }, + { + "kind": "AttributeHint", + "arguments": { + "typeName": "System.ComponentModel.DefaultValue", + "arguments": [ "-1" ] + } + } + ], "logicalLocation": [ { "kind": "BaseTypeHint", diff --git a/src/Sarif/NotYetAutoGenerated/FileLocation.cs b/src/Sarif/NotYetAutoGenerated/FileLocation.cs new file mode 100644 index 000000000..27b4cf085 --- /dev/null +++ b/src/Sarif/NotYetAutoGenerated/FileLocation.cs @@ -0,0 +1,143 @@ +// Copyright (c) Microsoft. All Rights Reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.CodeDom.Compiler; +using System.Collections.Generic; +using System.Runtime.Serialization; +using Microsoft.CodeAnalysis.Sarif.Readers; +using Newtonsoft.Json; + +namespace Microsoft.CodeAnalysis.Sarif +{ + /// + /// Specifies the location of a file. + /// + [DataContract] + [GeneratedCode("Microsoft.Json.Schema.ToDotNet", "0.58.0.0")] + public partial class FileLocation : PropertyBagHolder, ISarifNode + { + public static IEqualityComparer ValueComparer => FileLocationEqualityComparer.Instance; + + public bool ValueEquals(FileLocation other) => ValueComparer.Equals(this, other); + public int ValueGetHashCode() => ValueComparer.GetHashCode(this); + + /// + /// Gets a value indicating the type of object implementing . + /// + public SarifNodeKind SarifNodeKind + { + get + { + return SarifNodeKind.FileLocation; + } + } + + /// + /// A string containing a valid relative or absolute URI. + /// + [DataMember(Name = "uri", IsRequired = true)] + [JsonConverter(typeof(Microsoft.CodeAnalysis.Sarif.Readers.UriConverter))] + public Uri Uri { get; set; } + + /// + /// A string which indirectly specifies the absolute URI with respect to which a relative URI in the "uri" property is interpreted. + /// + [DataMember(Name = "uriBaseId", IsRequired = false, EmitDefaultValue = false)] + public string UriBaseId { get; set; } + + /// + /// The index within the run files array that specifies the file object associated with the file location. + /// + [DataMember(Name = "fileIndex", IsRequired = false, EmitDefaultValue = false)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] + [System.ComponentModel.DefaultValue(-1)] + public int FileIndex { get; set; } + + /// + /// Key/value pairs that provide additional information about the file location. + /// + [DataMember(Name = "properties", IsRequired = false, EmitDefaultValue = false)] + internal override IDictionary Properties { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public FileLocation() + { + FileIndex = -1; + } + + /// + /// Initializes a new instance of the class from the supplied values. + /// + /// + /// An initialization value for the property. + /// + /// + /// An initialization value for the property. + /// + /// + /// An initialization value for the property. + /// + /// + /// An initialization value for the property. + /// + public FileLocation(Uri uri, string uriBaseId, int fileIndex, IDictionary properties) + { + Init(uri, uriBaseId, fileIndex, properties); + } + + /// + /// Initializes a new instance of the class from the specified instance. + /// + /// + /// The instance from which the new instance is to be initialized. + /// + /// + /// Thrown if is null. + /// + public FileLocation(FileLocation other) + { + if (other == null) + { + throw new ArgumentNullException(nameof(other)); + } + + Init(other.Uri, other.UriBaseId, other.FileIndex, other.Properties); + } + + ISarifNode ISarifNode.DeepClone() + { + return DeepCloneCore(); + } + + /// + /// Creates a deep copy of this instance. + /// + public FileLocation DeepClone() + { + return (FileLocation)DeepCloneCore(); + } + + private ISarifNode DeepCloneCore() + { + return new FileLocation(this); + } + + private void Init(Uri uri, string uriBaseId, int fileIndex, IDictionary properties) + { + if (uri != null) + { + Uri = new Uri(uri.OriginalString, uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative); + } + + UriBaseId = uriBaseId; + FileIndex = fileIndex; + if (properties != null) + { + Properties = new Dictionary(properties); + } + } + } +} \ No newline at end of file diff --git a/src/Sarif/Sarif.csproj b/src/Sarif/Sarif.csproj index 4d4a052dc..48d771ecc 100644 --- a/src/Sarif/Sarif.csproj +++ b/src/Sarif/Sarif.csproj @@ -78,4 +78,6 @@ + + diff --git a/src/Sarif/Schemata/sarif-schema.json b/src/Sarif/Schemata/sarif-schema.json index f7ecdb8a8..2eb6ae272 100644 --- a/src/Sarif/Schemata/sarif-schema.json +++ b/src/Sarif/Schemata/sarif-schema.json @@ -468,6 +468,13 @@ "type": "string" }, + "fileIndex": { + "description": "The index within the run files array of the file object associated with the file location.", + "type": "integer", + "default": -1, + "minimum": -1 + }, + "properties": { "description": "Key/value pairs that provide additional information about the file location.", "$ref": "#/definitions/propertyBag" @@ -758,7 +765,7 @@ }, "logicalLocationIndex": { - "description": "The index within the logicalLocations array that specifies the logical location associated with the result.", + "description": "The index within the logical locations array of the logical location associated with the result.", "type": "integer", "default": -1, "minimum": -1 @@ -1535,7 +1542,7 @@ }, "files": { - "description": "A dictionary, each of whose keys is a URI and each of whose values is a file object.", + "description": "An array of file objects relevant to the run.", "type": "object", "additionalProperties": { "$ref": "#/definitions/file"