Skip to content

Commit 79492ca

Browse files
🩹 [Patch]: Refactor settings file path resolution logic for clarity and error handling
1 parent 36f7122 commit 79492ca

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

‎scripts/main.ps1‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ $testPath = Resolve-Path -Path "$PSScriptRoot/tests/PSScriptAnalyzer" | Select-O
33
$path = [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path) ? '.' : $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path
44
$codePath = Resolve-Path -Path $path | Select-Object -ExpandProperty Path
55

6-
# Try to resolve the settings file path, but allow it to be null if not found
7-
[string]$settingsFilePath = ''
8-
if (-not [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath)) {
9-
try {
10-
Write-Host "Looking for settings file under $($pwd.Path)"
11-
$settingsFilePath = (Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath -ErrorAction Stop).Path
12-
Write-Information "Using settings file: $settingsFilePath"
13-
} catch {
14-
Write-Warning "Settings file not found at path: $($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath). Using default settings."
15-
}
6+
Write-Host "Looking for settings file under $($pwd.Path)"
7+
$tmpSettingsFilePath = Join-Path -Path $pwd.Path -ChildPath $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath
8+
$settingsFileExists = Test-Path -Path $tmpSettingsFilePath
9+
if ($settingsFileExists) {
10+
$settingsFilePath = $tmpSettingsFilePath
11+
} else {
12+
$settingsFilePath = ''
1613
}
14+
Write-Warning "Settings file not found at path: $($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath). Using default settings."
1715

1816
[pscustomobject]@{
1917
CodePath = $codePath

0 commit comments

Comments
 (0)