@@ -20,6 +20,30 @@ 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 inside process block" {
24
+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline = $false)] $Param1) process {$_}}'
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 inside process block" {
30
+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline = $false)] $Param1) process {$PSItem}}'
31
+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
32
+ $Violations.Count | Should - Be 1
33
+ }
34
+
35
+ It " has 1 violation - function with 1 parameter with ValueFromPipeline set to true and `$ _ usage outside process block" {
36
+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) $_}'
37
+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
38
+ $Violations.Count | Should - Be 1
39
+ }
40
+
41
+ It " has 1 violation - function with 1 parameter with ValueFromPipeline set to true and `$ PSItem usage outside process block" {
42
+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) $PSItem}'
43
+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
44
+ $Violations.Count | Should - Be 1
45
+ }
46
+
23
47
It " has 1 violation - scriptblock with 1 unused parameter" {
24
48
$ScriptDefinition = ' { param ($Param1) }'
25
49
$Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
@@ -59,6 +83,30 @@ Describe "ReviewUnusedParameter" {
59
83
$Violations.Count | Should - Be 0
60
84
}
61
85
86
+ It " has no violation - function with 1 parameter with ValueFromPipeline explictly set to true and `$ _ usage inside process block" {
87
+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) process {$_}}'
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 explictly set to true and `$ PSItem usage inside process block" {
93
+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) process {$PSItem}}'
94
+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
95
+ $Violations.Count | Should - Be 0
96
+ }
97
+
98
+ It " has no violation - function with 1 parameter with ValueFromPipeline implicitly set to true and `$ _ usage inside process block" {
99
+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline)] $Param1) process{$_}}'
100
+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
101
+ $Violations.Count | Should - Be 0
102
+ }
103
+
104
+ It " has no violation - function with 1 parameter with ValueFromPipeline implicitly set to true and `$ PSItem usage inside process block" {
105
+ $ScriptDefinition = ' function BadFunc1 { param ([Parameter(ValueFromPipeline)] $Param1) process{$PSItem}}'
106
+ $Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
107
+ $Violations.Count | Should - Be 0
108
+ }
109
+
62
110
It " has no violations when using PSBoundParameters" {
63
111
$ScriptDefinition = ' function Bound { param ($Param1) Get-Foo @PSBoundParameters }'
64
112
$Violations = Invoke-ScriptAnalyzer - ScriptDefinition $ScriptDefinition - IncludeRule $RuleName
0 commit comments