@@ -20,6 +20,18 @@ Describe "ReviewUnusedParameter" {
20
20
$Violations.Count | Should - Be 2
21
21
}
22
22
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
+
23
35
It " has 1 violation - scriptblock with 1 unused parameter" {
24
36
$ScriptDefinition = ' { param ($Param1) }'
25
37
$Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
@@ -59,6 +71,30 @@ Describe "ReviewUnusedParameter" {
59
71
$Violations.Count | Should - Be 0
60
72
}
61
73
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
+
62
98
It " has no violations when using PSBoundParameters" {
63
99
$ScriptDefinition = ' function Bound { param ($Param1) Get-Foo @PSBoundParameters }'
64
100
$Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
0 commit comments