-
Notifications
You must be signed in to change notification settings - Fork 93
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
Enable export rules in multitool #2052
Changes from 3 commits
70d2cad
853671d
4e4b888
fed3ca1
30ee353
0022c68
215b97b
ef6debd
eb5b3e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
using Microsoft.CodeAnalysis.Sarif.Driver; | ||
using Microsoft.CodeAnalysis.Sarif.Multitool.Rules; | ||
|
||
namespace Microsoft.CodeAnalysis.Sarif.Multitool | ||
{ | ||
public class ExportCommand : CommandBase | ||
{ | ||
private readonly IFileSystem _fileSystem; | ||
|
||
public ExportCommand() | ||
{ | ||
_fileSystem = new FileSystem(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Inject the file system into the constructor:
This makes it easier to unit test. #Closed |
||
} | ||
|
||
public int Run(ExportOptions options) | ||
{ | ||
try | ||
{ | ||
var list = CompositionUtilities.GetExports<SarifValidationSkimmerBase>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Let's call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good job discovering |
||
new Assembly[] { Assembly.GetExecutingAssembly() }).ToList(); | ||
|
||
var sb = new StringBuilder(); | ||
sb.AppendLine($"# Rules{Environment.NewLine}"); | ||
|
||
foreach (SarifValidationSkimmerBase rule in list) | ||
{ | ||
BuildRule(rule, sb); | ||
} | ||
|
||
_fileSystem.WriteAllText($"{options.OutputDirectoryPath}\\rules.md", sb.ToString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just |
||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex); | ||
return FAILURE; | ||
} | ||
|
||
return SUCCESS; | ||
} | ||
|
||
private void BuildRule(SarifValidationSkimmerBase rule, StringBuilder sb) | ||
{ | ||
sb.AppendLine($"## Rule `{rule.Id}.{rule.Name}`{Environment.NewLine}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There's a new property |
||
sb.AppendLine($"### Description{Environment.NewLine}"); | ||
sb.AppendLine($"{rule.FullDescription.Text}{Environment.NewLine}"); | ||
sb.AppendLine($"### Messages{Environment.NewLine}"); | ||
|
||
foreach (System.Collections.Generic.KeyValuePair<string, MultiformatMessageString> message in rule.MessageStrings) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
sb.AppendLine($"#### `{message.Key.Split('_').Last()}`: {rule.DefaultLevel}{Environment.NewLine}"); | ||
sb.AppendLine($"{message.Value.Text}{Environment.NewLine}"); | ||
} | ||
|
||
sb.AppendLine($"---{Environment.NewLine}"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using CommandLine; | ||
|
||
namespace Microsoft.CodeAnalysis.Sarif.Multitool | ||
{ | ||
[Verb("export", HelpText = "Export rules to md file.")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
`"Export the documentation for the validation rules to a Markdown file." #Closed |
||
public class ExportOptions | ||
{ | ||
[Option( | ||
'o', | ||
"output-directory", | ||
HelpText = "A directory to output the exported file.")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Let them specify the file name, not just the directory:
|
||
public string OutputDirectoryPath { get; internal set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ | |
[assembly: CLSCompliant(false)] | ||
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)] | ||
|
||
// This reference necessary for Multitool. | ||
[assembly: InternalsVisibleTo("Sarif.Multitool, PublicKey=0024000004800000940000000602000000240000525341310004000001000100433fbf156abe9718142bdbd48a440e779a1b708fd21486ee0ae536f4c548edf8a7185c1e3ac89ceef76c15b8cc2497906798779a59402f9b9e27281fb15e7111566cdc9a9f8326301d45320623c5222089cf4d0013f365ae729fb0a9c9d15138042825cd511a0f3d4887a7b92f4c2749f81b410813d297b73244cf64995effb1")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could you explain why you need this? What is the exact error you get if you don't provide it? #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since CompositionUtilities is internal, we need this In reply to: 481265173 [](ancestors = 481265173) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make If we kept it internal -- which I don't recommend -- I wouldn't put the In reply to: 481273990 [](ancestors = 481273990,481265173) |
||
|
||
// This reference necessary for the MOQ test engine. | ||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call this
ExportRuleDocumentation
. "Export" is such a generic term, you might be exporting anything. You could imagine anExportRules
command that creates a SARIF file containing the rule metadata. #Closed