Skip to content

Commit

Permalink
Merge pull request #26 from andrewrdavidson/release-1.3.0
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
andrewrdavidson authored Jan 27, 2021
2 parents 7147c69 + 3f9ffe7 commit 34f7462
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 127 deletions.
6 changes: 3 additions & 3 deletions Build/Build.Properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"FileList": {
"PSQualityCheck": null,
"PSQualityCheck.Functions": [
"Checks\\HelpElementRules.psd1"
"Checks\\HelpRules.psd1"
]
},
"GUID": {
Expand All @@ -46,8 +46,8 @@
"pester-tests"
],
"Version": {
"PSQualityCheck": "1.2.1",
"PSQualityCheck.Functions": "1.2.1"
"PSQualityCheck": "1.3.0",
"PSQualityCheck.Functions": "1.3.0"
}
}
}
File renamed without changes.
14 changes: 9 additions & 5 deletions Checks/Script.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ param(
[string[]]$Source,

[parameter(Mandatory = $false)]
[string[]]$ScriptAnalyzerRulesPath
[string[]]$ScriptAnalyzerRulesPath,

[parameter(Mandatory = $false)]
[string]$HelpRulesPath

)

BeforeDiscovery {
Expand Down Expand Up @@ -40,7 +44,7 @@ BeforeDiscovery {

Describe "Script Tests" -Tag "Script" {

Context "Script: <File.Name> at <File.Directory>" -Foreach $scriptFiles {
Context "Script: <File.Name> at <File.Directory>" -ForEach $scriptFiles {

BeforeAll {

Expand Down Expand Up @@ -79,7 +83,7 @@ Describe "Script Tests" -Tag "Script" {
throw "No help block found"
}
$helpTokens = Convert-Help -Help $helpComments.Content
Test-RequiredToken -HelpTokens $helpTokens
Test-RequiredToken -HelpTokens $helpTokens -HelpRulesPath $HelpRulesPath

} |
Should -Not -Throw
Expand All @@ -95,7 +99,7 @@ Describe "Script Tests" -Tag "Script" {
throw "No help block found"
}
$helpTokens = Convert-Help -Help $helpComments.Content
Test-UnspecifiedToken -HelpTokens $helpTokens
Test-UnspecifiedToken -HelpTokens $helpTokens -HelpRulesPath $HelpRulesPath

} |
Should -Not -Throw
Expand Down Expand Up @@ -126,7 +130,7 @@ Describe "Script Tests" -Tag "Script" {
throw "No help block found"
}
$helpTokens = Convert-Help -Help $helpComments.Content
Test-HelpTokensCountIsValid -HelpTokens $helpTokens
Test-HelpTokensCountIsValid -HelpTokens $helpTokens -HelpRulesPath $HelpRulesPath

} | Should -Not -Throw

Expand Down
6 changes: 3 additions & 3 deletions PSQualityCheck.Functions.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Andrew Davidson
#
# Generated on: 23/01/2021
# Generated on: 27/01/2021
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'PSQualityCheck.Functions.psm1'

# Version number of this module.
ModuleVersion = '1.2.1'
ModuleVersion = '1.3.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -94,7 +94,7 @@ AliasesToExport = @()
# ModuleList = @()

# List of all files packaged with this module
FileList = 'Checks\HelpElementRules.psd1'
FileList = 'Checks\HelpRules.psd1'

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
Expand Down
78 changes: 24 additions & 54 deletions PSQualityCheck.Functions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -907,30 +907,20 @@ function Test-HelpTokensCountIsValid {
[OutputType([System.Exception], [System.Void])]
param (
[parameter(Mandatory = $true)]
[HashTable]$HelpTokens
[HashTable]$HelpTokens,

[parameter(Mandatory = $true)]
[string]$HelpRulesPath
)

try {

$module = Get-Module -Name PSQualityCheck

$helpElementRulesPath = (Join-Path -Path $module.ModuleBase -ChildPath "Checks\HelpElementRules.psd1")

if (Test-Path -Path $helpElementRulesPath) {

$helpElementRules = Import-PowerShellDataFile -Path $helpElementRulesPath

}
else {

throw "Unable to load Checks\HelpElementRules.psd1"

}
$helpRules = Import-PowerShellDataFile -Path $HelpRulesPath

# create a HashTable for tracking whether the element has been found
$tokenFound = @{}
for ($order = 1; $order -le $helpElementRules.Count; $order++) {
$token = $helpElementRules."$order".Key
for ($order = 1; $order -le $HelpRules.Count; $order++) {
$token = $HelpRules."$order".Key
$tokenFound[$token] = $false
}

Expand All @@ -940,9 +930,9 @@ function Test-HelpTokensCountIsValid {
foreach ($key in $HelpTokens.Keys) {

# loop through all the help element rules
for ($order = 1; $order -le $helpElementRules.Count; $order++) {
for ($order = 1; $order -le $HelpRules.Count; $order++) {

$token = $helpElementRules."$order"
$token = $HelpRules."$order"

# if the found token matches against a rule
if ( $token.Key -eq $key ) {
Expand Down Expand Up @@ -1281,31 +1271,21 @@ function Test-RequiredToken {
[OutputType([System.Exception], [System.Void])]
param (
[parameter(Mandatory = $true)]
[HashTable]$HelpTokens
[HashTable]$HelpTokens,

[parameter(Mandatory = $true)]
[string]$HelpRulesPath
)

try {

$module = Get-Module -Name PSQualityCheck

$helpElementRulesPath = (Join-Path -Path $module.ModuleBase -ChildPath "Checks\HelpElementRules.psd1")

if (Test-Path -Path $helpElementRulesPath) {

$helpElementRules = Import-PowerShellDataFile -Path $helpElementRulesPath

}
else {

throw "Unable to load Checks\HelpElementRules.psd1"

}
$helpRules = Import-PowerShellDataFile -Path $HelpRulesPath

$tokenErrors = @()

for ($order = 1; $order -le $helpElementRules.Count; $order++) {
for ($order = 1; $order -le $HelpRules.Count; $order++) {

$token = $helpElementRules."$order"
$token = $HelpRules."$order"

if ($token.Key -notin $HelpTokens.Keys ) {

Expand Down Expand Up @@ -1350,40 +1330,30 @@ function Test-UnspecifiedToken {
[OutputType([System.Exception], [System.Void])]
param (
[parameter(Mandatory = $true)]
[HashTable]$HelpTokens
[HashTable]$HelpTokens,

[parameter(Mandatory = $true)]
[string]$HelpRulesPath
)

try {

$module = Get-Module -Name PSQualityCheck

$helpElementRulesPath = (Join-Path -Path $module.ModuleBase -ChildPath "Checks\HelpElementRules.psd1")

if (Test-Path -Path $helpElementRulesPath) {

$helpElementRules = Import-PowerShellDataFile -Path $helpElementRulesPath

}
else {

throw "Unable to load Checks\HelpElementRules.psd1"

}
$helpRules = Import-PowerShellDataFile -Path $HelpRulesPath

$tokenErrors = @()
$helpTokensKeys = @()

# Create an array of the help element rules elements
for ($order = 1; $order -le $helpElementRules.Count; $order++) {
for ($order = 1; $order -le $helpRules.Count; $order++) {

$token = $helpElementRules."$order"
$token = $helpRules."$order"

$helpTokensKeys += $token.key

}

# search through the found tokens and match them against the rules
foreach ($key in $HelpTokens.Keys) {
foreach ($key in $helpTokens.Keys) {

if ( $key -notin $helpTokensKeys ) {

Expand Down
4 changes: 2 additions & 2 deletions PSQualityCheck.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Andrew Davidson
#
# Generated on: 23/01/2021
# Generated on: 27/01/2021
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'PSQualityCheck.psm1'

# Version number of this module.
ModuleVersion = '1.2.1'
ModuleVersion = '1.3.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
26 changes: 24 additions & 2 deletions PSQualityCheck.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function Invoke-PSQualityCheck {
.PARAMETER ProjectPath
A path to the root of a Project
.PARAMETER HelpRulesPath
A path to the HelpRules parameter file
.EXAMPLE
Invoke-PSQualityCheck -Path 'C:\Scripts'
Expand Down Expand Up @@ -130,7 +133,10 @@ function Invoke-PSQualityCheck {
[String[]]$Include,

[Parameter(Mandatory = $false)]
[String[]]$Exclude
[String[]]$Exclude,

[Parameter(Mandatory = $false)]
[String]$HelpRulesPath

)

Expand Down Expand Up @@ -159,6 +165,22 @@ function Invoke-PSQualityCheck {
$extractedScriptResults = $null
$scriptResults = $null

if ($PSBoundParameters.ContainsKey('HelpRulesPath')) {

if ( -not (Test-Path -Path $HelpRulesPath)) {

Write-Error "-HelpRulesPath does not exist"
break

}

}
else {

$helpRulesPath = (Join-Path -Path $modulePath -ChildPath "Checks\HelpRules.psd1")

}

if ($PSBoundParameters.ContainsKey('PesterConfiguration') -and $PesterConfiguration -is [PesterConfiguration]) {

# left here so that we can over-ride passed in object with values we require
Expand Down Expand Up @@ -364,7 +386,7 @@ function Invoke-PSQualityCheck {
$extractedScriptsToTest = Get-ChildItem -Path $extractPath -Include '*.ps1' -Recurse

# Run the Script tests against all the extracted functions .ps1 files
$container3 = New-PesterContainer -Path (Join-Path -Path $modulePath -ChildPath 'Checks\Script.Tests.ps1') -Data @{ Source = $extractedScriptsToTest; ScriptAnalyzerRulesPath = $ScriptAnalyzerRulesPath }
$container3 = New-PesterContainer -Path (Join-Path -Path $modulePath -ChildPath 'Checks\Script.Tests.ps1') -Data @{ Source = $extractedScriptsToTest; ScriptAnalyzerRulesPath = $ScriptAnalyzerRulesPath; HelpRulesPath = $HelpRulesPath }
$PesterConfiguration.Run.Container = $container3
$extractedScriptResults = Invoke-Pester -Configuration $PesterConfiguration
}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ For more information please see the wiki here [Wiki](https://github.com/andrewrd

#### Development

[![devtag](https://img.shields.io/badge/branch-1.3.0-blue)](https://github.com/andrewrdavidson/PSQualityCheck/tree/release-1.3.0)
[![commits since 1.2.1](https://img.shields.io/github/commits-since/andrewrdavidson/psqualitycheck/1.2.1/main?include_prereleases)](https://github.com/andrewrdavidson/PSQualityCheck/releases/1.2.1)
[![devtag](https://img.shields.io/badge/branch-1.4.0-blue)](https://github.com/andrewrdavidson/PSQualityCheck/tree/release-1.4.0)
[![commits since 1.3.0](https://img.shields.io/github/commits-since/andrewrdavidson/psqualitycheck/1.3.0/main?include_prereleases)](https://github.com/andrewrdavidson/PSQualityCheck/releases/1.3.0)

## Plans

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,20 @@ function Test-HelpTokensCountIsValid {
[OutputType([System.Exception], [System.Void])]
param (
[parameter(Mandatory = $true)]
[HashTable]$HelpTokens
[HashTable]$HelpTokens,

[parameter(Mandatory = $true)]
[string]$HelpRulesPath
)

try {

$module = Get-Module -Name PSQualityCheck

$helpElementRulesPath = (Join-Path -Path $module.ModuleBase -ChildPath "Checks\HelpElementRules.psd1")

if (Test-Path -Path $helpElementRulesPath) {

$helpElementRules = Import-PowerShellDataFile -Path $helpElementRulesPath

}
else {

throw "Unable to load Checks\HelpElementRules.psd1"

}
$helpRules = Import-PowerShellDataFile -Path $HelpRulesPath

# create a HashTable for tracking whether the element has been found
$tokenFound = @{}
for ($order = 1; $order -le $helpElementRules.Count; $order++) {
$token = $helpElementRules."$order".Key
for ($order = 1; $order -le $HelpRules.Count; $order++) {
$token = $HelpRules."$order".Key
$tokenFound[$token] = $false
}

Expand All @@ -52,9 +42,9 @@ function Test-HelpTokensCountIsValid {
foreach ($key in $HelpTokens.Keys) {

# loop through all the help element rules
for ($order = 1; $order -le $helpElementRules.Count; $order++) {
for ($order = 1; $order -le $HelpRules.Count; $order++) {

$token = $helpElementRules."$order"
$token = $HelpRules."$order"

# if the found token matches against a rule
if ( $token.Key -eq $key ) {
Expand Down
Loading

0 comments on commit 34f7462

Please sign in to comment.