Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReviewUnusedParameter: Do not trigger when MyInvocation.BoundParameters or PSCmdlet.MyInvocation.BoundParameters is used #1520

Merged
merged 7 commits into from Jun 14, 2020

Conversation

@jegannathanmaniganadan
Copy link
Contributor

jegannathanmaniganadan commented Jun 11, 2020

PR Summary

  • ReviewUnusedParameter returns false positives when parameters are splatted using $MyInvocation.BoundParameters & $PSCmldet.MyInvocation.BoundParameters variable. As of now it bails out only for $PSBoundParameter. This fix extends that logic to other bound parameter references.
  • fix #1505

PR Checklist

Manigandan Jegannathan and others added 6 commits May 22, 2020
…eters encountered
Enhance ReviewUnusedParameter to bail out if $MyInvocation.BoundParameters encountered
@microsoft-cla
Copy link

microsoft-cla bot commented Jun 11, 2020

CLA assistant check
All CLA requirements met.

Copy link
Collaborator

bergmeister left a comment

Thanks. Implementation looks good to me, just a minor suggestion.
Every new feature or fix needs to be accompanied by one or more test cases though. If you look qt the existing tests, it should be very easy to add 2 tests for the cases that you added:

It "has no violations when using PSBoundParameters" {
$ScriptDefinition = 'function Bound { param ($Param1) Get-Foo @PSBoundParameters }'
$Violations = Invoke-ScriptAnalyzer -ScriptDefinition $ScriptDefinition -IncludeRule $RuleName
$Violations.Count | Should -Be 0
}

Also, when you use a closing keyword in the PR description it will close the referenced issue
https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword

Rules/ReviewUnusedParameter.cs Outdated Show resolved Hide resolved
Copy link
Member

rjmholt left a comment

LGTM, with two small comments

Rules/ReviewUnusedParameter.cs Outdated Show resolved Hide resolved
Rules/ReviewUnusedParameter.cs Show resolved Hide resolved
Manigandan Jegannathan
- Add pester tests
@jegannathanmaniganadan
Copy link
Contributor Author

jegannathanmaniganadan commented Jun 14, 2020

Thanks both for your feedback. @bergmeister did not approve the PR, so requested review again.

Every new feature or fix needs to be accompanied by one or more test cases though. If you look qt the existing tests, it should be very easy to add 2 tests for the cases that you added:

Writing pester tests for testing PSSA rule behavior is the most easiest job I have come across :)

@bergmeister bergmeister changed the title ReviewUnusedParameter Bug Fix ReviewUnusedParameter: Do not trigger when MyInvocation.BoundParameters or PSCmdlet.MyInvocation.BoundParameters is used Jun 14, 2020
Copy link
Collaborator

bergmeister left a comment

Thanks, looks good 😊

@bergmeister bergmeister merged commit 1b4a9b9 into PowerShell:master Jun 14, 2020
3 checks passed
3 checks passed
PSScriptAnalyzer-CI #20200613.4 succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
license/cla All CLA requirements met.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.