PowerShell / PowerShell/PSScriptAnalyzer
Throw a warning when I redefine a global variable in a local scope
Open
Nobody has claimed this yet.
Issue - New Rule
Up-for-Grabs
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
Like the title says, it would be useful if I was warned whenever I try to reuse a global variable's name in a more local scope.
$a = 'Unchanged'
function foo {
Write-Host "foo can read `$a : `$a = $a"
$a = 'Changed from foo' # this should be warning!!
Write-Host "foo can change it's own copy of `$a: `$a = $a"
}
foo
Write-Host "After foo call: `$a = $a"
Thanks to @vors for the example.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the PowerShell example in the issue as the behavioral starting point. Review how PSScriptAnalyzer reports scope-related diagnostics, then define the warning trigger and verify it against the demonstrated global and local variable case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100