Skip to content

Commit

Permalink
🪲 [Fix]: Fix skip when multiple skips are found (#86)
Browse files Browse the repository at this point in the history
## Description

- Fix skip when multiple skips are found

## Type of change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] 📖 [Docs]
- [x] 🪲 [Fix]
- [ ] 🩹 [Patch]
- [ ] ⚠️ [Security fix]
- [ ] 🚀 [Feature]
- [ ] 🌟 [Breaking change]

## Checklist

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
  • Loading branch information
MariusStorhaug authored Dec 21, 2024
1 parent fe8b2bf commit 14d8042
Showing 1 changed file with 65 additions and 65 deletions.
130 changes: 65 additions & 65 deletions scripts/tests/PSModule/SourceCode.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ Describe 'PSModule - SourceCode tests' {
if ($skipTest.Matches.Count -gt 0) {
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping NumberOfProcessors test'
continue
} else {
$issues += " - $($_.Path):L$($_.LineNumber)"
}
$issues += " - $($_.Path):L$($_.LineNumber)"
}
}
$issues -join [Environment]::NewLine |
Expand All @@ -128,10 +128,10 @@ Describe 'PSModule - SourceCode tests' {
if ($skipTest.Matches.Count -gt 0) {
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping Verbose test'
continue
}
Select-String -Path $filePath -Pattern '\s(-Verbose(?::\$true)?)\b(?!:\$false)' -AllMatches | ForEach-Object {
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
} else {
Select-String -Path $filePath -Pattern '\s(-Verbose(?::\$true)?)\b(?!:\$false)' -AllMatches | ForEach-Object {
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
}
}
}
$issues -join [Environment]::NewLine |
Expand All @@ -146,10 +146,10 @@ Describe 'PSModule - SourceCode tests' {
if ($skipTest.Matches.Count -gt 0) {
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping OutNull test'
continue
}
Select-String -Path $filePath -Pattern 'Out-Null' -AllMatches | ForEach-Object {
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
} else {
Select-String -Path $filePath -Pattern 'Out-Null' -AllMatches | ForEach-Object {
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
}
}
}
$issues -join [Environment]::NewLine |
Expand All @@ -164,10 +164,10 @@ Describe 'PSModule - SourceCode tests' {
if ($skipTest.Matches.Count -gt 0) {
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping NoTernary test'
continue
}
Select-String -Path $filePath -Pattern '(?<!\|)\s+\?\s' -AllMatches | ForEach-Object {
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
} else {
Select-String -Path $filePath -Pattern '(?<!\|)\s+\?\s' -AllMatches | ForEach-Object {
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
}
}
}
$issues -join [Environment]::NewLine |
Expand All @@ -182,18 +182,18 @@ Describe 'PSModule - SourceCode tests' {
if ($skipTest.Matches.Count -gt 0) {
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping LowercaseKeywords test'
continue
}
$errors = $null
$tokens = $null
[System.Management.Automation.Language.Parser]::ParseFile($FilePath, [ref]$tokens, [ref]$errors)
} else {
$errors = $null
$tokens = $null
[System.Management.Automation.Language.Parser]::ParseFile($FilePath, [ref]$tokens, [ref]$errors)

foreach ($token in $tokens) {
$keyword = $token.Text
$lineNumber = $token.Extent.StartLineNumber
$columnNumber = $token.Extent.StartColumnNumber
if (($token.TokenFlags -match 'Keyword') -and ($keyword -cne $keyword.ToLower())) {
$issues += " - $relativePath`:L$lineNumber`:C$columnNumber - $keyword"
foreach ($token in $tokens) {
$keyword = $token.Text
$lineNumber = $token.Extent.StartLineNumber
$columnNumber = $token.Extent.StartColumnNumber
if (($token.TokenFlags -match 'Keyword') -and ($keyword -cne $keyword.ToLower())) {
$issues += " - $relativePath`:L$lineNumber`:C$columnNumber - $keyword"
}
}
}
}
Expand Down Expand Up @@ -238,12 +238,12 @@ Describe 'PSModule - SourceCode tests' {
if ($skipTest.Matches.Count -gt 0) {
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping FunctionCount test'
continue
}
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
if ($tokens.count -ne 1) {
$issues += " - $relativePath - $($tokens.Name)"
} else {
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
if ($tokens.count -ne 1) {
$issues += " - $relativePath - $($tokens.Name)"
}
}
}
$issues -join [Environment]::NewLine |
Expand All @@ -259,12 +259,12 @@ Describe 'PSModule - SourceCode tests' {
if ($skipTest.Matches.Count -gt 0) {
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping FunctionName test'
continue
}
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
if ($tokens.Name -ne $fileName) {
$issues += " - $relativePath - $($tokens.Name)"
} else {
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
if ($tokens.Name -ne $fileName) {
$issues += " - $relativePath - $($tokens.Name)"
}
}
}
$issues -join [Environment]::NewLine |
Expand All @@ -280,17 +280,17 @@ Describe 'PSModule - SourceCode tests' {
if ($skipTest.Matches.Count -gt 0) {
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping CmdletBinding test'
continue
}
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
$tokens = $scriptAst.FindAll({ $true }, $true)
foreach ($token in $tokens) {
if ($token.TypeName.Name -eq 'CmdletBinding') {
$found = $true
} else {
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
$tokens = $scriptAst.FindAll({ $true }, $true)
foreach ($token in $tokens) {
if ($token.TypeName.Name -eq 'CmdletBinding') {
$found = $true
}
}
if (-not $found) {
$issues += " - $relativePath"
}
}
if (-not $found) {
$issues += " - $relativePath"
}
}
$issues -join [Environment]::NewLine |
Expand All @@ -306,17 +306,17 @@ Describe 'PSModule - SourceCode tests' {
if ($skipTest.Matches.Count -gt 0) {
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping ParamBlock test'
continue
}
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
$tokens = $scriptAst.FindAll({ $args[0] -is [System.Management.Automation.Language.ParamBlockAst] }, $true)
foreach ($token in $tokens) {
if ($token.count -eq 1) {
$found = $true
} else {
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
$tokens = $scriptAst.FindAll({ $args[0] -is [System.Management.Automation.Language.ParamBlockAst] }, $true)
foreach ($token in $tokens) {
if ($token.count -eq 1) {
$found = $true
}
}
if (-not $found) {
$issues += " - $relativePath"
}
}
if (-not $found) {
$issues += " - $relativePath"
}
}
$issues -join [Environment]::NewLine |
Expand Down Expand Up @@ -358,14 +358,14 @@ Describe 'PSModule - SourceCode tests' {
if ($skipTest.Matches.Count -gt 0) {
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping FunctionTest test'
continue
}
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
$functionName = $tokens.Name
# If the file contains a function and the function name is not in the test files, add it as an issue.
if ($functionName.count -eq 1 -and $functionsInTestFiles -notcontains $functionName) {
$issues += " - $relativePath - $functionName"
} else {
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
$functionName = $tokens.Name
# If the file contains a function and the function name is not in the test files, add it as an issue.
if ($functionName.count -eq 1 -and $functionsInTestFiles -notcontains $functionName) {
$issues += " - $relativePath - $functionName"
}
}
}
$issues -join [Environment]::NewLine |
Expand Down

0 comments on commit 14d8042

Please sign in to comment.