@@ -20,6 +20,18 @@ Describe "ReviewUnusedParameter" {
2020 $Violations.Count | Should - Be 2
2121 }
2222
23+ It " has 1 violation - function with 1 parameter with ValueFromPipeline set to false and `$ _ usage" {
24+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline = $false)] $Param1) $_}'
25+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
26+ $Violations.Count | Should - Be 1
27+ }
28+
29+ It " has 1 violation - function with 1 parameter with ValueFromPipeline set to false and `$ PSItem usage" {
30+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline = $false)] $Param1) $PSItem}'
31+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
32+ $Violations.Count | Should - Be 1
33+ }
34+
2335 It " has 1 violation - scriptblock with 1 unused parameter" {
2436 $ScriptDefinition = ' { param ($Param1) }'
2537 $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
@@ -59,6 +71,30 @@ Describe "ReviewUnusedParameter" {
5971 $Violations.Count | Should - Be 0
6072 }
6173
74+ It " has no violation - function with 1 parameter with ValueFromPipeline explictly set to true and `$ _ usage" {
75+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) $_}'
76+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
77+ $Violations.Count | Should - Be 0
78+ }
79+
80+ It " has no violation - function with 1 parameter with ValueFromPipeline explictly set to true and `$ PSItem usage" {
81+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) $PSItem}'
82+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
83+ $Violations.Count | Should - Be 0
84+ }
85+
86+ It " has no violation - function with 1 parameter with ValueFromPipeline implicitly set to true and `$ _ usage" {
87+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline)] $Param1) $_}'
88+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
89+ $Violations.Count | Should - Be 0
90+ }
91+
92+ It " has no violation - function with 1 parameter with ValueFromPipeline implicitly set to true and `$ PSItem usage" {
93+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline)] $Param1) $PSItem}'
94+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
95+ $Violations.Count | Should - Be 0
96+ }
97+
6298 It " has no violations when using PSBoundParameters" {
6399 $ScriptDefinition = ' function Bound { param ($Param1) Get-Foo @PSBoundParameters }'
64100 $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
0 commit comments