55# The configuration should look like this:
66#
77# ### PSScriptAnalyzer Configuration
8- # ``` yaml
8+ # ```yaml
99# targetVersions:
1010# - "5.1"
1111# - "7.0"
1717function Read-ComplianceConfiguration {
1818 $path = " README.md"
1919 $configMarker = " ### PSScriptAnalyzer Configuration"
20- $backTicksYaml = ' ``` yaml'
20+ $backTicksYaml = ' ```yaml'
2121 $backTicks = ' ```'
2222
2323 $readme = Get-Content $path
@@ -41,8 +41,7 @@ function Read-ComplianceConfiguration {
4141 }
4242
4343 if (" " -eq $yaml ) {
44- Write-Error " No PSScriptAnalyzer Configuration found in README.md"
45- exit 2
44+ Throw " No PSScriptAnalyzer Configuration found in README.md"
4645 }
4746
4847 # Parse the YAML.
@@ -51,12 +50,10 @@ function Read-ComplianceConfiguration {
5150 # Confirm that there is at least one TargetVersion and that there are the
5251 # same number of TargetVersions as TargetProfiles.
5352 if ($yamlObj.targetVersions.Count -eq 0 ) {
54- Write-Error " No TargetVersions found in PSScriptAnalyzer Configuration."
55- exit 4
53+ Throw " No TargetVersions found in PSScriptAnalyzer Configuration."
5654 }
5755 if ($yamlObj.targetVersions.Count -ne $yamlObj.targetProfiles.Count ) {
58- Write-Error " Number of TargetVersions ($ ( $yamlObj.targetVersions.Count ) ) and TargetProfiles ($ ( $yamlObj.targetprofiles.Count ) ) do not match."
59- exit 6
56+ Throw " Number of TargetVersions ($ ( $yamlObj.targetVersions.Count ) ) and TargetProfiles ($ ( $yamlObj.targetprofiles.Count ) ) do not match."
6057 }
6158
6259 return $yamlObj
@@ -94,8 +91,7 @@ function Confirm-Compliance {
9491 $problems = $ (Get-ChildItem - Path ./ custom - Recurse - Include ' *.ps1' | Invoke-ScriptAnalyzer - Settings $settings )
9592 if (" " -ne $problems ) {
9693 Write-Output $problems
97- Write-Error ' ScriptAnalyzer found (possibly back-compatibility) issues.'
98- exit 5
94+ Throw ' ScriptAnalyzer found (possibly back-compatibility) issues.'
9995 }
10096}
10197
@@ -105,8 +101,7 @@ function Confirm-CustomScript {
105101 # Get all *.ps1 files in the current directory
106102 $scripts = Get-ChildItem - Path ./ custom - Recurse - Include ' *.ps1'
107103 if ($scripts.Length -eq 0 ) {
108- Write-Error " No custom scripts found in the repository."
109- exit 3
104+ Throw " No custom scripts found in the repository."
110105 }
111106}
112107
@@ -116,20 +111,17 @@ function Confirm-InAutorestEnv {
116111 # Get current working directory then confirm it ends in ".autorest"
117112 $cwd = Get-Location
118113 if ($cwd -notlike " *.autorest" ) {
119- Write-Error " This script should be run from an autorest directory."
120- exit 1
114+ Throw " This script should be run from an autorest directory."
121115 }
122116
123117}
124118
125119# Confirm that the required modules are installed.
126120if (-not (Get-InstalledModule - Name " powershell-yaml" )) {
127- Write-Error " powershell-yaml module is required. Please install it."
128- exit 7
121+ Throw " powershell-yaml module is required. Please install it."
129122}
130123if (-not (Get-InstalledModule - Name PSScriptAnalyzer)) {
131- Write-Error " PSScriptAnalyzer module is required. Please install it."
132- exit 7
124+ Throw " PSScriptAnalyzer module is required. Please install it."
133125}
134126
135127# Run the script.
0 commit comments