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

rule validation template file #1902

Merged
merged 7 commits into from
Jun 24, 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
140 changes: 140 additions & 0 deletions docs/ValidationRules/RULEID.RULEFRIENDLYNAME.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;

/*
* INSTRUCTIONS:
*
* - Replace `RULEID` with a valid value.
* It should start with a prefix "SARIF", followed by
* a 4 digit number which is the next sequential number available
* to use in ~\src\Sarif.Multitool\Rules\RuleId.cs file.
* Example:
* SARIF1023
*
* - Replace `RULEFRIENDLYNAME` with a valid value.
* RULEFRIENDLYNAME should concisely define the purpose of this rule.
* Use imperative language, like `UseAbsoluteUri`
Copy link
Contributor Author

@harleenkohli harleenkohli Jun 4, 2020

Choose a reason for hiding this comment

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

Use imperative language, like `UseAbsoluteUri [](start = 7, length = 46)

i changed the language here to be stricter. #Closed

Copy link

Choose a reason for hiding this comment

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

good.


In reply to: 435587873 [](ancestors = 435587873)

* instead of indicative language, like `UriIsNotAbsolute`.
* Examples:
* DoNotUseFriendlyNameAsRuleId
* ReferToFinalSchema
*
* - Rename this file as <RULEID>.<RULEFRIENDLYNAME>.cs.
*
* - Remove All INSTRUCTIONS after the changes have been made.
*/
namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules
{
public class RULEFRIENDLYNAME : SarifValidationSkimmerBase
{
private readonly MultiformatMessageString FullDescription = new MultiformatMessageString
{
/*
* INSTRUCTIONS:
* Add a new key-value pair in ~\src\Sarif.Multitool\Rules\RuleResources.resx.
*
* Key:
* RULEID_RULEFRIENDLYNAME
*
* Value:
* Provide a brief description with atleast two sentences, both ending in a period.
* The first sentence should be a short description of the rule.
* The second sentence must describe the utility/usage of the rule.
*
* Example:
* The $schema property should be present, and must refer to the final version
* of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.
*
* Notes:
* The first sentence will be used as a `ShortDescription` for this rule.
* All sentences together will be used as a `LongDescription` for this rule.
*/
Text = RuleResources.RULEID_RULEFRIENDLYNAME
};

/*
* INSTRUCTIONS:
* Decide the appropriate FailureLevel for this rule as appropriate.
* The following heuristics can be used to arrive at a decision:
*
* Error:
* In general, an `Error` should be reserved for rules which address
* a SARIF spec violation that cannot be expressed by the Schema.
* Example:
* SARIF1019.RuleIdMustBePresentAndConsistent
* Per spec, at least one of result.ruleId and result.rule.id must be present,
* and if both are present, they must be the same.
*
* Warning:
* In general, a `Warning` is a good practice which should be followed, but it
* does not violate the SARIF spec.
* Example:
* SARIF1021.DoNotUseFriendlyNameAsRuleId
*/
public override FailureLevel DefaultLevel => FailureLevel.Warning;

/*
Copy link

@ghost ghost Jun 4, 2020

Choose a reason for hiding this comment

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

Remove extra blank line. #Closed

* INSTRUCTIONS:
* Add a new property in ~\src\Sarif.Multitool\Rules\RuleId.cs with
Copy link

@ghost ghost Jun 4, 2020

Choose a reason for hiding this comment

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

~ [](start = 33, length = 1)

If you're going to use ~ to mean "repo root", then use it consistently. On 14, 37, and 102, you use it without the src component. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooh nice! thnk u


In reply to: 435562733 [](ancestors = 435562733)

Copy link

Choose a reason for hiding this comment

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

:-) Frankly I'd've preferred it the other way around, since ~ ("home directory") is IMO more plausible for repo root than for source root. But really, you don't need it: src\Sarif.Mutitool\Rules\RuleId.cs is fine.


In reply to: 435569225 [](ancestors = 435569225,435562733)

* the name as RULEFRIENDLYNAME and
* the value as RULEID.
*
* Example:
* public const string ReferToFinalSchema = "SARIF1020";
*/
public override string Id => RuleId.RULEFRIENDLYNAME;

protected override IEnumerable<string> MessageResourceNames => new string[]
{
/*
* INSTRUCTIONS:
* Each rule has one or more result message strings, each with symbolic name
* in PascalCase. Add at least one new key-value pair for user messages
* in ~\src\Sarif.Multitool\Rules\RuleResources.resx.
*
* Key:
* RULEID_USERMESSAGESYMBOLICNAME
*
* Value:
* Provide the default user message for this rule. It should be a dynamic string
* and always start with `{0}:`.
*
* Conditional user messages:
* If the rule requires more than one user messages to be defined, define each as a
* key-value pair in resx file. The keys should be named as: RULEID_SHORTDESCRIPTION
*
* Example:
*
* Key : SARIF1018_LacksTrailingSlash
* Value : {0}: The URI '{1}' belonging to the '{2}' element of
* run.originalUriBaseIds does not end with a slash.
*
* Notes:
* Provide a meaningful symbolic name for each message, even if there is only one
* in this rule. Do not use a generic name like "default" for a single message.
*/
Copy link

@ghost ghost Jun 4, 2020

Choose a reason for hiding this comment

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

  • [](start = 12, length = 1)
  • NOTE: Provide a meaningful symbolic name for each message, even if there is only one in this rule. Do not use a generic name like "default" for a single message. #Closed

nameof(RuleResources.RULEID_Default)
};

/*
* INSTRUCTIONS:
* Override the "Analyze" method for the SARIF property which needs analysis.
* Here is an example:
*/
protected override void Analyze(ReportingDescriptor reportingDescriptor, string reportingDescriptorPointer)
{
if (reportingDescriptor.Id != null &&
reportingDescriptor.Name != null &&
reportingDescriptor.Id.Equals(reportingDescriptor.Name, StringComparison.OrdinalIgnoreCase))
{
LogResult(
reportingDescriptorPointer,
nameof(RuleResources.SARIF1001_Default),
reportingDescriptor.Id);
}
}
}
}
3 changes: 3 additions & 0 deletions src/Sarif.Multitool/Rules/RuleId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ public static class RuleId
public const string InvalidUriInOriginalUriBaseIds = "SARIF1018";
public const string RuleIdMustBePresentAndConsistent = "SARIF1019";
public const string ReferToFinalSchema = "SARIF1020";

// TEMPLATE:
// public const string RULEFRIENDLYNAME = "RULEID";
}
}
16 changes: 16 additions & 0 deletions src/Sarif.Sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{6EEAC61E-A362-4C46-A9AD-00EDB74CFCF2}"
ProjectSection(SolutionItems) = preProject
..\docs\how-to.md = ..\docs\how-to.md
..\docs\json-map.md = ..\docs\json-map.md
..\docs\multitool-usage.md = ..\docs\multitool-usage.md
..\docs\query-mode.md = ..\docs\query-mode.md
..\docs\Rule reference page template.md = ..\docs\Rule reference page template.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ValidationRules", "ValidationRules", "{81910EAA-C010-4940-90E5-BF64DE64381C}"
ProjectSection(SolutionItems) = preProject
..\docs\ValidationRules\RULEID.RULEFRIENDLYNAME.cs = ..\docs\ValidationRules\RULEID.RULEFRIENDLYNAME.cs
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -306,6 +320,8 @@ Global
{9CEE4119-25C6-4331-8DB6-C53462DDEA47} = {BBDE0751-B8A3-4EA6-A3DF-3CE7BA41EA0F}
{90E0CA8D-0D63-4576-8E77-D9FD4D0D28BA} = {BBDE0751-B8A3-4EA6-A3DF-3CE7BA41EA0F}
{A2D43A0B-F2ED-42A5-A980-D6F4476FE455} = {7D46D6BE-C3CD-424C-9A20-245DE63A9C10}
{6EEAC61E-A362-4C46-A9AD-00EDB74CFCF2} = {BBDE0751-B8A3-4EA6-A3DF-3CE7BA41EA0F}
{81910EAA-C010-4940-90E5-BF64DE64381C} = {6EEAC61E-A362-4C46-A9AD-00EDB74CFCF2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9EFA21E3-70A0-467C-9D1F-D5AD0DC1C1E6}
Expand Down