Skip to content

Commit e12c4a6

Browse files
committed
Merge branch 'AutoFixWarnings' of https://github.com/bergmeister/PSScriptAnalyzer into AutoFixWarnings
2 parents 8525e03 + 0df445b commit e12c4a6

5 files changed

+12
-12
lines changed

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,14 @@ Describe "Test -Fix Switch" {
475475
AfterEach {
476476
if ($null -ne $initialTestScript)
477477
{
478-
$initialTestScript | Set-Content $directory\TestScriptWithFixableWarnings.ps1 -NoNewline
478+
[System.IO.File]::WriteAllText("$($directory)\TestScriptWithFixableWarnings.ps1", $initialTestScript) # Set-Content -NoNewline was only introduced in PS v5 and would therefore not work in CI
479479
}
480480
}
481481

482482
It "Fixes warnings" {
483483
# we expect the script to contain warnings
484484
$warningsBeforeFix = Invoke-ScriptAnalyzer $directory\TestScriptWithFixableWarnings.ps1
485-
$warningsBeforeFix.Count | Should Be 4
485+
$warningsBeforeFix.Count | Should Be 5
486486

487487
# fix the warnings and expect that it should not return the fixed warnings
488488
$warningsWithFixSwitch = Invoke-ScriptAnalyzer $directory\TestScriptWithFixableWarnings.ps1 -Fix

Tests/Engine/LibraryUsage.tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $directory = Split-Path -Parent $MyInvocation.MyCommand.Path
1515
# wraps the usage of ScriptAnalyzer as a .NET library
1616
function Invoke-ScriptAnalyzer {
1717
param (
18-
[CmdletBinding(DefaultParameterSetName="File")]
18+
[CmdletBinding(DefaultParameterSetName="File", SupportsShouldProcess = $true)]
1919

2020
[parameter(Mandatory = $true, Position = 0, ParameterSetName="File")]
2121
[Alias("PSPath")]
@@ -78,7 +78,7 @@ function Invoke-ScriptAnalyzer {
7878
);
7979

8080
if ($PSCmdlet.ParameterSetName -eq "File") {
81-
$supportsShouldProcessFunc = [Func[string, string, bool]]{ return $Recurse.IsPresent }
81+
$supportsShouldProcessFunc = [Func[string, string, bool]]{ return $PSCmdlet.Shouldprocess }
8282
if ($Fix.IsPresent)
8383
{
8484
return $scriptAnalyzer.AnalyzeAndFixPath($Path, $supportsShouldProcessFunc, $Recurse.IsPresent);

Tests/Engine/ModuleHelp.Tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function Get-ParametersDefaultFirst {
121121
)
122122

123123
BEGIN {
124-
$Common = 'Debug', 'ErrorAction', 'ErrorVariable', 'InformationAction', 'InformationVariable', 'OutBuffer', 'OutVariable', 'PipelineVariable', 'Verbose', 'WarningAction', 'WarningVariable'
124+
$Common = 'Debug', 'ErrorAction', 'ErrorVariable', 'InformationAction', 'InformationVariable', 'OutBuffer', 'OutVariable', 'PipelineVariable', 'Verbose', 'WarningAction', 'WarningVariable', 'WhatIf', 'Confirm'
125125
$parameters = @()
126126
}
127127
PROCESS {
@@ -266,7 +266,7 @@ foreach ($command in $commands) {
266266
Context "Test parameter help for $commandName" {
267267

268268
$Common = 'Debug', 'ErrorAction', 'ErrorVariable', 'InformationAction', 'InformationVariable', 'OutBuffer', 'OutVariable',
269-
'PipelineVariable', 'Verbose', 'WarningAction', 'WarningVariable'
269+
'PipelineVariable', 'Verbose', 'WarningAction', 'WarningVariable', 'WhatIf', 'Confirm'
270270

271271
# Get parameters. When >1 parameter with same name,
272272
# get parameter from the default parameter set, if any.
@@ -315,4 +315,4 @@ foreach ($command in $commands) {
315315
}
316316
}
317317
}
318-
}
318+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Produce PSAvoidUsingCmdletAliases warning that should get fixed by replacing it with the actual command
1+
# Produce PSAvoidUsingCmdletAliases and PSAvoidTrailingWhitespace warnings that should get fixed by replacing it with the actual command
22
gci . | % { } | ? { }
33

44
# Produces PSAvoidUsingPlainTextForPassword warning that should get fixed by making it a [SecureString]
5-
function Test-bar([string]$PasswordInPlainText){}
5+
function Test-bar([string]$PasswordInPlainText){}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Produce PSAvoidUsingCmdletAliases warning that should get fixed by replacing it with the actual command
2-
Get-ChildItem . | ForEach-Object { } | Where-Object { }
1+
# Produce PSAvoidUsingCmdletAliases and PSAvoidTrailingWhitespace warnings that should get fixed by replacing it with the actual command
2+
Get-ChildItem . | ForEach-Object { } | Where-Object { }
33

44
# Produces PSAvoidUsingPlainTextForPassword warning that should get fixed by making it a [SecureString]
5-
function Test-bar([SecureString]$PasswordInPlainText){}
5+
function Test-bar([SecureString]$PasswordInPlainText){}

0 commit comments

Comments
 (0)