Skip to content

style: replace IsNullOrEmpty guard with ValidateNotNullOrEmpty in Split-SemVerString#7

Merged
tablackburn merged 1 commit into
mainfrom
style/remove-redundant-isnullorempty-guard
May 10, 2026
Merged

style: replace IsNullOrEmpty guard with ValidateNotNullOrEmpty in Split-SemVerString#7
tablackburn merged 1 commit into
mainfrom
style/remove-redundant-isnullorempty-guard

Conversation

@tablackburn
Copy link
Copy Markdown
Owner

Summary

Syncs the same cleanup landed in PowerShellModuleTemplate PR #23 (specifically commit abf5d46) into JsmOperations.

Split-SemVerString in tests/ManifestHelpers.psm1 currently has a runtime [string]::IsNullOrEmpty($VersionString) check + throw. Switching $VersionString to [ValidateNotNullOrEmpty()] enforces the contract at parameter-bind time, so the runtime guard becomes redundant.

What changed

  • tests/ManifestHelpers.psm1 — added [ValidateNotNullOrEmpty()] to $VersionString; removed the if ([string]::IsNullOrEmpty(...)) if-block.

Atomic single edit: validator added and guard removed in the same commit so the function never passes through the transient dead-code state (validator + guard both present) that Copilot and CodeRabbit flagged on the template PR.

Why this is its own PR

Out of scope for feature/v0.1.0-mvp (#2 — release PR; merge auto-publishes to PowerShell Gallery). Style sync items shouldn't ride a release commit.

Verification

  • Diff is minimal: 1 line added (attribute), 4 lines removed (guard block).
  • Behavior is unchanged for valid input. For invalid input ($null / ''), the failure mode shifts from a runtime exception inside the function to a parameter-binding error — both halt execution; the bind-time error is more idiomatic and self-documenting.

Out of scope

Other consumer repos (YouTubeMusicPS, SrrDBAutomationToolkit, ScheduledTasksManager, PlexAutomationToolkit, ReScenePS) don't have tests/ManifestHelpers.psm1 at all — JsmOperations is the only consumer affected.

🤖 Generated with Claude Code

Syncs the same cleanup landed in PowerShellModuleTemplate PR #23
(commit abf5d46). The runtime IsNullOrEmpty check + throw on
$VersionString is fail-at-bind-time material — switching to
[ValidateNotNullOrEmpty()] makes the contract self-documenting and
removes the redundant guard.

Atomic single edit: add validator and remove guard together so the
function never goes through a transient dead-code state where both
exist (which is what Copilot and CodeRabbit caught on the template PR).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 10, 2026 06:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns Split-SemVerString’s parameter validation with the pattern used elsewhere in the repo by enforcing non-null/non-empty input at parameter-binding time instead of via an explicit runtime guard.

Changes:

  • Added [ValidateNotNullOrEmpty()] to Split-SemVerString’s $VersionString parameter.
  • Removed the redundant [string]::IsNullOrEmpty(...) + throw guard block.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tablackburn tablackburn merged commit 887e7bb into main May 10, 2026
14 checks passed
@tablackburn tablackburn deleted the style/remove-redundant-isnullorempty-guard branch May 10, 2026 06:29
tablackburn added a commit that referenced this pull request May 12, 2026
… params (#8)

Completes the cross-repo validator alignment with PowerShellModuleTemplate#23.
PR #7 (2026-05-10) added the validator to `Split-SemVerString -VersionString`;
this commit covers the remaining six mandatory `[string]` parameters across
`Compare-SemVerPrerelease`, `Test-VersionComparison`, and `Test-VersionConstraint`.

Behavior for valid inputs is unchanged. Misuse (null or empty version/prerelease
strings) now fails at parameter binding instead of producing downstream
NullReferenceExceptions inside the comparison logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants