-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummarise-warnings.ps1
94 lines (84 loc) · 2.75 KB
/
summarise-warnings.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)]
[string]$warningsFile
)
function ParseWarning($line)
{
$source, $warning, $description = $line -split ": ", 3
$description -match '(.*)\[(.*)\]' | Out-Null
$description = $Matches[1]
$project = $Matches[2]
$action = ""
if ($description -match '(.*) : (.*)') {
$action = $Matches[1]
$description = $Matches[2]
}
$warning = $warning -replace "warning "
@{
project = $project;
source = $source;
warning = $warning;
action = $action;
description = $description
}
}
function ParseWarnings($warningsfile)
{
Get-Content $warningsfile | % { ,(ParseWarning($_)) }
}
function SummariseByDescription($warnings, $prefix, [scriptblock]$subSummary = $null)
{
$groupedByDescription = @($warnings | group { $_['description'] })
if ($groupedByDescription.Count -eq 1) {
"$prefix{0,4} {1} {2}" -f $_.Count, $_.Name, $_.Group[0]['description']
if ($subSummary -ne $null) {
&$subSummary $_.Group "$prefix "
}
}
else {
"$prefix{0,4} {1}" -f $_.Count, $_.Name
if ($_.Name -notlike 'LGHT*') {
$groupedByDescription | sort -Descending { $_.Count } | % {
"$prefix {0,4} {1}" -f $_.Count, $_.Name
if ($subSummary -ne $null) {
&$subSummary $_.Group "$prefix "
}
}
}
}
}
function SummariseWarnings($warningsfile)
{
$warnings = ParseWarnings $warningsfile
"=== Warnings by project"
""
$warnings | group { $_['project'] } | sort -Descending { $_.Count } | % {
"{0,4} {1}" -f $_.Count, [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
$_.Group | group { $_['warning'] } | sort -Descending { $_.Count } | % {
SummariseByDescription $_.Group " "
}
}
""
"=== Warnings by type"
""
$warnings | group { $_['warning'] } | sort -Descending { $_.Count } | % {
SummariseByDescription $_.Group " " {
$warnings, $prefix = $args
$warnings | group { $_['project'] } | sort -Descending { $_.Count } | % {
"$prefix{0, 4} {1}" -f $_.Count, [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
}
}
}
""
"=== Warnings by file"
""
$warnings | group { $_['source'] -replace "\(.*\)", ""} | sort -Descending { $_.Count } | % {
"{0,4} {1}" -f $_.Count, $_.Name
$_.Group | group { $_['warning'] } | sort -Descending { $_.Count } | % {
SummariseByDescription $_.Group " "
}
}
""
}
SummariseWarnings($warningsFile)