Skip to content

[Code Quality] bump-version.ps1 — Dead else branches in version-format logic #772

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Info

Location: bump-version.ps1:32-41

Code:

param(
    [Parameter(Mandatory = $true, Position = 0)]
    [ValidatePattern("^\d+\.\d+$")]
    [string]$Version
)

# -----------------------------
# Convert short version to full versions
# -----------------------------
$fullVersion = if ($Version -match "^\d+\.\d+$") { "$Version.0" } else { $Version }
$fileVersion = if ($Version -match "^\d+\.\d+$") { "$Version.0.0" } else { "$Version.0.0" }

Explanation:
[ValidatePattern("^\d+\.\d+$")] is applied to $Version, so by the time the body of the script executes, $Version is guaranteed to match that exact pattern. The if conditions therefore always evaluate to $true, and the else branches are unreachable.

The $fileVersion line is also a no-op conditional — both branches return the same string "$Version.0.0".

Suggested fix:

$fullVersion = "$Version.0"
$fileVersion = "$Version.0.0"

This simplifies the file and removes code that might mislead a future maintainer into thinking the script accepts three-part versions.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions