From 0d451329fd2657c46ce54f7a48150d508e91dd7a Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 9 Jun 2021 18:46:57 -0700 Subject: [PATCH] Strict mode needs the variables initialized (#15657) --- eng/common/scripts/ChangeLog-Operations.ps1 | 12 +++++++----- eng/common/scripts/Update-ChangeLog.ps1 | 9 +++++---- eng/common/scripts/Verify-ChangeLog.ps1 | 3 ++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/eng/common/scripts/ChangeLog-Operations.ps1 b/eng/common/scripts/ChangeLog-Operations.ps1 index 98769dcd9eb0..96866ba8f210 100644 --- a/eng/common/scripts/ChangeLog-Operations.ps1 +++ b/eng/common/scripts/ChangeLog-Operations.ps1 @@ -37,12 +37,14 @@ function Get-ChangeLogEntriesFromContent { return $null } + $changelogEntry = $null + $sectionName = $null $changeLogEntries = [Ordered]@{} try { # walk the document, finding where the version specifiers are and creating lists foreach ($line in $changeLogContent) { if ($line -match $RELEASE_TITLE_REGEX) { - $changeLogEntry = [pscustomobject]@{ + $changeLogEntry = [pscustomobject]@{ ReleaseVersion = $matches["version"] ReleaseStatus = $matches["releaseStatus"] ReleaseTitle = "## {0} {1}" -f $matches["version"], $matches["releaseStatus"] @@ -72,8 +74,8 @@ function Get-ChangeLogEntriesFromContent { } } catch { - Write-Host "Error parsing Changelog." - Write-Host $_.Exception.Message + Write-Error "Error parsing Changelog." + Write-Error $_ } return $changeLogEntries } @@ -208,7 +210,7 @@ function New-ChangeLogEntry { return $null } - if (!$Content) { + if (!$Content) { $Content = @() $Content += "" $Content += "### Features Added" @@ -222,7 +224,7 @@ function New-ChangeLogEntry { $Content += "" } - $newChangeLogEntry = [pscustomobject]@{ + $newChangeLogEntry = [pscustomobject]@{ ReleaseVersion = $Version ReleaseStatus = $Status ReleaseTitle = "## $Version $Status" diff --git a/eng/common/scripts/Update-ChangeLog.ps1 b/eng/common/scripts/Update-ChangeLog.ps1 index e802ce6f0686..b4c07d597629 100644 --- a/eng/common/scripts/Update-ChangeLog.ps1 +++ b/eng/common/scripts/Update-ChangeLog.ps1 @@ -15,6 +15,7 @@ param ( [String]$ChangelogPath, [String]$ReleaseDate ) +Set-StrictMode -Version 3 . (Join-Path $PSScriptRoot common.ps1) @@ -39,11 +40,11 @@ if ($ReleaseDate) exit 1 } } -elseif ($Unreleased) +elseif ($Unreleased) { $ReleaseStatus = $CHANGELOG_UNRELEASED_STATUS } -else +else { $ReleaseStatus = "$(Get-Date -Format $CHANGELOG_DATE_FORMAT)" $ReleaseStatus = "($ReleaseStatus)" @@ -61,7 +62,7 @@ if ([string]::IsNullOrEmpty($ChangelogPath)) $ChangelogPath = $pkgProperties.ChangeLogPath } -if (!(Test-Path $ChangelogPath)) +if (!(Test-Path $ChangelogPath)) { LogError "Changelog path [$ChangelogPath] is invalid." exit 1 @@ -103,7 +104,7 @@ if ($LatestsSorted[0] -ne $Version) { LogWarning "Version [$Version] is older than the latestversion [$LatestVersion] in the changelog. Consider using a more recent version." } -if ($ReplaceLatestEntryTitle) +if ($ReplaceLatestEntryTitle) { $newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $ChangeLogEntries[$LatestVersion].ReleaseContent LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]" diff --git a/eng/common/scripts/Verify-ChangeLog.ps1 b/eng/common/scripts/Verify-ChangeLog.ps1 index e56994a30e83..9be30f09261c 100644 --- a/eng/common/scripts/Verify-ChangeLog.ps1 +++ b/eng/common/scripts/Verify-ChangeLog.ps1 @@ -6,11 +6,12 @@ param ( [string]$ServiceDirectory, [boolean]$ForRelease = $False ) +Set-StrictMode -Version 3 . (Join-Path $PSScriptRoot common.ps1) $validChangeLog = $false -if ($ChangeLogLocation -and $VersionString) +if ($ChangeLogLocation -and $VersionString) { $validChangeLog = Confirm-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString -ForRelease $ForRelease }