Skip to content

Commit 55b5fad

Browse files
committed
scripts to check rules
1 parent 9a2090a commit 55b5fad

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function Get-RulesFromCSV {
2+
param(
3+
[ValidateSet('c', 'cpp', 'all')]
4+
[string]
5+
$Language = 'all')
6+
7+
8+
$csvFile = (Join-Path (Get-RepositoryRoot) "rules.csv")
9+
10+
Write-Host "Loading rules for language=$Language from file $csvFile..."
11+
12+
$csv = Import-Csv $csvFile
13+
$filteredCSV = @()
14+
# don't filter if not neeeded
15+
if ($Language -eq 'all'){
16+
$filteredCSV = $csv
17+
}else{
18+
foreach($rule in $csv){
19+
if($rule.Language -eq $Language){
20+
$filteredCSV += $rule
21+
}
22+
}
23+
}
24+
25+
Write-Host "Loaded $($filteredCSV.Length) rules."
26+
27+
return $csv
28+
29+
}

scripts/util/Get-DuplicateRules.ps1

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env pwsh
2+
param(
3+
[ValidateSet('c', 'cpp', 'all')]
4+
[string]
5+
$Language = 'all',
6+
[switch]
7+
$CIMode
8+
9+
)
10+
11+
Import-Module -Name "$PSScriptRoot\..\PSCodingStandards\CodingStandards"
12+
13+
# load the rules.
14+
$rules = Get-RulesFromCSV -Language $Language
15+
16+
# find out duplicates
17+
$counter = @{}
18+
19+
foreach($rule in $rules){
20+
if($counter.Contains($rule.ID)){
21+
$counter[$rule.ID] += $rule
22+
}else{
23+
$counter[$rule.ID] = @()
24+
$counter[$rule.ID] += $rule
25+
}
26+
}
27+
28+
$duplicates = @()
29+
$numDuplicates = 0
30+
31+
foreach($k in $counter.Keys){
32+
if($counter[$k].Count -gt 1){
33+
$numDuplicates = $numDuplicates + 1
34+
foreach($v in $counter[$k]){
35+
$duplicates += $v
36+
}
37+
}
38+
}
39+
40+
$duplicates | Format-Table
41+
42+
if(($CIMode) -and ($numDuplicates -gt 0)){
43+
throw "Found $numDuplicates duplicate Rule IDs"
44+
}else{
45+
Write-Host "Found $numDuplicates duplicate Rule IDs"
46+
}

0 commit comments

Comments
 (0)