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

Provide messages for SARIF2011.ProvideContextRegion. #1980

Merged
2 commits merged into from
Jul 4, 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: 6 additions & 2 deletions docs/Producing effective SARIF.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,22 +500,26 @@ for example, 'CS2001' for a diagnostic from the Roslyn C# compiler. For uniformi

#### Description

Provide code snippets to enable users to see the source code that triggered the result, even if they are not enlisted in the code.
Provide code snippets to enable users to see the code that triggered each result, even if they are not enlisted in the code.

#### Messages

##### `Default`: note

The 'region' object in this result location does not include a 'snippet' property. Providing code snippets enables users to see the source code that triggered the result, even if they are not enlisted in the code.
{0}: The 'region' object in this result location does not provide a 'snippet' property. Providing a code snippet enables users to see the source code that triggered the result, even if they are not enlisted in the code.

---

### Rule `SARIF2011.ProvideContextRegion`

#### Description

Provide context regions to enable users to see a portion of the code that surrounds each result, even if they are not enlisted in the code.

##### `Default`: note

{0}: This result location does not provide a 'contextRegion' property. Providing a context region enables users to see a portion of the code that surrounds the result, even if they are not enlisted in the code.

---

### Rule `SARIF2012.ProvideHelpUris`
Expand Down
Binary file modified docs/Rule factoring.xlsx
Binary file not shown.
8 changes: 4 additions & 4 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.

8 changes: 4 additions & 4 deletions src/Sarif.Multitool/Rules/RuleResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,16 @@ Each element of the 'versionControlProvenance' array is a 'versionControlDetails
<value>{0}: The 'versionControlDetails' object that describes the repository '{1}' does not provide 'mappedTo.uriBaseId'. As a result, it will not be possible to determine the repo-relative location of files containing analysis results for this repository.</value>
</data>
<data name="SARIF2010_ProvideCodeSnippets_FullDescription_Text" xml:space="preserve">
<value>Provide code snippets to enable users to see the source code that triggered the result, even if they are not enlisted in the code.</value>
<value>Provide code snippets to enable users to see the code that triggered each result, even if they are not enlisted in the code.</value>
</data>
<data name="SARIF2010_ProvideCodeSnippets_Note_Default_Text" xml:space="preserve">
<value>{0}: The 'region' object in this result location does not include a 'snippet' property. Providing code snippets enables users to see the source code that triggered the result, even if they are not enlisted in the code.</value>
<value>{0}: The 'region' object in this result location does not provide a 'snippet' property. Providing a code snippet enables users to see the code that triggered the result, even if they are not enlisted in the code.</value>
</data>
<data name="SARIF2011_ProvideContextRegion_FullDescription_Text" xml:space="preserve">
<value>Placeholder_SARIF2011_ProvideContextRegion_FullDescription_Text</value>
<value>Provide context regions to enable users to see a portion of the code that surrounds each result, even if they are not enlisted in the code.</value>
</data>
<data name="SARIF2011_ProvideContextRegion_Note_Default_Text" xml:space="preserve">
<value>{0}: Placeholder</value>
<value>{0}: This result location does not provide a 'contextRegion' property. Providing a context region enables users to see a portion of the code that surrounds the result, even if they are not enlisted in the code.</value>
</data>
<data name="SARIF1012_MessageArgumentsMustBeConsistentWithRule_Error_MessageIdMustExist_Text" xml:space="preserve">
<value>{0}: This message object refers to the message with id '{1}' in rule '{2}', but that rule does not define a message with that id. When a tool creates a result message that uses the 'id' property, it must ensure that the specified rule actually has a message with that id.</value>
Expand Down
6 changes: 3 additions & 3 deletions src/Sarif.Multitool/Rules/SARIF2010.ProvideCodeSnippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ProvideCodeSnippets : SarifValidationSkimmerBase
public override string Id => RuleId.ProvideCodeSnippets;

/// <summary>
/// Provide code snippets to enable users to see the source code that triggered the result,
/// Provide code snippets to enable users to see the code that triggered each result,
/// even if they are not enlisted in the code.
/// </summary>
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF2010_ProvideCodeSnippets_FullDescription_Text };
Expand Down Expand Up @@ -57,8 +57,8 @@ private void AnalyzeRegion(Region region, string regionPointer)
{
if (region != null && region.Snippet == null)
{
// {0}: The 'region' object in this result location does not include a 'snippet'
// property. Providing code snippets enables users to see the source code that
// {0}: The 'region' object in this result location does not provide a 'snippet'
// property. Providing a code snippet enables users to see the source code that
// triggered the result, even if they are not enlisted in the code.
LogResult(
regionPointer,
Expand Down
7 changes: 5 additions & 2 deletions src/Sarif.Multitool/Rules/SARIF2011.ProvideContextRegion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ProvideContextRegion : SarifValidationSkimmerBase
public override string Id => RuleId.ProvideContextRegion;

/// <summary>
/// Placeholder
/// Provide context regions to enable users to see a portion of the code that surrounds
/// each result, even if they are not enlisted in the code.
/// </summary>
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF2011_ProvideContextRegion_FullDescription_Text };

Expand Down Expand Up @@ -45,7 +46,9 @@ private void AnalyzeLocation(Location location, string locationPointer)
{
string physicalLocationPointer = locationPointer.AtProperty(SarifPropertyName.PhysicalLocation);

// {0}: Placeholder
// {0}: This result location does not provide a 'contextRegion' property. Providing
// a context region enables users to see a portion of the code that surrounds the
// result, even if they are not enlisted in the code.
LogResult(
physicalLocationPointer,
nameof(RuleResources.SARIF2011_ProvideContextRegion_Note_Default_Text));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void SARIF2010_ProvideCodeSnippets_Valid()
public void SARIF2010_ProvideCodeSnippets_Invalid()
=> RunTest(
MakeInvalidTestFileName(RuleId.ProvideCodeSnippets, nameof(RuleId.ProvideCodeSnippets)),
parameter: new TestParameters(verbose: true));
parameter: new TestParameters(verbose: true, configFileName: "disable2011.configuration.xml"));

[Fact]
public void SARIF2011_ProvideContextRegion_Valid()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@
<None Update="default.configuration.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="disable2011.configuration.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="enable2002.configuration.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,14 @@
"id": "SARIF2010",
"name": "ProvideCodeSnippets",
"shortDescription": {
"text": "Provide code snippets to enable users to see the source code that triggered the result, even if they are not enlisted in the code."
"text": "Provide code snippets to enable users to see the code that triggered each result, even if they are not enlisted in the code."
},
"fullDescription": {
"text": "Provide code snippets to enable users to see the source code that triggered the result, even if they are not enlisted in the code."
"text": "Provide code snippets to enable users to see the code that triggered each result, even if they are not enlisted in the code."
},
"messageStrings": {
"Note_Default": {
"text": "{0}: The 'region' object in this result location does not include a 'snippet' property. Providing code snippets enables users to see the source code that triggered the result, even if they are not enlisted in the code."
}
},
"helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html"
},
{
"id": "SARIF2011",
"name": "ProvideContextRegion",
"shortDescription": {
"text": "Placeholder_SARIF2011_ProvideContextRegion_FullDescription_Text."
},
"fullDescription": {
"text": "Placeholder_SARIF2011_ProvideContextRegion_FullDescription_Text"
},
"messageStrings": {
"Note_Default": {
"text": "{0}: Placeholder"
"text": "{0}: The 'region' object in this result location does not provide a 'snippet' property. Providing a code snippet enables users to see the code that triggered the result, even if they are not enlisted in the code."
}
},
"helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html"
Expand Down Expand Up @@ -68,6 +52,14 @@
"descriptor": {
"id": "WRN999.RuleExplicitlyDisabled"
}
},
{
"message": {
"text": "Rule 'SARIF2011' was explicitly disabled by the user. As result, this tool run cannot be used for compliance or other auditing processes that require a comprehensive analysis."
},
"descriptor": {
"id": "WRN999.RuleExplicitlyDisabled"
}
}
],
"executionSuccessful": true
Expand Down Expand Up @@ -201,30 +193,6 @@
}
}
]
},
{
"ruleId": "SARIF2011",
"ruleIndex": 1,
"level": "note",
"message": {
"id": "Note_Default",
"arguments": [
"runs[0].results[3].locations[0].physicalLocation"
]
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"index": 0
},
"region": {
"startLine": 101,
"startColumn": 35
}
}
}
]
}
],
"columnKind": "utf16CodeUnits"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"id": "SARIF2011",
"name": "ProvideContextRegion",
"shortDescription": {
"text": "Placeholder_SARIF2011_ProvideContextRegion_FullDescription_Text."
"text": "Provide context regions to enable users to see a portion of the code that surrounds each result, even if they are not enlisted in the code."
},
"fullDescription": {
"text": "Placeholder_SARIF2011_ProvideContextRegion_FullDescription_Text"
"text": "Provide context regions to enable users to see a portion of the code that surrounds each result, even if they are not enlisted in the code."
},
"messageStrings": {
"Note_Default": {
"text": "{0}: Placeholder"
"text": "{0}: This result location does not provide a 'contextRegion' property. Providing a context region enables users to see a portion of the code that surrounds the result, even if they are not enlisted in the code."
}
},
"helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html"
Expand Down
18 changes: 18 additions & 0 deletions src/Test.FunctionalTests.Sarif/disable2011.configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
This file contains the default rule configurations for the functional tests of the SARIF validator rule.
-->
<Properties>
<Properties Key="SARIF2002.ProvideMessageArguments.Options">
<Property Key="RuleEnabled" Value="Disabled" />
</Properties>
<Properties Key="SARIF2006.UrisShouldBeReachable.Options">
<Property Key="RuleEnabled" Value="Disabled" />
</Properties>
<Properties Key="SARIF2007.ExpressPathsRelativeToRepoRoot.Options">
<Property Key="RuleEnabled" Value="Disabled" />
</Properties>
<Properties Key="SARIF2011.ProvideContextRegion.Options">
<Property Key="RuleEnabled" Value="Disabled" />
</Properties>
</Properties>