Skip to content

Commit

Permalink
sarif validation rules 1002 1006 2001 (#1918)
Browse files Browse the repository at this point in the history
* changing rule ids only

* updating rule names and message ids

Co-authored-by: Harleen Kaur Kohli <erferferfg>
  • Loading branch information
harleenkohli authored Jun 18, 2020
1 parent 1b94f25 commit a872717
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 126 deletions.
6 changes: 3 additions & 3 deletions src/Sarif.Multitool/Rules/RuleId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules
public static class RuleId
{
public const string RuleIdentifiersMustBeValid = "SARIF1001";
public const string UrisMustBeValid = "SARIF1003";
public const string EndTimeMustNotBeBeforeStartTime = "SARIF1007";
public const string MessagesShouldEndWithPeriod = "SARIF1008";
public const string UrisMustBeValid = "SARIF1002";
public const string InvocationPropertiesMustBeConsistent = "SARIF1006";
public const string AuthorHighQualityMessages = "SARIF2001";
public const string EndLineMustNotBeLessThanStartLine = "SARIF1012";
public const string EndColumnMustNotBeLessThanStartColumn = "SARIF1013";
public const string UriBaseIdRequiresRelativeUri = "SARIF1014";
Expand Down
53 changes: 27 additions & 26 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.

12 changes: 6 additions & 6 deletions src/Sarif.Multitool/Rules/RuleResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,22 @@
<data name="SARIF1001_RuleIdentifiersMustBeValid_FullDescription_Text" xml:space="preserve">
<value>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".</value>
</data>
<data name="SARIF1003_Default" xml:space="preserve">
<data name="SARIF1002_UrisMustBeValid_Error_UrisMustConformToRfc3986_Text" xml:space="preserve">
<value>{0}: The string "{1}" is not a valid URI reference.</value>
</data>
<data name="SARIF1003_UrisMustBeValid" xml:space="preserve">
<data name="SARIF1002_UrisMustBeValid_FullDescription_Text" xml:space="preserve">
<value>Specify a valid URI reference for every URI-valued property.</value>
</data>
<data name="SARIF1007_Default" xml:space="preserve">
<data name="SARIF1006_InvocationPropertiesMustBeConsistent_Error_EndTimeMustNotPrecedeStartTime_Text" xml:space="preserve">
<value>{0}: The end time "{1}" is before the start time "{2}".</value>
</data>
<data name="SARIF1007_EndTimeMustNotBeBeforeStartTime" xml:space="preserve">
<data name="SARIF1006_InvocationPropertiesMustBeConsistent_FullDescription_Text" xml:space="preserve">
<value>The end time of a run must not precede the start time. To allow for the possibility that the duration of the run is less than the resolution of the string representation of the time, the start time and the end time may be equal.</value>
</data>
<data name="SARIF1008_Default" xml:space="preserve">
<data name="SARIF2001_AuthorHighQualityMessages_Warning_TerminateWithPeriod_Text" xml:space="preserve">
<value>{0}: The message "{1}" does not end with a period.</value>
</data>
<data name="SARIF1008_MessagesShouldEndWithPeriod" xml:space="preserve">
<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="SARIF1012_Default" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class UrisMustBeValid : SarifValidationSkimmerBase
{
public override MultiformatMessageString FullDescription => new MultiformatMessageString
{
Text = RuleResources.SARIF1003_UrisMustBeValid
Text = RuleResources.SARIF1002_UrisMustBeValid_FullDescription_Text
};

public override FailureLevel DefaultLevel => FailureLevel.Error;
Expand All @@ -21,7 +21,7 @@ public class UrisMustBeValid : SarifValidationSkimmerBase

protected override IEnumerable<string> MessageResourceNames => new string[]
{
nameof(RuleResources.SARIF1003_Default)
nameof(RuleResources.SARIF1002_UrisMustBeValid_Error_UrisMustConformToRfc3986_Text)
};

protected override void Analyze(SarifLog log, string logPointer)
Expand Down Expand Up @@ -87,7 +87,7 @@ private void AnalyzeUri(string uri, string pointer)
{
if (!Uri.IsWellFormedUriString(uri, UriKind.RelativeOrAbsolute))
{
LogResult(pointer, nameof(RuleResources.SARIF1003_Default), uri);
LogResult(pointer, nameof(RuleResources.SARIF1002_UrisMustBeValid_Error_UrisMustConformToRfc3986_Text), uri);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules
{
public class EndTimeMustNotBeBeforeStartTime : SarifValidationSkimmerBase
public class InvocationPropertiesMustBeConsistent : SarifValidationSkimmerBase
{
public override MultiformatMessageString FullDescription => new MultiformatMessageString
{
Text = RuleResources.SARIF1007_EndTimeMustNotBeBeforeStartTime
Text = RuleResources.SARIF1006_InvocationPropertiesMustBeConsistent_FullDescription_Text
};

public override FailureLevel DefaultLevel => FailureLevel.Error;

public override string Id => RuleId.EndTimeMustNotBeBeforeStartTime;
public override string Id => RuleId.InvocationPropertiesMustBeConsistent;

protected override IEnumerable<string> MessageResourceNames => new string[]
{
nameof(RuleResources.SARIF1007_Default)
nameof(RuleResources.SARIF1006_InvocationPropertiesMustBeConsistent_Error_EndTimeMustNotPrecedeStartTime_Text)
};

protected override void Analyze(Invocation invocation, string invocationPointer)
Expand All @@ -35,7 +35,7 @@ protected override void Analyze(Invocation invocation, string invocationPointer)

LogResult(
endTimePointer,
nameof(RuleResources.SARIF1007_Default),
nameof(RuleResources.SARIF1006_InvocationPropertiesMustBeConsistent_Error_EndTimeMustNotPrecedeStartTime_Text),
FormatDateTime(invocation.EndTimeUtc),
FormatDateTime(invocation.StartTimeUtc));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@

namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules
{
public class MessagesShouldEndWithPeriod : SarifValidationSkimmerBase
public class AuthorHighQualityMessages : SarifValidationSkimmerBase
{
public override MultiformatMessageString FullDescription => new MultiformatMessageString
{
Text = RuleResources.SARIF1008_MessagesShouldEndWithPeriod
Text = RuleResources.SARIF2001_AuthorHighQualityMessages_FullDescription_Text
};

public override FailureLevel DefaultLevel => FailureLevel.Warning;

public override string Id => RuleId.MessagesShouldEndWithPeriod;
public override string Id => RuleId.AuthorHighQualityMessages;

protected override IEnumerable<string> MessageResourceNames
{
get
{
return new string[]
{
nameof(RuleResources.SARIF1008_Default)
nameof(RuleResources.SARIF2001_AuthorHighQualityMessages_Warning_TerminateWithPeriod_Text)
};
}
}
Expand Down Expand Up @@ -74,7 +74,7 @@ private void AnalyzeMessageString(

LogResult(
textPointer,
nameof(RuleResources.SARIF1008_Default),
nameof(RuleResources.SARIF2001_AuthorHighQualityMessages_Warning_TerminateWithPeriod_Text),
messageString);
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ public void SARIF1001_RuleIdentifiersMustBeValid_Invalid()
=> RunTest(MakeInvalidTestFileName(RuleId.RuleIdentifiersMustBeValid, nameof(RuleId.RuleIdentifiersMustBeValid)));

[Fact]
public void SARIF1003_UrisMustBeValid_Valid()
public void SARIF1002_UrisMustBeValid_Valid()
=> RunTest(MakeValidTestFileName(RuleId.UrisMustBeValid, nameof(RuleId.UrisMustBeValid)));

[Fact]
public void SARIF1003_UrisMustBeValid_Invalid()
public void SARIF1002_UrisMustBeValid_Invalid()
=> RunTest(MakeInvalidTestFileName(RuleId.UrisMustBeValid, nameof(RuleId.UrisMustBeValid)));

[Fact]
public void SARIF1007_EndTimeMustNotBeBeforeStartTime_Valid()
=> RunTest(MakeValidTestFileName(RuleId.EndTimeMustNotBeBeforeStartTime, nameof(RuleId.EndTimeMustNotBeBeforeStartTime)));
public void SARIF1006_InvocationPropertiesMustBeConsistent_Valid()
=> RunTest(MakeValidTestFileName(RuleId.InvocationPropertiesMustBeConsistent, nameof(RuleId.InvocationPropertiesMustBeConsistent)));

[Fact]
public void SARIF1007_EndTimeMustNotBeBeforeStartTime_Invalid()
=> RunTest(MakeInvalidTestFileName(RuleId.EndTimeMustNotBeBeforeStartTime, nameof(RuleId.EndTimeMustNotBeBeforeStartTime)));
public void SARIF1006_InvocationPropertiesMustBeConsistent_Invalid()
=> RunTest(MakeInvalidTestFileName(RuleId.InvocationPropertiesMustBeConsistent, nameof(RuleId.InvocationPropertiesMustBeConsistent)));
[Fact]
public void SARIF1008_MessagesShouldEndWithPeriod_Valid()
=> RunTest(MakeValidTestFileName(RuleId.MessagesShouldEndWithPeriod, nameof(RuleId.MessagesShouldEndWithPeriod)));
public void SARIF2001_AuthorHighQualityMessages_Valid()
=> RunTest(MakeValidTestFileName(RuleId.AuthorHighQualityMessages, nameof(RuleId.AuthorHighQualityMessages)));

[Fact]
public void SARIF1008_MessagesShouldEndWithPeriod_Invalid()
=> RunTest(MakeInvalidTestFileName(RuleId.MessagesShouldEndWithPeriod, nameof(RuleId.MessagesShouldEndWithPeriod)));
public void SARIF2001_AuthorHighQualityMessages_Invalid()
=> RunTest(MakeInvalidTestFileName(RuleId.AuthorHighQualityMessages, nameof(RuleId.AuthorHighQualityMessages)));

/******************
* This set of tests constructs a full file path that exceeds MAX_PATH when running in some AzureDevOps build and test
Expand Down
Loading

0 comments on commit a872717

Please sign in to comment.