-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (46 loc) · 1.79 KB
/
Copy pathProgram.cs
File metadata and controls
53 lines (46 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Reflection;
using SACSharp.Rules;
using SACSharp.Core;
using SACSharp.Models;
class Program
{
static void Main(string[] args)
{
if (args.Length == 0 || args[0] != "scan" || args.Length < 2)
{
Console.WriteLine("Usage: sacsharp scan /path/to/project-directory");
return;
}
string path = args[1];
var csFiles = Directory.GetFiles(path, "*.cs", SearchOption.AllDirectories);
var ruleInterface = typeof(IRule);
var rules = Assembly.GetExecutingAssembly()
.GetTypes()
.Where(t => ruleInterface.IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface)
.Select(t => (IRule)Activator.CreateInstance(t)!)
.ToList();
foreach (var file in csFiles)
{
var findings = Scanner.ScanFile(file, rules);
foreach (var finding in findings)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write($"[{finding.RuleId}] ");
Console.ForegroundColor = finding.Severity switch
{
Severity.Low => ConsoleColor.White,
Severity.Medium => ConsoleColor.Yellow,
Severity.High => ConsoleColor.DarkYellow,
Severity.Critical => ConsoleColor.Red,
_ => ConsoleColor.Gray
};
Console.WriteLine(finding.Message);
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine($" -> {finding.FilePath}:{finding.LineNumber}");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($" Resolution: {finding.Resolution}");
Console.ResetColor();
}
}
}
}