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

Updating rules based on the guidelines #1955

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
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class RuleIdentifiersMustBeValid : SarifValidationSkimmerBase
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF1001_RuleIdentifiersMustBeValid_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Warning;

Expand Down
6 changes: 3 additions & 3 deletions src/Sarif.Multitool/Rules/SARIF1002.UrisMustBeValid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class UrisMustBeValid : SarifValidationSkimmerBase
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF1002_UrisMustBeValid_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Error;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public class ExpressUriBaseIdsCorrectly : SarifValidationSkimmerBase
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Error;

Expand Down
11 changes: 7 additions & 4 deletions src/Sarif.Multitool/Rules/SARIF1005.UriMustBeAbsolute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class UriMustBeAbsolute : SarifValidationSkimmerBase
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF1005_UriMustBeAbsolute_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Error;

Expand Down Expand Up @@ -80,8 +80,11 @@ private void AnalyzeUri(string uriString, string pointer)
Uri uri = new Uri(uriString, UriKind.RelativeOrAbsolute);
if (!uri.IsAbsoluteUri)
{
// Placeholder
LogResult(pointer, nameof(RuleResources.SARIF1005_UriMustBeAbsolute_Error_Default_Text), uriString);
// {0}: Placeholder '{1}'
LogResult(
pointer,
nameof(RuleResources.SARIF1005_UriMustBeAbsolute_Error_Default_Text),
uriString);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class InvocationPropertiesMustBeConsistent : SarifValidationSkimmerBase
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF1006_InvocationPropertiesMustBeConsistent_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Error;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class RegionPropertiesMustBeConsistent : SarifValidationSkimmerBase
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF1007_RegionPropertiesMustBeConsistent_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Error;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public class PhysicalLocationPropertiesMustBeConsistent : SarifValidationSkimmer
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF1008_PhysicalLocationPropertiesMustBeConsistent_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Error;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class IndexPropertiesMustBeConsistentWithArrays : SarifValidationSkimmerB
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF1009_IndexPropertiesMustBeConsistentWithArrays_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Error;

Expand Down
33 changes: 21 additions & 12 deletions src/Sarif.Multitool/Rules/SARIF1010.RuleIdMustBeConsistent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules
{
public class RuleIdMustBeConsistent : SarifValidationSkimmerBase
{
public override MultiformatMessageString FullDescription => new MultiformatMessageString
{
Text = RuleResources.SARIF1010_RuleIdMustBeConsistent_FullDescription_Text
};

public override FailureLevel DefaultLevel => FailureLevel.Error;

/// <summary>
/// SARIF1010
/// </summary>
public override string Id => RuleId.RuleIdMustBeConsistent;

/// <summary>
/// Placeholder
/// </summary>
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF1010_RuleIdMustBeConsistent_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Error;

protected override void Analyze(Result result, string resultPointer)
{
AnalyzeRuleId(result, resultPointer);
Expand All @@ -33,14 +34,22 @@ private void AnalyzeRuleId(Result result, string pointer)
// At least one of result.ruleId or result.rule.id must be present
if (string.IsNullOrWhiteSpace(result.RuleId) && string.IsNullOrWhiteSpace(result.Rule?.Id))
{
LogResult(pointer, nameof(RuleResources.SARIF1010_RuleIdMustBeConsistent_Error_ResultMustSpecifyRuleId_Text));
// {0}: Placeholder
LogResult(
pointer,
nameof(RuleResources.SARIF1010_RuleIdMustBeConsistent_Error_ResultMustSpecifyRuleId_Text));
}
// if both are present, they must be equal.
else if (!string.IsNullOrWhiteSpace(result.RuleId)
&& !string.IsNullOrWhiteSpace(result.Rule?.Id)
&& !result.RuleId.Equals(result.Rule?.Id, StringComparison.OrdinalIgnoreCase))
{
LogResult(pointer, nameof(RuleResources.SARIF1010_RuleIdMustBeConsistent_Error_ResultRuleIdMustBeConsistent_Text), result.RuleId, result.Rule?.Id);
// {0}: Placeholder '{1}' '{2}' '{3}'
LogResult(
pointer,
nameof(RuleResources.SARIF1010_RuleIdMustBeConsistent_Error_ResultRuleIdMustBeConsistent_Text),
result.RuleId,
result.Rule?.Id);
}
}
}
Expand Down
33 changes: 20 additions & 13 deletions src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,36 @@

using System;
using System.Collections.Generic;

using Microsoft.Json.Pointer;

namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules
{
public class ReferenceFinalSchema : SarifValidationSkimmerBase
{
public override MultiformatMessageString FullDescription => new MultiformatMessageString
{
Text = RuleResources.SARIF1011_ReferenceFinalSchema_FullDescription_Text
};

public override FailureLevel DefaultLevel => FailureLevel.Error;

/// <summary>
/// SARIF1011
/// </summary>
public override string Id => RuleId.ReferenceFinalSchema;

protected override IEnumerable<string> MessageResourceNames => new string[]
{
/// <summary>
/// Placeholder
/// </summary>
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF1011_ReferenceFinalSchema_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Error;


protected override void Analyze(SarifLog log, string logPointer)
{
AnalyzeSchema(log.SchemaUri, logPointer);
AnalyzeSchema(log.SchemaUri, logPointer.AtProperty(SarifPropertyName.Schema));
Copy link

@ghost ghost Jun 30, 2020

Choose a reason for hiding this comment

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

AtProperty [](start = 52, length = 10)

Good catch! #ByDesign

}

private void AnalyzeSchema(Uri schemaUri, string pointer)
private void AnalyzeSchema(Uri schemaUri, string schema)
{
if (schemaUri == null)
{
Expand All @@ -41,8 +45,11 @@ private void AnalyzeSchema(Uri schemaUri, string pointer)
&& !schemaUri.OriginalString.EndsWith(VersionConstants.SchemaVersionAsPublishedToSchemaStoreOrg)
&& !schemaUri.OriginalString.EndsWith($"{VersionConstants.SchemaVersionAsPublishedToSchemaStoreOrg}.json"))
{
LogResult(pointer.AtProperty(SarifPropertyName.Schema), nameof(RuleResources.SARIF1011_ReferenceFinalSchema_Error_Default_Text), schemaUri.OriginalString);
return;
// {0}: Placeholder '{1}'
LogResult(
schema,
nameof(RuleResources.SARIF1011_ReferenceFinalSchema_Error_Default_Text),
schemaUri.OriginalString);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Sarif.Multitool/Rules/SARIF2004.OptimizeFileSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public class OptimizeFileSize : SarifValidationSkimmerBase
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF2004_OptimizeFileSize_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Warning;

Expand Down
8 changes: 4 additions & 4 deletions src/Sarif.Multitool/Rules/SARIF2005.ProvideToolProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public class ProvideToolProperties : SarifValidationSkimmerBase
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF2005_ProvideToolProperties_FullDescription_Text };

protected override IEnumerable<string> MessageResourceNames => new string[] {
nameof(RuleResources.SARIF2005_ProvideToolProperties_Warning_ProvideToolVersion_Text),
nameof(RuleResources.SARIF2005_ProvideToolProperties_Warning_ProvideConciseToolName_Text),
nameof(RuleResources.SARIF2005_ProvideToolProperties_Warning_UseNumericToolVersions_Text)
};
nameof(RuleResources.SARIF2005_ProvideToolProperties_Warning_ProvideToolVersion_Text),
nameof(RuleResources.SARIF2005_ProvideToolProperties_Warning_ProvideConciseToolName_Text),
nameof(RuleResources.SARIF2005_ProvideToolProperties_Warning_UseNumericToolVersions_Text)
};

public override FailureLevel DefaultLevel => FailureLevel.Warning;

Expand Down
7 changes: 5 additions & 2 deletions src/Sarif.Multitool/Rules/SARIF2006.UrisShouldBeReachable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ private void AnalyzeUri(string uriString, string pointer)
Uri uri = new Uri(uriString, UriKind.Absolute);
if (!IsUriReachable(uri.AbsoluteUri))
{
// Placeholder
LogResult(pointer, nameof(RuleResources.SARIF1005_UriMustBeAbsolute_Error_Default_Text), uriString);
// {0}: Placeholder '{1}'
LogResult(
pointer,
nameof(RuleResources.SARIF1005_UriMustBeAbsolute_Error_Default_Text),
uriString);
}
}
}
Expand Down
25 changes: 15 additions & 10 deletions src/Sarif.Multitool/Rules/SARIF2008.ProvideSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,30 @@ namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules
{
public class ProvideSchema : SarifValidationSkimmerBase
{
public override MultiformatMessageString FullDescription => new MultiformatMessageString
{
Text = RuleResources.SARIF2008_ProvideSchema_FullDescription_Text
};

public override FailureLevel DefaultLevel => FailureLevel.Warning;

/// <summary>
/// SARIF2008
/// </summary>
public override string Id => RuleId.ProvideSchema;

/// <summary>
/// Placeholder
/// </summary>
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF2008_ProvideSchema_FullDescription_Text };

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

public override FailureLevel DefaultLevel => FailureLevel.Warning;

protected override void Analyze(SarifLog log, string logPointer)
{
if (!Context.InputLogToken.HasProperty("$schema"))
{
LogResult(logPointer, nameof(RuleResources.SARIF2008_ProvideSchema_Warning_Default_Text));
// {0}: Placeholder
LogResult(
logPointer,
nameof(RuleResources.SARIF2008_ProvideSchema_Warning_Default_Text));
}
}
}
Expand Down