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

validation rule 1004 #1923

Merged
merged 5 commits into from
Jun 19, 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
8 changes: 4 additions & 4 deletions src/Sarif.Multitool/Rules/RuleId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ public static class RuleId
{
public const string RuleIdentifiersMustBeValid = "SARIF1001";
public const string UrisMustBeValid = "SARIF1002";
public const string ExpressUriBaseIdsCorrectly = "SARIF1004";
public const string UriMustBeAbsolute = "SARIF1005";
public const string InvocationPropertiesMustBeConsistent = "SARIF1006";
public const string AuthorHighQualityMessages = "SARIF2001";
public const string RegionPropertiesMustBeConsistent = "SARIF1007";
public const string UriBaseIdRequiresRelativeUri = "SARIF1014";
public const string UriMustBeAbsolute = "SARIF1005";
public const string PhysicalLocationPropertiesMustBeConsistent = "SARIF1008";
public const string IndexPropertiesMustBeConsistentWithArrays = "SARIF1009";
public const string InvalidUriInOriginalUriBaseIds = "SARIF1018";
public const string RuleIdMustBeConsistent = "SARIF1010";
public const string ReferenceFinalSchema = "SARIF1011";

public const string AuthorHighQualityMessages = "SARIF2001";
public const string ProvideSchema = "SARIF2008";
}
}
96 changes: 46 additions & 50 deletions src/Sarif.Multitool/Rules/RuleResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions src/Sarif.Multitool/Rules/RuleResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@
<data name="SARIF2001_AuthorHighQualityMessages_FullDescription_Text" xml:space="preserve">
<value>Messages should consist of one or more complete sentences, ending with a period.</value>
</data>
<data name="SARIF1014_Default" xml:space="preserve">
<data name="SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdRequiresRelativeUri_Text" xml:space="preserve">
<value>{0}: This fileLocation object contains a "uriBaseId" property, which means that the value of the "uri" property must be a relative URI reference, but "{1}" is an absolute URI reference.</value>
</data>
<data name="SARIF1014_UriBaseIdRequiresRelativeUri" xml:space="preserve">
<value>If a fileLocation object contains a "uriBaseId" property, the value of the "uri" property must be a relative URI reference.</value>
<data name="SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text" xml:space="preserve">
<value>Placeholder_SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text</value>
</data>
<data name="SARIF1005_UriMustBeAbsolute_Error_Default_Text" xml:space="preserve">
<value>{0}: The value of this property is required to be an absolute URI, but "{1}" is a relative URI reference.</value>
Expand All @@ -165,13 +165,10 @@
<data name="SARIF1009_IndexPropertiesMustBeConsistentWithArrays_FullDescription_Text" xml:space="preserve">
<value>If an object contains a property that is used as an array index, then that array must be present and must contain at least "index + 1" elements.</value>
</data>
<data name="SARIF1018_InvalidUriInOriginalUriBaseIds" xml:space="preserve">
<value>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.</value>
</data>
<data name="SARIF1018_LacksTrailingSlash" xml:space="preserve">
<data name="SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdValueMustEndWithSlash_Text" xml:space="preserve">
<value>{0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds does not end with a slash.</value>
</data>
<data name="SARIF1018_NotAbsolute" xml:space="preserve">
<data name="SARIF1004_ExpressUriBaseIdsCorrectly_Error_TopLevelUriBaseIdMustBeAbsolute_Text" xml:space="preserve">
<value>{0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds is not an absolute URI.</value>
</data>
<data name="SARIF1010_RuleIdMustBeConsistent_Error_ResultRuleIdMustBeConsistent_Text" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,35 @@

namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules
{
public class InvalidUriInOriginalUriBaseIds : SarifValidationSkimmerBase
public class ExpressUriBaseIdsCorrectly : SarifValidationSkimmerBase
{
public override MultiformatMessageString FullDescription => new MultiformatMessageString
{
Text = RuleResources.SARIF1018_InvalidUriInOriginalUriBaseIds
Text = RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text
};

public override FailureLevel DefaultLevel => FailureLevel.Error;

public override string Id => RuleId.InvalidUriInOriginalUriBaseIds;
public override string Id => RuleId.ExpressUriBaseIdsCorrectly;

protected override IEnumerable<string> MessageResourceNames => new string[]
{
nameof(RuleResources.SARIF1018_NotAbsolute),
nameof(RuleResources.SARIF1018_LacksTrailingSlash)
nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdRequiresRelativeUri_Text),
nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_TopLevelUriBaseIdMustBeAbsolute_Text),
nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdValueMustEndWithSlash_Text)
};

protected override void Analyze(ArtifactLocation fileLocation, string fileLocationPointer)
{
if (fileLocation.UriBaseId != null && fileLocation.Uri.IsAbsoluteUri)
{
LogResult(
fileLocationPointer.AtProperty(SarifPropertyName.Uri),
nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdRequiresRelativeUri_Text),
fileLocation.Uri.OriginalString);
}
}

protected override void Analyze(Run run, string runPointer)
{
if (run.OriginalUriBaseIds != null)
Expand Down Expand Up @@ -53,12 +65,12 @@ private void AnalyzeOriginalUriBaseIdsEntry(string uriBaseId, ArtifactLocation a

if (artifactLocation.UriBaseId == null && !uri.IsAbsoluteUri)
{
LogResult(pointer, nameof(RuleResources.SARIF1018_NotAbsolute), uriString, uriBaseId);
LogResult(pointer, nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_TopLevelUriBaseIdMustBeAbsolute_Text), uriString, uriBaseId);
}

if (!uriString.EndsWith("/"))
{
LogResult(pointer, nameof(RuleResources.SARIF1018_LacksTrailingSlash), uriString, uriBaseId);
LogResult(pointer, nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdValueMustEndWithSlash_Text), uriString, uriBaseId);
}
}
}
Expand Down

This file was deleted.

Loading