-
Notifications
You must be signed in to change notification settings - Fork 107
/
verify_stylecode.ps1
60 lines (49 loc) · 1.72 KB
/
verify_stylecode.ps1
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
54
55
56
57
58
59
60
Param(
[int] $level = 1,
[string] $output,
[string] $projects = "ScriptEngine;oscript;ScriptEngine.HostedScript;TestApp"
)
$InspectCodeToolPath = "JetBrains.ReSharper.CommandLineTools\inspectcode.exe"
$categories = @("CodeStyleIssues", "ConstraintViolation")
$levels = @{
"SUGGESTION" = 1;
"WARNING" = 2;
"ERROR" = 3;
}
$logFile = "codestyle.log"
& "$($InspectCodeToolPath)" --toolset=12.0 --output=$logFile --project="$($projects)" src\1Script.sln | Out-Null
Write-Host "Analysis Completed" -Foreground Green
# Parse report
[xml] $reportXml = Get-Content $logFile
$report = $reportXml.Report
$codeStyleIssueTypes = @{}
foreach ($issueType in $report.IssueTypes.IssueType) {
if (-not ($categories -contains $issueType.CategoryId)) {
continue
}
$codeStyleIssueTypes.Add($issueType.Id, $issueType)
}
foreach ($project in $report.Issues.Project) {
foreach ($issue in $project.Issue) {
if (-not $codeStyleIssueTypes.ContainsKey($issue.TypeId)) {
continue
}
$type = $codeStyleIssueTypes[$issue.TypeId]
if ($levels[$type.Severity] -lt $level) {
continue
}
$message = "[$($type.Severity)] $($issue.File):$($issue.Line) `"$($issue.Message)`""
$color = "White"
switch ($levels[$type.Severity]) {
1 { $color = "Green" }
2 { $color = "Yellow" }
3 { $color = "Red" }
}
if (-not [string]::IsNullOrEmpty($output)) {
$message | Out-File $output -Append
}
else {
Write-Host $message -Foreground $color
}
}
}