Skip to content

[Code Quality] bump-runtime.ps1 — Counters use $global: scope, pollute caller session #774

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Info

Location: bump-runtime.ps1:61-63,97,107-108

Code:

# Statistics counters
$global:totalFilesScanned = 0
$global:filesModified     = 0
$global:totalReplacements = 0
...
$global:totalFilesScanned++
...
$global:filesModified++
$global:totalReplacements += $matchCount

Explanation:
The three statistics counters are assigned to the $global: scope. If this script is dot-sourced (. .\bump-runtime.ps1 10.0) the variables persist in the caller's session after the script exits, polluting the global namespace. Even when run normally, $global: is unnecessarily broad — the counters are only needed inside the script and its helper function.

Suggested fix:
Use $script: scope so the variables are visible to Update-Files but cleaned up when the script exits:

$script:totalFilesScanned = 0
$script:filesModified     = 0
$script:totalReplacements = 0

…and inside Update-Files:

$script:totalFilesScanned++
...
$script:filesModified++
$script:totalReplacements += $matchCount

Same behavior, no session pollution.

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