-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite VerifyResourceUsage in powershell Co-authored-by: Keegan Caruso <[email protected]>
- Loading branch information
1 parent
9f61d7b
commit 5f437df
Showing
5 changed files
with
57 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
$folderPath = $PSScriptRoot + "/../src" | ||
|
||
# Get LogMessages C# files | ||
$files = Get-ChildItem -Path $folderPath -Filter LogMessages.cs -Recurse | ||
|
||
# Dictionary to hold constants and their usage status | ||
$constants = @{} | ||
|
||
# Extract constants | ||
foreach ($file in $files) { | ||
$content = Get-Content -Path $file.FullName | ||
foreach ($line in $content) { | ||
if (($line -match 'const\s+\w+\s+(\w+)\s*=') -and !($line.Contains("//"))) { | ||
$constantName = $matches[1] | ||
$constants[$constantName] = [PSCustomObject]@{ | ||
File = $file.FullName | ||
ConstantName = $constantName | ||
Found = $false | ||
} | ||
} | ||
} | ||
} | ||
|
||
$files = Get-ChildItem -Path $folderPath -Filter *.cs -Exclude LogMessages.cs -Recurse | ||
$keys = @($constants.Keys) | ||
|
||
# Check for usage | ||
foreach ($file in $files) { | ||
$content = Get-Content -Path $file.FullName | ||
foreach ($constantName in $keys) { | ||
if (Select-String -InputObject $content -Pattern $constantName) { | ||
$constants[$constantName].Found = $true | ||
} | ||
} | ||
} | ||
|
||
# Output unused constants | ||
$unusedConstants = $constants.GetEnumerator() | Where-Object { $_.Value.Found -eq $false } | ||
if ($unusedConstants.Count -eq 0) { | ||
Write-Output "No unused constants found." | ||
} else { | ||
Write-Output "Unused constants:" | ||
foreach ($unused in $unusedConstants) { | ||
$constName = $unused.Value.ConstantName | ||
$filePath = $unused.Value.File | ||
$message = "'$constName' in file '$filePath'" | ||
Write-Output $message | ||
} | ||
|
||
throw "found unused constants" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.