Skip to content
Andrew Davidson edited this page Jan 4, 2021 · 17 revisions

PSQualityCheck

Summary

This is a PowerShell module which runs a series of Pester 5 tests to validate code quality. It uses a combination of Pester tests, PSScriptAnalyzer and a set of quality standards to ensure consistent quality on PowerShell scripts and modules.

Availability

The module is available on the PowerShell Gallery

Standards

The standards that these scripts are enforcing are detailed here: Standards

Rules

The rules that are tested are detailed here: Module Tests and here: Script Tests

Usage

Import the module

Import-Module -Name PSQualityCheck

Check the folder C:\Scripts and all subfolders beneath it:

Invoke-PSQualityCheck -Path 'C:\Scripts'

Check the folders C:\Scripts and C:\MoreScripts' and all subfolders beneath both folders:

Invoke-PSQualityCheck -Path @('C:\Scripts', 'C:\MoreScripts')

Check the file C:\Scripts\Script.ps1:

Invoke-PSQualityCheck -File 'C:\Scripts\Script.ps1'

Check the files C:\Scripts\Script1.ps1, C:\Scripts\Script2.ps1:

Invoke-PSQualityCheck -File @('C:\Scripts\Script.ps1', 'C:\Scripts\Script.ps1')

Check the file C:\Scripts\Script.ps1 including the extra PSScriptAnalyzer rules used by SonarQube:

Invoke-PSQualityCheck -File 'C:\Scripts\Script.ps1' -SonarQubeRulesPath 'C:\SonarQubeRules'

Check the folder C:\Scripts and all subfolders beneath it and display a summary of the checks performed:

Invoke-PSQualityCheck -Path 'C:\Scripts' -ShowCheckResults

output below uses sample data:

Test                            Files Tested Total Passed Failed Skipped
----                            ------------ ----- ------ ------ -------
Module Tests                               3    21     20      1       0
Extracting functions                       3     3      3      0       0
Extracted function script tests           13   195     64    114      17
Script Tests                              17   255     78    152      25
Total                                     33   474    165    267      42

Future Plans

The plan for the future of the module is detailed here: Release Plan

Clone this wiki locally