Skip to content

Commit 433a41c

Browse files
SeeminglySciencepwshBot
authored andcommitted
Suppress false positive PSScriptAnalyzer warnings in tests and build scripts (PowerShell#25864)
1 parent af70e9e commit 433a41c

16 files changed

Lines changed: 127 additions & 103 deletions

File tree

test/powershell/Modules/Microsoft.PowerShell.LocalAccounts/Pester.Command.Cmdlets.LocalAccounts.LocalUser.Tests.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# Module removed due to #4272
55
# disabling tests
66

7+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
8+
param()
9+
710
return
811

912
Set-Variable dateInFuture -Option Constant -Value "12/12/2036 09:00"
@@ -1557,4 +1560,3 @@ try {
15571560
finally {
15581561
$global:PSDefaultParameterValues = $originalDefaultParameterValues
15591562
}
1560-

test/powershell/Modules/Microsoft.PowerShell.Management/Set-Service.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
3+
4+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
5+
param()
6+
37
Import-Module (Join-Path -Path $PSScriptRoot '..\Microsoft.PowerShell.Security\certificateCommon.psm1')
48

59
Describe "Set/New/Remove-Service cmdlet tests" -Tags "Feature", "RequireAdminOnWindows" {

test/powershell/Modules/Microsoft.PowerShell.Security/CmsMessage.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
3+
4+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
5+
param()
6+
37
Import-Module (Join-Path -Path $PSScriptRoot 'certificateCommon.psm1') -Force
48

59
Describe "CmsMessage cmdlets and Get-PfxCertificate basic tests" -Tags "CI" {

test/powershell/Modules/Microsoft.PowerShell.Security/GetCredential.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
3+
4+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
5+
param()
6+
37
Describe "Get-Credential Test" -Tag "CI" {
48
BeforeAll {
59
$th = New-TestHost

test/powershell/Modules/Microsoft.PowerShell.Security/TestData/CatalogTestData/UserConfigProv/DSCResources/UserConfigProviderModVersion1/UserConfigProviderModVersion1.psm1

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,50 @@
55
# This cmdlet executes the user supplied script (i.e., the script is responsible for validating the desired state of the
66
# DSC managed node). The result of the script execution is in the form of a hashtable containing all the information
77
# gathered from the GetScript execution.
8-
function Get-TargetResource
9-
{
8+
function Get-TargetResource {
109
[CmdletBinding()]
11-
param
12-
(
13-
[parameter(Mandatory = $true)]
14-
[ValidateNotNullOrEmpty()]
15-
[string]
16-
$text
17-
)
10+
param(
11+
[Parameter(Mandatory = $true)]
12+
[ValidateNotNullOrEmpty()]
13+
[string]
14+
$Text
15+
)
1816

1917
$result = @{
20-
Text = "Hello from Get!";
21-
}
22-
$result;
18+
Text = "Hello from Get!"
19+
}
20+
21+
$result
2322
}
2423

2524
# The Set-TargetResource cmdlet is used to Set the desired state of the DSC managed node through a powershell script.
2625
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
2726
# DSC managed node). If the DSC managed node requires a restart either during or after the execution of the SetScript,
2827
# the SetScript notifies the PS Infrastructure by setting the variable $DSCMachineStatus.IsRestartRequired to $true.
29-
function Set-TargetResource
30-
{
28+
function Set-TargetResource {
3129
[CmdletBinding()]
32-
param
33-
(
34-
[parameter(Mandatory = $true)]
35-
[ValidateNotNullOrEmpty()]
36-
[string]
37-
$text
38-
)
39-
$path = "$env:SystemDrive\dscTestPath\hello1.txt"
40-
New-Item -Path $path -Type File -Force
41-
Add-Content -Path $path -Value $text
30+
param(
31+
[Parameter(Mandatory = $true)]
32+
[ValidateNotNullOrEmpty()]
33+
[string]
34+
$Text
35+
)
36+
$path = "$env:SystemDrive\dscTestPath\hello1.txt"
37+
New-Item -Path $path -Type File -Force
38+
Add-Content -Path $path -Value $text
4239
}
4340

4441
# The Test-TargetResource cmdlet is used to validate the desired state of the DSC managed node through a powershell script.
4542
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
4643
# DSC managed node). The result of the script execution should be true if the DSC managed machine is in the desired state
4744
# or else false should be returned.
48-
function Test-TargetResource
49-
{
45+
function Test-TargetResource {
5046
[CmdletBinding()]
51-
param
52-
(
53-
[parameter(Mandatory = $true)]
47+
param(
48+
[Parameter(Mandatory = $true)]
5449
[ValidateNotNullOrEmpty()]
5550
[string]
56-
$text
57-
)
58-
$false
51+
$Text
52+
)
53+
$false
5954
}
60-

test/powershell/Modules/Microsoft.PowerShell.Security/TestData/CatalogTestData/UserConfigProv/DSCResources/UserConfigProviderModVersion2/UserConfigProviderModVersion2.psm1

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,51 @@
55
# This cmdlet executes the user supplied script (i.e., the script is responsible for validating the desired state of the
66
# DSC managed node). The result of the script execution is in the form of a hashtable containing all the information
77
# gathered from the GetScript execution.
8-
function Get-TargetResource
9-
{
8+
function Get-TargetResource {
109
[CmdletBinding()]
11-
param
12-
(
13-
[parameter(Mandatory = $true)]
14-
[ValidateNotNullOrEmpty()]
15-
[string]
16-
$text
17-
)
10+
param(
11+
[Parameter(Mandatory = $true)]
12+
[ValidateNotNullOrEmpty()]
13+
[string]
14+
$Text
15+
)
1816

1917
$result = @{
20-
Text = "Hello from Get!";
21-
}
22-
$result;
23-
}
18+
Text = "Hello from Get!"
19+
}
20+
21+
$result
22+
}
2423

2524
# The Set-TargetResource cmdlet is used to Set the desired state of the DSC managed node through a powershell script.
2625
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
2726
# DSC managed node). If the DSC managed node requires a restart either during or after the execution of the SetScript,
2827
# the SetScript notifies the PS Infrastructure by setting the variable $DSCMachineStatus.IsRestartRequired to $true.
29-
function Set-TargetResource
30-
{
28+
function Set-TargetResource {
3129
[CmdletBinding()]
32-
param
33-
(
34-
[parameter(Mandatory = $true)]
35-
[ValidateNotNullOrEmpty()]
36-
[string]
37-
$text
38-
)
30+
param(
31+
[Parameter(Mandatory = $true)]
32+
[ValidateNotNullOrEmpty()]
33+
[string]
34+
$Text
35+
)
3936

40-
$path = "$env:SystemDrive\dscTestPath\hello2.txt"
41-
New-Item -Path $path -Type File -Force
42-
Add-Content -Path $path -Value $text
37+
$path = "$env:SystemDrive\dscTestPath\hello2.txt"
38+
New-Item -Path $path -Type File -Force
39+
Add-Content -Path $path -Value $text
4340
}
4441

4542
# The Test-TargetResource cmdlet is used to validate the desired state of the DSC managed node through a powershell script.
4643
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
4744
# DSC managed node). The result of the script execution should be true if the DSC managed machine is in the desired state
4845
# or else false should be returned.
49-
function Test-TargetResource
50-
{
46+
function Test-TargetResource {
5147
[CmdletBinding()]
52-
param
53-
(
54-
[parameter(Mandatory = $true)]
55-
[ValidateNotNullOrEmpty()]
56-
[string]
57-
$text
58-
)
59-
$false
48+
param(
49+
[Parameter(Mandatory = $true)]
50+
[ValidateNotNullOrEmpty()]
51+
[string]
52+
$Text
53+
)
54+
$false
6055
}
61-

test/powershell/Modules/Microsoft.PowerShell.Security/TestData/CatalogTestData/UserConfigProv/DSCResources/UserConfigProviderModVersion3/UserConfigProviderModVersion3.psm1

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,51 @@
55
# This cmdlet executes the user supplied script (i.e., the script is responsible for validating the desired state of the
66
# DSC managed node). The result of the script execution is in the form of a hashtable containing all the information
77
# gathered from the GetScript execution.
8-
function Get-TargetResource
9-
{
8+
function Get-TargetResource {
109
[CmdletBinding()]
11-
param
12-
(
13-
[parameter(Mandatory = $true)]
10+
param(
11+
[Parameter(Mandatory = $true)]
1412
[ValidateNotNullOrEmpty()]
1513
[string]
16-
$text
17-
)
14+
$Text
15+
)
1816

1917
$result = @{
20-
Text = "Hello from Get!";
21-
}
22-
$result;
23-
}
18+
Text = "Hello from Get!"
19+
}
20+
21+
$result
22+
}
2423

2524
# The Set-TargetResource cmdlet is used to Set the desired state of the DSC managed node through a powershell script.
2625
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
2726
# DSC managed node). If the DSC managed node requires a restart either during or after the execution of the SetScript,
2827
# the SetScript notifies the PS Infrastructure by setting the variable $DSCMachineStatus.IsRestartRequired to $true.
29-
function Set-TargetResource
30-
{
28+
function Set-TargetResource {
3129
[CmdletBinding()]
32-
param
33-
(
34-
[parameter(Mandatory = $true)]
30+
param(
31+
[Parameter(Mandatory = $true)]
3532
[ValidateNotNullOrEmpty()]
3633
[string]
37-
$text
38-
)
34+
$Text
35+
)
3936

40-
$path = "$env:SystemDrive\dscTestPath\hello3.txt"
41-
New-Item -Path $path -Type File -Force
42-
Add-Content -Path $path -Value $text
37+
$path = "$env:SystemDrive\dscTestPath\hello3.txt"
38+
New-Item -Path $path -Type File -Force
39+
Add-Content -Path $path -Value $text
4340
}
4441

4542
# The Test-TargetResource cmdlet is used to validate the desired state of the DSC managed node through a powershell script.
4643
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
4744
# DSC managed node). The result of the script execution should be true if the DSC managed machine is in the desired state
4845
# or else false should be returned.
49-
function Test-TargetResource
50-
{
46+
function Test-TargetResource {
5147
[CmdletBinding()]
52-
param
53-
(
54-
[parameter(Mandatory = $true)]
55-
[ValidateNotNullOrEmpty()]
56-
[string]
57-
$text
58-
)
59-
$false
48+
param(
49+
[Parameter(Mandatory = $true)]
50+
[ValidateNotNullOrEmpty()]
51+
[string]
52+
$Text
53+
)
54+
$false
6055
}
61-

test/powershell/Modules/Microsoft.PowerShell.Security/certificateCommon.psm1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
5+
param()
6+
47
Function New-GoodCertificate
58
{
69
<#

test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-SecureString.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
3+
4+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
5+
param()
6+
37
Describe "ConvertTo--SecureString" -Tags "CI" {
48

59
Context "Checking return types of ConvertTo--SecureString" {

test/powershell/Modules/Microsoft.WSMan.Management/ConfigProvider.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
5+
param()
6+
47
Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
58
BeforeAll {
69
#skip all tests on non-windows platform

0 commit comments

Comments
 (0)