Build/Analyze.ps1

Install-Module PSScriptAnalyzer -Force
$ProjectRoot = Split-Path $PSScriptRoot -Parent
$RulesExclusions = @('PSUseToExportFieldsInManifest',
    'PSAvoidGlobalVars',
    'PSAvoidUsingWriteHost',
    'PSUseOutputTypeCorrectly',
    'PSUseShouldProcessForStateChangingFunctions',
    'PSReviewUnusedParameter',
    'PSAvoidUsingConvertToSecureStringWithPlainText',
    'PSUseSingularNouns',
    'PSAvoidAssignmentToAutomaticVariable',
    'PSUseBOMForUnicodeEncodedFile')

$Violations = Invoke-ScriptAnalyzer -Path $ProjectRoot -Recurse -ExcludeRule $RulesExclusions
if ($Violations) {
    $Violations
    Write-Error -Message 'PSScriptAnalyzer violations found, please correct them before merging.' -ErrorAction Stop
}