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 1007 #1922

Merged
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
3 changes: 1 addition & 2 deletions src/Sarif.Multitool/Rules/RuleId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public static class RuleId
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 RegionPropertiesMustBeConsistent = "SARIF1007";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RegionPropertiesMustBeConsistent [](start = 28, length = 32)

Let's put these in numeric order now.

public const string UriBaseIdRequiresRelativeUri = "SARIF1014";
public const string UriMustBeAbsolute = "SARIF1005";
public const string PhysicalLocationPropertiesMustBeConsistent = "SARIF1008";
Expand Down
72 changes: 30 additions & 42 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.

21 changes: 9 additions & 12 deletions src/Sarif.Multitool/Rules/RuleResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,6 @@
<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">
<value>{0}: The value of the "endLine" property is {1}, which is less than the value of the "startLine" property, which is {2}.</value>
</data>
<data name="SARIF1012_EndLineMustNotBeLessThanStartLine" xml:space="preserve">
<value>The "endLine" property of a region object must not be less than the "startLine" property.</value>
</data>
<data name="SARIF1013_Default" xml:space="preserve">
<value>{0}: The value of the "endColumn" property is {1}, which is less than the value of the "startColumn" property, which is {2}.</value>
</data>
<data name="SARIF1013_EndColumnMustNotBeLessThanStartColumn" xml:space="preserve">
<value>The "endColumn" property of a region object must not be less than the "startColumn" property.</value>
</data>
<data name="SARIF1014_Default" 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>
Expand Down Expand Up @@ -210,4 +198,13 @@
<data name="SARIF2008_ProvideSchema_Warning_Default_Text" xml:space="preserve">
<value>{0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.</value>
</data>
<data name="SARIF1007_RegionPropertiesMustBeConsistent_Error_EndColumnMustNotPrecedeStartColumn_Text" xml:space="preserve">
<value>{0}: The value of the "endColumn" property is {1}, which is less than the value of the "startColumn" property, which is {2}.</value>
</data>
<data name="SARIF1007_RegionPropertiesMustBeConsistent_Error_EndLineMustNotPrecedeStartLine_Text" xml:space="preserve">
<value>{0}: The value of the "endLine" property is {1}, which is less than the value of the "startLine" property, which is {2}.</value>
</data>
<data name="SARIF1007_RegionPropertiesMustBeConsistent_FullDescription_Text" xml:space="preserve">
<value>Placeholder_SARIF1007_RegionPropertiesMustBeConsistent_FullDescription_Text</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,41 @@

namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules
{
public class EndColumnMustNotBeLessThanStartColumn : SarifValidationSkimmerBase
public class RegionPropertiesMustBeConsistent : SarifValidationSkimmerBase
{
public override MultiformatMessageString FullDescription => new MultiformatMessageString
{
Text = RuleResources.SARIF1013_EndColumnMustNotBeLessThanStartColumn
Text = RuleResources.SARIF1007_RegionPropertiesMustBeConsistent_FullDescription_Text
};

public override FailureLevel DefaultLevel => FailureLevel.Error;

public override string Id => RuleId.EndColumnMustNotBeLessThanStartColumn;
public override string Id => RuleId.RegionPropertiesMustBeConsistent;

protected override IEnumerable<string> MessageResourceNames => new string[]
{
nameof(RuleResources.SARIF1013_Default)
nameof(RuleResources.SARIF1007_RegionPropertiesMustBeConsistent_Error_EndLineMustNotPrecedeStartLine_Text),
nameof(RuleResources.SARIF1007_RegionPropertiesMustBeConsistent_Error_EndColumnMustNotPrecedeStartColumn_Text)
};

protected override void Analyze(Region region, string regionPointer)
{
var jsonPointer = new JsonPointer(regionPointer);
JToken regionToken = jsonPointer.Evaluate(Context.InputLogToken);

if (regionToken.HasProperty(SarifPropertyName.EndLine) &&
region.EndLine < region.StartLine)
{
string endLinePointer = regionPointer.AtProperty(SarifPropertyName.EndLine);

LogResult(
endLinePointer,
nameof(RuleResources.SARIF1007_RegionPropertiesMustBeConsistent_Error_EndLineMustNotPrecedeStartLine_Text),
region.EndLine.ToInvariantString(),
region.StartLine.ToInvariantString());
}


if (RegionIsOnOneLine(region, regionToken) &&
regionToken.HasProperty(SarifPropertyName.EndColumn) &&
region.EndColumn < region.StartColumn)
Expand All @@ -36,7 +50,7 @@ protected override void Analyze(Region region, string regionPointer)

LogResult(
endColumnPointer,
nameof(RuleResources.SARIF1013_Default),
nameof(RuleResources.SARIF1007_RegionPropertiesMustBeConsistent_Error_EndColumnMustNotPrecedeStartColumn_Text),
region.EndColumn.ToInvariantString(),
region.StartColumn.ToInvariantString());
}
Expand Down

This file was deleted.

14 changes: 4 additions & 10 deletions src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,13 @@ public void SARIF2001_AuthorHighQualityMessages_Invalid()
* test file names in TestData\Inputs and TestData\ExpectedOutputs.
******************/
[Fact]
public void SARIF1012_EndLineMustNotBeLessThanStartLine_Valid()
=> RunTest(MakeValidTestFileName(RuleId.EndLineMustNotBeLessThanStartLine, "EndLineMustNotBeLessThanStart"));
public void SARIF1007_RegionPropertiesMustBeConsistent_Valid()
=> RunTest(MakeValidTestFileName(RuleId.RegionPropertiesMustBeConsistent, "RegionPropertiesMustBeConsistent"));

[Fact]
public void SARIF1012_EndLineMustNotBeLessThanStartLine_Invalid()
=> RunTest(MakeInvalidTestFileName(RuleId.EndLineMustNotBeLessThanStartLine, "EndLineMustNotBeLessThanStart"));
[Fact]
public void SARIF1013_EndColumnMustNotBeLessThanStartColumn_Valid()
=> RunTest(MakeValidTestFileName(RuleId.EndColumnMustNotBeLessThanStartColumn, "EndColumnMustNotBeLessThanStart"));
public void SARIF1007_RegionPropertiesMustBeConsistent_Invalid()
=> RunTest(MakeInvalidTestFileName(RuleId.RegionPropertiesMustBeConsistent, "RegionPropertiesMustBeConsistent"));

[Fact]
public void SARIF1013_EndColumnMustNotBeLessThanStartColumn_Invalid()
=> RunTest(MakeInvalidTestFileName(RuleId.EndColumnMustNotBeLessThanStartColumn, "EndColumnMustNotBeLessThanStart"));
/********** END PROBLEMATIC TESTS*******/

[Fact]
Expand Down
Loading