diff --git a/Tests/Disabled Rules/AvoidOneChar.tests.ps1 b/Tests/Disabled Rules/AvoidOneChar.tests.ps1 new file mode 100644 index 000000000..6c9820fe1 --- /dev/null +++ b/Tests/Disabled Rules/AvoidOneChar.tests.ps1 @@ -0,0 +1,24 @@ +Import-Module PSScriptAnalyzer +$oneCharMessage = "The cmdlet name O only has one character." +$oneCharName = "PSOneChar" +$directory = Split-Path -Parent $MyInvocation.MyCommand.Path +$invoke = Invoke-ScriptAnalyzer $directory\AvoidUsingReservedCharOneCharNames.ps1 | Where-Object {$_.RuleName -eq $oneCharName} +$noViolations = Invoke-ScriptAnalyzer $directory\GoodCmdlet.ps1 | Where-Object {$_.RuleName -eq $oneCharName} + +Describe "Avoid Using One Char" { + Context "When there are violations" { + It "has 1 One Char Violation" { + $oneCharViolations.Count | Should Be 1 + } + + It "has the correct description message" { + $oneCharViolations[0].Message | Should Match $oneCharMessage + } + } + + Context "When there are no violations" { + It "has no violations" { + $noReservedCharViolations.Count | Should Be 0 + } + } +} \ No newline at end of file diff --git a/Tests/Disabled Rules/AvoidUnloadableModule.tests.ps1 b/Tests/Disabled Rules/AvoidUnloadableModule.tests.ps1 new file mode 100644 index 000000000..a9d5f85cf --- /dev/null +++ b/Tests/Disabled Rules/AvoidUnloadableModule.tests.ps1 @@ -0,0 +1,24 @@ +Import-Module PSScriptAnalyzer +$unloadableMessage = [regex]::Escape("Cannot load the module TestBadModule that the file TestBadModule.psd1 is in.") +$unloadableName = "PSAvoidUnloadableModule" +$directory = Split-Path -Parent $MyInvocation.MyCommand.Path +$violations = Invoke-ScriptAnalyzer $directory\TestBadModule\TestBadModule.psd1 | Where-Object {$_.RuleName -eq $unloadableName} +$noViolations = Invoke-ScriptAnalyzer $directory\TestGoodModule\TestGoodModule.psd1 | Where-Object {$_.RuleName -eq $unloadableName} + +Describe "AvoidUnloadableModule" { + Context "When there are violations" { + It "has 1 unloadable module violation" { + $violations.Count | Should Be 1 + } + + It "has the correct description message" { + $violations.Message | Should Match $unloadableMessage + } + } + + Context "When there are no violations" { + It "returns no violations" { + $noViolations.Count | Should Be 0 + } + } +} \ No newline at end of file diff --git a/Tests/Rules/AvoidUsingClearHostWriteHost.ps1 b/Tests/Disabled Rules/AvoidUsingClearHost.ps1 similarity index 100% rename from Tests/Rules/AvoidUsingClearHostWriteHost.ps1 rename to Tests/Disabled Rules/AvoidUsingClearHost.ps1 diff --git a/Tests/Disabled Rules/AvoidUsingClearHost.tests.ps1 b/Tests/Disabled Rules/AvoidUsingClearHost.tests.ps1 new file mode 100644 index 000000000..b32fd73db --- /dev/null +++ b/Tests/Disabled Rules/AvoidUsingClearHost.tests.ps1 @@ -0,0 +1,25 @@ +Import-Module PSScriptAnalyzer +Set-Alias ctss ConvertTo-SecureString +$clearHostMessage = "File 'AvoidUsingClearHostWriteHost.ps1' uses Clear-Host. This is not recommended because it may not work in some hosts or there may even be no hosts at all." +$clearHostName = "PSAvoidUsingClearHost" +$directory = Split-Path -Parent $MyInvocation.MyCommand.Path +$violations = Invoke-ScriptAnalyzer $directory\AvoidUsingClearHost.ps1 | Where-Object {$_.RuleName -eq $clearHostName} +$noViolations = Invoke-ScriptAnalyzer $directory\AvoidUsingClearHostNoViolations.ps1 | Where-Object {$_.RuleName -eq $writeHostName} + +Describe "AvoidUsingClearHost" { + Context "When there are violations" { + It "has 3 Clear-Host violations" { + $violations.Count | Should Be 3 + } + + It "has the correct description message for Clear-Host" { + $violations[0].Message | Should Match $clearHostMessage + } + } + + Context "When there are no violations" { + It "returns no violations" { + $noViolations.Count | Should Be 0 + } + } +} \ No newline at end of file diff --git a/Tests/Rules/AvoidUsingClearHostWriteHostNoViolations.ps1 b/Tests/Disabled Rules/AvoidUsingClearHostNoViolations.ps1 similarity index 100% rename from Tests/Rules/AvoidUsingClearHostWriteHostNoViolations.ps1 rename to Tests/Disabled Rules/AvoidUsingClearHostNoViolations.ps1 diff --git a/Tests/Rules/AvoidUsingFilePath.ps1 b/Tests/Disabled Rules/AvoidUsingFilePath.ps1 similarity index 100% rename from Tests/Rules/AvoidUsingFilePath.ps1 rename to Tests/Disabled Rules/AvoidUsingFilePath.ps1 diff --git a/Tests/Rules/AvoidUsingFilePath.tests.ps1 b/Tests/Disabled Rules/AvoidUsingFilePath.tests.ps1 similarity index 97% rename from Tests/Rules/AvoidUsingFilePath.tests.ps1 rename to Tests/Disabled Rules/AvoidUsingFilePath.tests.ps1 index 5b34cecdf..50030ee01 100644 --- a/Tests/Rules/AvoidUsingFilePath.tests.ps1 +++ b/Tests/Disabled Rules/AvoidUsingFilePath.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $violationMessage = @' The file path "D:\\Code" of AvoidUsingFilePath.ps1 is rooted. This should be avoided if AvoidUsingFilePath.ps1 is published online '@ diff --git a/Tests/Rules/AvoidUsingFilePathNoViolations.ps1 b/Tests/Disabled Rules/AvoidUsingFilePathNoViolations.ps1 similarity index 100% rename from Tests/Rules/AvoidUsingFilePathNoViolations.ps1 rename to Tests/Disabled Rules/AvoidUsingFilePathNoViolations.ps1 diff --git a/Tests/Rules/CommandNotFound.ps1 b/Tests/Disabled Rules/CommandNotFound.ps1 similarity index 100% rename from Tests/Rules/CommandNotFound.ps1 rename to Tests/Disabled Rules/CommandNotFound.ps1 diff --git a/Tests/Rules/CommandNotFound.tests.ps1 b/Tests/Disabled Rules/CommandNotFound.tests.ps1 similarity index 100% rename from Tests/Rules/CommandNotFound.tests.ps1 rename to Tests/Disabled Rules/CommandNotFound.tests.ps1 diff --git a/Tests/Rules/TypeNotFound.ps1 b/Tests/Disabled Rules/TypeNotFound.ps1 similarity index 100% rename from Tests/Rules/TypeNotFound.ps1 rename to Tests/Disabled Rules/TypeNotFound.ps1 diff --git a/Tests/Rules/TypeNotFound.tests.ps1 b/Tests/Disabled Rules/TypeNotFound.tests.ps1 similarity index 94% rename from Tests/Rules/TypeNotFound.tests.ps1 rename to Tests/Disabled Rules/TypeNotFound.tests.ps1 index fc9b0e9dc..72ed21180 100644 --- a/Tests/Rules/TypeNotFound.tests.ps1 +++ b/Tests/Disabled Rules/TypeNotFound.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module -Verbose ScriptAnalyzer +Import-Module -Verbose PSScriptAnalyzer $violationMessage = "Type Stre is not found" $violationName = "PSTypeNotFound" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path diff --git a/Tests/Rules/UseTypeAtVariableAssignment.ps1 b/Tests/Disabled Rules/UseTypeAtVariableAssignment.ps1 similarity index 100% rename from Tests/Rules/UseTypeAtVariableAssignment.ps1 rename to Tests/Disabled Rules/UseTypeAtVariableAssignment.ps1 diff --git a/Tests/Rules/UseTypeAtVariableAssignment.tests.ps1 b/Tests/Disabled Rules/UseTypeAtVariableAssignment.tests.ps1 similarity index 95% rename from Tests/Rules/UseTypeAtVariableAssignment.tests.ps1 rename to Tests/Disabled Rules/UseTypeAtVariableAssignment.tests.ps1 index 8dc737e0a..3b2551533 100644 --- a/Tests/Rules/UseTypeAtVariableAssignment.tests.ps1 +++ b/Tests/Disabled Rules/UseTypeAtVariableAssignment.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module -Verbose ScriptAnalyzer +Import-Module -Verbose PSScriptAnalyzer $violationMessage = [regex]::Escape('Specify type at the assignment of variable $test') $violationName = "PSUseTypeAtVariableAssignment" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path diff --git a/Tests/Engine/CommunityAnalyzerRules/CommunityAnalyzerRules.psm1 b/Tests/Engine/CommunityAnalyzerRules/CommunityAnalyzerRules.psm1 index 17d763601..8b96af38f 100644 --- a/Tests/Engine/CommunityAnalyzerRules/CommunityAnalyzerRules.psm1 +++ b/Tests/Engine/CommunityAnalyzerRules/CommunityAnalyzerRules.psm1 @@ -95,7 +95,7 @@ function Measure-RequiresRunAsAdministrator $result = [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord]@{"Message" = $Messages.MeasureRequiresRunAsAdministrator; "Extent" = $assignmentAst.Extent; "RuleName" = $PSCmdlet.MyInvocation.InvocationName; - "Severity" = "Strict"} + "Severity" = "Information"} $results += $result } } @@ -106,7 +106,7 @@ function Measure-RequiresRunAsAdministrator $result = [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord]@{"Message" = $Messages.MeasureRequiresRunAsAdministrator; "Extent" = $assignmentAst.Extent; "RuleName" = $PSCmdlet.MyInvocation.InvocationName; - "Severity" = "Strict"} + "Severity" = "Information"} $results += $result } } @@ -195,7 +195,7 @@ function Measure-RequiresModules $result = [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord]@{"Message" = $Messages.MeasureRequiresModules; "Extent" = $ast.Extent; "RuleName" = $PSCmdlet.MyInvocation.InvocationName; - "Severity" = "Strict"} + "Severity" = "Information"} $results += $result } } @@ -209,7 +209,7 @@ function Measure-RequiresModules $result = [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord]@{"Message" = $Messages.MeasureRequiresModules; "Extent" = $ast.Extent; "RuleName" = $PSCmdlet.MyInvocation.InvocationName; - "Severity" = "Strict"} + "Severity" = "Information"} $results += $result } } @@ -288,7 +288,7 @@ function Measure-LongClassName $result = [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord]@{"Message" = $Messages.MeasureLongClassName; "Extent" = $sbResult.BoundParameters["TypeName"].Value.Extent; "RuleName" = $PSCmdlet.MyInvocation.InvocationName; - "Severity" = "Strict"} + "Severity" = "Information"} $results += $result } } @@ -346,7 +346,7 @@ function Measure-DeprecatedWMIClass $result = [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord]@{"Message" = $Messages.MeasureDeprecatedWMIClass; "Extent" = $StringConstantExpressionAst.Extent; "RuleName" = $PSCmdlet.MyInvocation.InvocationName; - "Severity" = "Strict"} + "Severity" = "Information"} $results += $result } @@ -511,7 +511,7 @@ function Measure-CurlyBracket $result = [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord]@{"Message" = $Messages.MeasureCurlyBracket; "Extent" = $ast.Extent; "RuleName" = $PSCmdlet.MyInvocation.InvocationName; - "Severity" = "Strict"} + "Severity" = "Information"} $results += $result } } diff --git a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 index 9b0bea2aa..dbbc97f08 100644 --- a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 +++ b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 @@ -1,9 +1,8 @@ -Import-Module -Verbose ScriptAnalyzer +Import-Module -Verbose PSScriptAnalyzer $sa = Get-Command Get-ScriptAnalyzerRule $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $singularNouns = "PSUseSingularNouns" $approvedVerbs = "PSUseApprovedVerbs" -$unloadableModule = "PSAvoidUnloadableModule" $dscIdentical = "PSDSCUseIdenticalParametersForDSC" Describe "Test available parameters" { @@ -45,9 +44,8 @@ Describe "Test Name parameters" { } It "works with 3 names" { - $rules = Get-ScriptAnalyzerRule -Name $unloadableModule, $approvedVerbs, $singularNouns - $rules.Count | Should Be 3 - ($rules | Where-Object {$_.Name -eq $unloadableModule}).Count | Should Be 1 + $rules = Get-ScriptAnalyzerRule -Name $approvedVerbs, $singularNouns + $rules.Count | Should Be 2 ($rules | Where-Object {$_.Name -eq $singularNouns}).Count | Should Be 1 ($rules | Where-Object {$_.Name -eq $approvedVerbs}).Count | Should Be 1 } diff --git a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 index 16aa0862c..53ddb9a02 100644 --- a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 +++ b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $sa = Get-Command Invoke-ScriptAnalyzer $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $singularNouns = "PSUseSingularNouns" @@ -26,16 +26,6 @@ Describe "Test available parameters" { } } - Context "LoggerPath parameters" { - It "has a LoggerPath parameter" { - $params.ContainsKey("LoggerPath") | Should Be $true - } - - It "accepts string array" { - $params["LoggerPath"].ParameterType.FullName | Should Be "System.String[]" - } - } - Context "IncludeRule parameters" { It "has an IncludeRule parameter" { $params.ContainsKey("IncludeRule") | Should Be $true @@ -72,21 +62,21 @@ Describe "Test Path" { } Context "When given a directory" { - $withoutPathWithDirectory = Invoke-ScriptAnalyzer $directory\RecursionDirectoryTest - $withPathWithDirectory = Invoke-ScriptAnalyzer -Path $directory\RecursionDirectoryTest + $withoutPathWithDirectory = Invoke-ScriptAnalyzer -Recurse $directory\RecursionDirectoryTest + $withPathWithDirectory = Invoke-ScriptAnalyzer -Recurse -Path $directory\RecursionDirectoryTest It "Has the same count as without Path parameter"{ $withoutPathWithDirectory.Count -eq $withPathWithDirectory.Count | Should Be $true } - It "Analyzes all the file" { + It "Analyzes all the files" { $globalVarsViolation = $withPathWithDirectory | Where-Object {$_.RuleName -eq "PSAvoidGlobalVars"} $clearHostViolation = $withPathWithDirectory | Where-Object {$_.RuleName -eq "PSAvoidUsingClearHost"} $writeHostViolation = $withPathWithDirectory | Where-Object {$_.RuleName -eq "PSAvoidUsingWriteHost"} Write-Output $globalVarsViolation.Count Write-Output $clearHostViolation.Count Write-Output $writeHostViolation.Count - $globalVarsViolation.Count -eq 1 -and $clearHostViolation.Count -eq 1 -and $writeHostViolation.Count -eq 1 | Should Be $true + $globalVarsViolation.Count -eq 1 -and $writeHostViolation.Count -eq 1 | Should Be $true } } @@ -151,12 +141,12 @@ Describe "Test Exclude And Include" { Describe "Test Severity" { Context "When used correctly" { It "works with one argument" { - $errors = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -Severity Strict + $errors = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -Severity Information $errors.Count | Should Be 0 } It "works with 2 arguments" { - $errors = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -Severity Strict, Warning + $errors = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -Severity Information, Warning $errors.Count | Should Be 2 } } diff --git a/Tests/Rules/AvoidConvertToSecureStringWithPlainText.tests.ps1 b/Tests/Rules/AvoidConvertToSecureStringWithPlainText.tests.ps1 index 9c4e78ff0..2f0febbb2 100644 --- a/Tests/Rules/AvoidConvertToSecureStringWithPlainText.tests.ps1 +++ b/Tests/Rules/AvoidConvertToSecureStringWithPlainText.tests.ps1 @@ -1,6 +1,6 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer Set-Alias ctss ConvertTo-SecureString -$violationMessage = "File AvoidConvertToSecureStringWithPlainText.ps1 uses ConvertTo-SecureString with plaintext. This will expose secure information. Encrypted standard strings should be used instead." +$violationMessage = "File 'AvoidConvertToSecureStringWithPlainText.ps1' uses ConvertTo-SecureString with plaintext. This will expose secure information. Encrypted standard strings should be used instead." $violationName = "PSAvoidUsingConvertToSecureStringWithPlainText" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\AvoidConvertToSecureStringWithPlainText.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/AvoidDefaultTrueValueSwitchParameter.tests.ps1 b/Tests/Rules/AvoidDefaultTrueValueSwitchParameter.tests.ps1 index 9163327a0..469dc6a66 100644 --- a/Tests/Rules/AvoidDefaultTrueValueSwitchParameter.tests.ps1 +++ b/Tests/Rules/AvoidDefaultTrueValueSwitchParameter.tests.ps1 @@ -1,5 +1,5 @@ -Import-Module ScriptAnalyzer -$violationMessage = "File AvoidDefaultTrueValueSwitchParameter.ps1 has a switch parameter default to true." +Import-Module PSScriptAnalyzer +$violationMessage = "File 'AvoidDefaultTrueValueSwitchParameter.ps1' has a switch parameter default to true." $violationName = "PSAvoidDefaultValueSwitchParameter" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\AvoidDefaultTrueValueSwitchParameter.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/AvoidEmptyCatchBlock.tests.ps1 b/Tests/Rules/AvoidEmptyCatchBlock.tests.ps1 index 175a417b4..bcd2fb9d5 100644 --- a/Tests/Rules/AvoidEmptyCatchBlock.tests.ps1 +++ b/Tests/Rules/AvoidEmptyCatchBlock.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $violationMessage = "Empty catch block is used. Please use Write-Error or throw statements in catch blocks." $violationName = "PSAvoidUsingEmptyCatchBlock" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path diff --git a/Tests/Rules/AvoidGlobalOrUnitializedVars.tests.ps1 b/Tests/Rules/AvoidGlobalOrUnitializedVars.tests.ps1 index e7ac86448..537f57024 100644 --- a/Tests/Rules/AvoidGlobalOrUnitializedVars.tests.ps1 +++ b/Tests/Rules/AvoidGlobalOrUnitializedVars.tests.ps1 @@ -1,8 +1,8 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $globalMessage = "Found global variable 'Global:1'." $globalName = "PSAvoidGlobalVars" $nonInitializedName = "PSAvoidUninitializedVariable" -$nonInitializedMessage = "Variable a is not initialized. Non-global variables must be initialized. To fix a violation of this rule, please initialize non-global variables." +$nonInitializedMessage = "Variable 'a' is not initialized. Non-global variables must be initialized. To fix a violation of this rule, please initialize non-global variables." $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\AvoidGlobalOrUnitializedVars.ps1 $globalViolations = $violations | Where-Object {$_.RuleName -eq $globalName} @@ -18,7 +18,7 @@ Describe "AvoidGlobalVars" { } It "has the correct description message" { - $violations[0].Message | Should Match $violationMessage + $violations[0].Message | Should Match $globalMessage } } diff --git a/Tests/Rules/AvoidInvokingEmptyMembers.tests.ps1 b/Tests/Rules/AvoidInvokingEmptyMembers.tests.ps1 index 8c83d7503..de411f490 100644 --- a/Tests/Rules/AvoidInvokingEmptyMembers.tests.ps1 +++ b/Tests/Rules/AvoidInvokingEmptyMembers.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $violationMessage = "() has non-constant members. Invoking empty members may cause bugs in the script." $violationName = "PSAvoidInvokingEmptyMembers" diff --git a/Tests/Rules/AvoidPositionalParameters.tests.ps1 b/Tests/Rules/AvoidPositionalParameters.tests.ps1 index 022017b32..82be8a726 100644 --- a/Tests/Rules/AvoidPositionalParameters.tests.ps1 +++ b/Tests/Rules/AvoidPositionalParameters.tests.ps1 @@ -1,5 +1,5 @@ -Import-Module ScriptAnalyzer -$violationMessage = "Cmdlet Get-Content has positional parameter. Please use named parameters instead of positional parameters when calling a command." +Import-Module PSScriptAnalyzer +$violationMessage = "Cmdlet 'Get-Content' has positional parameter. Please use named parameters instead of positional parameters when calling a command." $violationName = "PSAvoidUsingPositionalParameters" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\AvoidPositionalParameters.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/AvoidReservedParams.tests.ps1 b/Tests/Rules/AvoidReservedParams.tests.ps1 index b6b70f42b..602af77fd 100644 --- a/Tests/Rules/AvoidReservedParams.tests.ps1 +++ b/Tests/Rules/AvoidReservedParams.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $violationMessage = [regex]::Escape("Verb-Files' defines the reserved common parameter 'Verbose'.") $violationName = "PSReservedParams" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path diff --git a/Tests/Rules/AvoidShouldContinueWithoutForce.tests.ps1 b/Tests/Rules/AvoidShouldContinueWithoutForce.tests.ps1 index 2a73c3b5a..4fab2e16b 100644 --- a/Tests/Rules/AvoidShouldContinueWithoutForce.tests.ps1 +++ b/Tests/Rules/AvoidShouldContinueWithoutForce.tests.ps1 @@ -1,14 +1,14 @@ -Import-Module ScriptAnalyzer -$violationMessage = "Function Verb-Noun in file AvoidShouldContinueShouldProcessWithoutForce.ps1 uses ShouldContinue or ShouldProcess but does not have a boolean force parameter. The force parameter will allow users of the script to bypass ShouldContinue prompt" -$violationName = "PSAvoidShouldContinueShouldProcessWithoutForce" +Import-Module PSScriptAnalyzer +$violationMessage = "Function 'Verb-Noun' in file 'AvoidShouldContinueWithoutForce.ps1' uses ShouldContinue but does not have a boolean force parameter. The force parameter will allow users of the script to bypass ShouldContinue prompt" +$violationName = "PSAvoidShouldContinueWithoutForce" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path -$violations = Invoke-ScriptAnalyzer $directory\AvoidShouldContinueShouldProcessWithoutForce.ps1 | Where-Object {$_.RuleName -eq $violationName} +$violations = Invoke-ScriptAnalyzer $directory\AvoidShouldContinueWithoutForce.ps1 | Where-Object {$_.RuleName -eq $violationName} $noViolations = Invoke-ScriptAnalyzer $directory\GoodCmdlet.ps1 | Where-Object {$_.RuleName -eq $violationName} -Describe "AvoidShouldContinueShouldProcessWithoutForce" { +Describe "AvoidShouldContinueWithoutForce" { Context "When there are violations" { - It "has 4 avoid ShouldContinue or ShouldProcess without boolean Force parameter violations" { - $violations.Count | Should Be 4 + It "has 2 avoid ShouldContinue without boolean Force parameter violations" { + $violations.Count | Should Be 2 } It "has the correct description message" { diff --git a/Tests/Rules/AvoidTrapStatements.tests.ps1 b/Tests/Rules/AvoidTrapStatements.tests.ps1 index 3888ae03a..4b4aa674f 100644 --- a/Tests/Rules/AvoidTrapStatements.tests.ps1 +++ b/Tests/Rules/AvoidTrapStatements.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $violationMessage = "Trap found." $violationName = "PSAvoidTrapStatement" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path diff --git a/Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1 b/Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1 index de1dc67dc..8f828d9ac 100644 --- a/Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1 +++ b/Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1 @@ -1,48 +1,24 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $missingMessage = "The member 'ModuleVersion' is not present in the module manifest." $missingName = "PSMissingModuleManifestField" -$unloadableMessage = [regex]::Escape("Cannot load the module TestBadModule that the file TestBadModule.psd1 is in.") -$unloadableName = "PSAvoidUnloadableModule" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path -$violations = Invoke-ScriptAnalyzer $directory\TestBadModule\TestBadModule.psd1 -$missingViolations = $violations | Where-Object {$_.RuleName -eq $missingName} -$unloadableViolations = $violations | Where-Object {$_.RuleName -eq $unloadableName} -$noViolations = Invoke-ScriptAnalyzer $directory\TestGoodModule\TestGoodModule.psd1 -$noMissingViolations = $noViolations | Where-Object {$_.RuleName -eq $missingName} -$noUnloadableViolations = $noViolations | Where-Object {$_.RuleName -eq $unloadableName} - -Describe "AvoidUnloadableModule" { - Context "When there are violations" { - It "has 1 unloadable module violation" { - $unloadableViolations.Count | Should Be 1 - } - - It "has the correct description message" { - $unloadableViolations.Message | Should Match $unloadableMessage - } - } - - Context "When there are no violations" { - It "returns no violations" { - $noUnloadableViolations.Count | Should Be 0 - } - } -} +$violations = Invoke-ScriptAnalyzer $directory\TestBadModule\TestBadModule.psd1 | Where-Object {$_.RuleName -eq $missingName} +$noViolations = Invoke-ScriptAnalyzer $directory\TestGoodModule\TestGoodModule.psd1 | Where-Object {$_.RuleName -eq $missingName} Describe "MissingRequiredFieldModuleManifest" { Context "When there are violations" { It "has 1 missing required field module manifest violation" { - $missingViolations.Count | Should Be 1 + $violations.Count | Should Be 1 } It "has the correct description message" { - $missingViolations.Message | Should Match $missingMessage + $violations.Message | Should Match $missingMessage } } Context "When there are no violations" { It "returns no violations" { - $noMissingViolations.Count | Should Be 0 + $noViolations.Count | Should Be 0 } } } diff --git a/Tests/Rules/AvoidUserNameAndPasswordParams.tests.ps1 b/Tests/Rules/AvoidUserNameAndPasswordParams.tests.ps1 index bab6dfe3b..e50e9fcdc 100644 --- a/Tests/Rules/AvoidUserNameAndPasswordParams.tests.ps1 +++ b/Tests/Rules/AvoidUserNameAndPasswordParams.tests.ps1 @@ -1,6 +1,6 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer -$violationMessage = "Function TestFunction has both username and password parameters. A credential parameter of type PSCredential should be used." +$violationMessage = "Function 'TestFunction' has both username and password parameters. A credential parameter of type PSCredential should be used." $violationName = "PSAvoidUsingUserNameAndPasswordParams" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\AvoidUserNameAndPasswordParams.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/AvoidUsingAlias.tests.ps1 b/Tests/Rules/AvoidUsingAlias.tests.ps1 index d2e45ad23..7c9d74db1 100644 --- a/Tests/Rules/AvoidUsingAlias.tests.ps1 +++ b/Tests/Rules/AvoidUsingAlias.tests.ps1 @@ -1,5 +1,5 @@ -Import-Module ScriptAnalyzer -$violationMessage = "iex is an alias of Invoke-Expression. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content." +Import-Module PSScriptAnalyzer +$violationMessage = "'iex' is an alias of 'Invoke-Expression'. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content." $violationName = "PSAvoidUsingCmdletAliases" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\AvoidUsingAlias.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/AvoidUsingClearHostWriteHost.tests.ps1 b/Tests/Rules/AvoidUsingClearHostWriteHost.tests.ps1 deleted file mode 100644 index 2d3d5b323..000000000 --- a/Tests/Rules/AvoidUsingClearHostWriteHost.tests.ps1 +++ /dev/null @@ -1,50 +0,0 @@ -Import-Module ScriptAnalyzer -Set-Alias ctss ConvertTo-SecureString -$consoleWriteMessage = "File AvoidUsingClearHostWriteHost.ps1 uses Console.WriteLine. Using Console to write is not recommended because it may not work in all hosts or there may even be no hosts at all. Use Write-Output instead." -$writeHostMessage = "File AvoidUsingClearHostWriteHost.ps1 uses Write-Host. This is not recommended because it may not work in some hosts or there may even be no hosts at all. Use Write-Output instead." -$clearHostMessage = "File AvoidUsingClearHostWriteHost.ps1 uses Clear-Host. This is not recommended because it may not work in some hosts or there may even be no hosts at all." -$writeHostName = "PSAvoidUsingWriteHost" -$clearHostName = "PSAvoidUsingClearHost" -$directory = Split-Path -Parent $MyInvocation.MyCommand.Path -$invocation = Invoke-ScriptAnalyzer $directory\AvoidUsingClearHostWriteHost.ps1 -$clearHostViolations = $invocation | Where-Object {$_.RuleName -eq $clearHostName} -$writeHostViolations = $invocation | Where-Object {$_.RuleName -eq $writeHostName} -$noViolations = Invoke-ScriptAnalyzer $directory\AvoidUsingClearHostWriteHostNoViolations.ps1 -$noClearHostViolations = $noViolations | Where-Object {$_.RuleName -eq $writeHostName} -$noWriteHostViolations = $noViolations | Where-Object {$_.RuleName -eq $clearHostName} - -Describe "AvoidUsingClearHost" { - Context "When there are violations" { - It "has 3 Clear-Host violations" { - $clearHostViolations.Count | Should Be 3 - } - - It "has the correct description message for Clear-Host" { - $clearHostViolations[0].Message | Should Match $clearHostMessage - } - } - - Context "When there are no violations" { - It "returns no violations" { - $noClearHostViolations.Count | Should Be 0 - } - } -} - -Describe "AvoidUsingWriteHost" { - Context "When there are violations" { - It "has 3 Write-Host violations" { - $writeHostViolations.Count | Should Be 3 - } - - It "has the correct description message for Write-Host" { - $writeHostViolations[0].Message | Should Match $writeHostMessage - } - } - - Context "When there are no violations" { - It "returns no violations" { - $noWriteHostViolations.Count | Should Be 0 - } - } -} \ No newline at end of file diff --git a/Tests/Rules/AvoidUsingComputerNameHardcoded.tests.ps1 b/Tests/Rules/AvoidUsingComputerNameHardcoded.tests.ps1 index a4c44e29b..c651d482b 100644 --- a/Tests/Rules/AvoidUsingComputerNameHardcoded.tests.ps1 +++ b/Tests/Rules/AvoidUsingComputerNameHardcoded.tests.ps1 @@ -1,5 +1,5 @@ -Import-Module ScriptAnalyzer -$violationMessage = [regex]::Escape('The ComputerName parameter of cmdlet Invoke-Command is hardcoded. This will expose sensitive information about the system if the script is shared.') +Import-Module PSScriptAnalyzer +$violationMessage = [regex]::Escape("The ComputerName parameter of cmdlet 'Invoke-Command' is hardcoded. This will expose sensitive information about the system if the script is shared.") $violationName = "PSAvoidUsingComputerNameHardcoded" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\AvoidUsingComputerNameHardcoded.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/AvoidUsingInternalURLs.tests.ps1 b/Tests/Rules/AvoidUsingInternalURLs.tests.ps1 index 59e9d0dc3..51c090df8 100644 --- a/Tests/Rules/AvoidUsingInternalURLs.tests.ps1 +++ b/Tests/Rules/AvoidUsingInternalURLs.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $violationMessage = "could be an internal URL. Using internal URL directly in the script may cause potential information discloure." $violationName = "PSAvoidUsingInternalURLs" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path diff --git a/Tests/Rules/AvoidUsingInvokeExpression.tests.ps1 b/Tests/Rules/AvoidUsingInvokeExpression.tests.ps1 index 63df90718..1ef064714 100644 --- a/Tests/Rules/AvoidUsingInvokeExpression.tests.ps1 +++ b/Tests/Rules/AvoidUsingInvokeExpression.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $violationMessage = "Invoke-Expression is used. Please remove Invoke-Expression from script and find other options instead." $violationName = "PSAvoidUsingInvokeExpression" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path diff --git a/Tests/Rules/AvoidUsingPlainTextForPassword.tests.ps1 b/Tests/Rules/AvoidUsingPlainTextForPassword.tests.ps1 index ad5860f2a..2c298a7cf 100644 --- a/Tests/Rules/AvoidUsingPlainTextForPassword.tests.ps1 +++ b/Tests/Rules/AvoidUsingPlainTextForPassword.tests.ps1 @@ -1,6 +1,6 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer -$violationMessage = [regex]::Escape('Parameter $passphrases should use SecureString, otherwise this will expose sensitive information. See ConvertTo-SecureString for more information.') +$violationMessage = [regex]::Escape("Parameter '`$passphrases' should use SecureString, otherwise this will expose sensitive information. See ConvertTo-SecureString for more information.") $violationName = "PSAvoidUsingPlainTextForPassword" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\AvoidUsingPlainTextForPassword.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/AvoidUsingReservedCharOneCharNames.ps1 b/Tests/Rules/AvoidUsingReservedCharNames.ps1 similarity index 100% rename from Tests/Rules/AvoidUsingReservedCharOneCharNames.ps1 rename to Tests/Rules/AvoidUsingReservedCharNames.ps1 diff --git a/Tests/Rules/AvoidUsingReservedCharNames.tests.ps1 b/Tests/Rules/AvoidUsingReservedCharNames.tests.ps1 new file mode 100644 index 000000000..2b5250658 --- /dev/null +++ b/Tests/Rules/AvoidUsingReservedCharNames.tests.ps1 @@ -0,0 +1,24 @@ +Import-Module PSScriptAnalyzer +$reservedCharMessage = "The cmdlet 'Use-#Reserved' uses a reserved char in its name." +$reservedCharName = "PSReservedCmdletChar" +$directory = Split-Path -Parent $MyInvocation.MyCommand.Path +$violations = Invoke-ScriptAnalyzer $directory\AvoidUsingReservedCharNames.ps1 | Where-Object {$_.RuleName -eq $reservedCharName} +$noViolations = Invoke-ScriptAnalyzer $directory\GoodCmdlet.ps1 | Where-Object {$_.RuleName -eq $reservedCharName} + +Describe "Avoid Using Reserved Char" { + Context "When there are violations" { + It "has 1 Reserved Char Violation" { + $violations.Count | Should Be 1 + } + + It "has the correct description message" { + $violations[0].Message | Should Match $reservedCharMessage + } + } + + Context "When there are no violations" { + It "has no violations" { + $noViolations.Count | Should Be 0 + } + } +} \ No newline at end of file diff --git a/Tests/Rules/AvoidUsingReservedCharOneCharNames.tests.ps1 b/Tests/Rules/AvoidUsingReservedCharOneCharNames.tests.ps1 deleted file mode 100644 index 225e3df02..000000000 --- a/Tests/Rules/AvoidUsingReservedCharOneCharNames.tests.ps1 +++ /dev/null @@ -1,48 +0,0 @@ -Import-Module ScriptAnalyzer -$oneCharMessage = "The cmdlet name O only has one character." -$reservedCharMessage = "The cmdlet Use-#Reserved uses a reserved char in its name." -$oneCharName = "PSOneChar" -$reservedCharName = "PSReservedCmdletChar" -$directory = Split-Path -Parent $MyInvocation.MyCommand.Path -$invoke = Invoke-ScriptAnalyzer $directory\AvoidUsingReservedCharOneCharNames.ps1 -$oneCharViolations = $invoke | Where-Object {$_.RuleName -eq $oneCharName} -$reservedCharViolations = $invoke | Where-Object {$_.RuleName -eq $reservedCharName} -$noViolations = Invoke-ScriptAnalyzer $directory\GoodCmdlet.ps1 -$noOneCharViolations = $noViolations | Where-Object {$_.RuleName -eq $oneCharName} -$noReservedCharViolations = $noViolations | Where-Object {$_.RuleName -eq $reservedCharName} - -Describe "Avoid Using Reserved Char" { - Context "When there are violations" { - It "has 1 Reserved Char Violation" { - $reservedCharViolations.Count | Should Be 1 - } - - It "has the correct description message" { - $reservedCharViolations[0].Message | Should Match $reservedCharMessage - } - } - - Context "When there are no violations" { - It "has no violations" { - $noOneCharViolations.Count | Should Be 0 - } - } -} - -Describe "Avoid Using One Char" { - Context "When there are violations" { - It "has 1 One Char Violation" { - $oneCharViolations.Count | Should Be 1 - } - - It "has the correct description message" { - $oneCharViolations[0].Message | Should Match $oneCharMessage - } - } - - Context "When there are no violations" { - It "has no violations" { - $noReservedCharViolations.Count | Should Be 0 - } - } -} \ No newline at end of file diff --git a/Tests/Rules/AvoidUsingWriteHost.ps1 b/Tests/Rules/AvoidUsingWriteHost.ps1 new file mode 100644 index 000000000..b9ea56344 --- /dev/null +++ b/Tests/Rules/AvoidUsingWriteHost.ps1 @@ -0,0 +1,6 @@ +Clear-Host +cls +Write-Host "aaa" +clear +[System.Console]::Write("abcdefg"); +[System.Console]::WriteLine("No console.writeline plz!"); \ No newline at end of file diff --git a/Tests/Rules/AvoidUsingWriteHost.tests.ps1 b/Tests/Rules/AvoidUsingWriteHost.tests.ps1 new file mode 100644 index 000000000..f9cd926a2 --- /dev/null +++ b/Tests/Rules/AvoidUsingWriteHost.tests.ps1 @@ -0,0 +1,25 @@ +Import-Module PSScriptAnalyzer +Set-Alias ctss ConvertTo-SecureString +$writeHostMessage = [Regex]::Escape("File 'AvoidUsingWriteHost.ps1' uses Write-Host. This is not recommended because it may not work in some hosts or there may even be no hosts at all. Use Write-Output instead.") +$writeHostName = "PSAvoidUsingWriteHost" +$directory = Split-Path -Parent $MyInvocation.MyCommand.Path +$violations = Invoke-ScriptAnalyzer $directory\AvoidUsingWriteHost.ps1 | Where-Object {$_.RuleName -eq $writeHostName} +$noViolations = Invoke-ScriptAnalyzer $directory\AvoidUsingWriteHostNoViolations.ps1 | Where-Object {$_.RuleName -eq $clearHostName} + +Describe "AvoidUsingWriteHost" { + Context "When there are violations" { + It "has 3 Write-Host violations" { + $violations.Count | Should Be 3 + } + + It "has the correct description message for Write-Host" { + $violations[0].Message | Should Match $writeHostMessage + } + } + + Context "When there are no violations" { + It "returns no violations" { + $noViolations.Count | Should Be 0 + } + } +} \ No newline at end of file diff --git a/Tests/Rules/AvoidUsingWriteHostNoViolations.ps1 b/Tests/Rules/AvoidUsingWriteHostNoViolations.ps1 new file mode 100644 index 000000000..4dadd1faa --- /dev/null +++ b/Tests/Rules/AvoidUsingWriteHostNoViolations.ps1 @@ -0,0 +1 @@ +Write-Output "This is the correct way to write output" \ No newline at end of file diff --git a/Tests/Rules/PSCredentialType.tests.ps1 b/Tests/Rules/PSCredentialType.tests.ps1 index ad5047c70..50a5f083c 100644 --- a/Tests/Rules/PSCredentialType.tests.ps1 +++ b/Tests/Rules/PSCredentialType.tests.ps1 @@ -1,5 +1,5 @@ -Import-Module ScriptAnalyzer -$violationMessage = "The Credential parameter in Credential must be of the type PSCredential." +Import-Module PSScriptAnalyzer +$violationMessage = "The Credential parameter in 'Credential' must be of the type PSCredential." $violationName = "PSUsePSCredentialType" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\PSCredentialType.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/PossibleIncorrectComparisonWithNull.tests.ps1 b/Tests/Rules/PossibleIncorrectComparisonWithNull.tests.ps1 index 66845d94f..4ef850c55 100644 --- a/Tests/Rules/PossibleIncorrectComparisonWithNull.tests.ps1 +++ b/Tests/Rules/PossibleIncorrectComparisonWithNull.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $violationMessage = [regex]::Escape('$null should be on the left side of equality comparisons.') $violationName = "PSPossibleIncorrectComparisonWithNull" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path diff --git a/Tests/Rules/ProvideCommentHelp.tests.ps1 b/Tests/Rules/ProvideCommentHelp.tests.ps1 index e6609ee25..6ea13d0ca 100644 --- a/Tests/Rules/ProvideCommentHelp.tests.ps1 +++ b/Tests/Rules/ProvideCommentHelp.tests.ps1 @@ -1,5 +1,5 @@ -Import-Module ScriptAnalyzer -$violationMessage = "The cmdlet Verb-Files does not have a help comment." +Import-Module PSScriptAnalyzer +$violationMessage = "The cmdlet 'Verb-Files' does not have a help comment." $violationName = "PSProvideCommentHelp" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\BadCmdlet.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/ProvideVerboseMessage.tests.ps1 b/Tests/Rules/ProvideVerboseMessage.tests.ps1 index 35cd8b409..6ae8c639c 100644 --- a/Tests/Rules/ProvideVerboseMessage.tests.ps1 +++ b/Tests/Rules/ProvideVerboseMessage.tests.ps1 @@ -1,5 +1,5 @@ -Import-Module ScriptAnalyzer -$violationMessage = "There is no call to Write-Verbose in the function Verb-Files." +Import-Module PSScriptAnalyzer +$violationMessage = [regex]::Escape("There is no call to Write-Verbose in the function ‘Verb-Files’.") $violationName = "PSProvideVerboseMessage" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\BadCmdlet.ps1 | Where-Object {$_.RuleName -eq $violationName} @@ -17,7 +17,7 @@ Describe "ProvideVerboseMessage" { } It "Does not count violation in DSC class" { - $dscViolations.Count | Should Be 1 + $dscViolations.Count | Should Be 0 } } diff --git a/Tests/Rules/ReturnCorrectTypesForDSCFunctions.ps1 b/Tests/Rules/ReturnCorrectTypesForDSCFunctions.tests.ps1 similarity index 97% rename from Tests/Rules/ReturnCorrectTypesForDSCFunctions.ps1 rename to Tests/Rules/ReturnCorrectTypesForDSCFunctions.tests.ps1 index 252982c11..f45163f88 100644 --- a/Tests/Rules/ReturnCorrectTypesForDSCFunctions.ps1 +++ b/Tests/Rules/ReturnCorrectTypesForDSCFunctions.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module -Verbose ScriptAnalyzer +Import-Module -Verbose PSScriptAnalyzer $violationMessageDSCResource = "Test-TargetResource function in DSC Resource should return object of type System.Boolean instead of System.Collections.Hashtable" $violationMessageDSCClass = "Test function in DSC Class FileResource should return object of type System.Boolean instead of type System.Int32" diff --git a/Tests/Rules/UseCmdletCorrectly.tests.ps1 b/Tests/Rules/UseCmdletCorrectly.tests.ps1 index 45b20fa3b..360199c58 100644 --- a/Tests/Rules/UseCmdletCorrectly.tests.ps1 +++ b/Tests/Rules/UseCmdletCorrectly.tests.ps1 @@ -1,5 +1,5 @@ -Import-Module -Verbose ScriptAnalyzer -$violationMessage = "Cmdlet Write-Warning may be used incorrectly. Please check that all mandatory parameters are supplied." +Import-Module -Verbose PSScriptAnalyzer +$violationMessage = "Cmdlet 'Write-Warning' may be used incorrectly. Please check that all mandatory parameters are supplied." $violationName = "PSUseCmdletCorrectly" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\UseCmdletCorrectly.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/UseDSCResourceFunctions.tests.ps1 b/Tests/Rules/UseDSCResourceFunctions.tests.ps1 index ae4845899..fbf791bfc 100644 --- a/Tests/Rules/UseDSCResourceFunctions.tests.ps1 +++ b/Tests/Rules/UseDSCResourceFunctions.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module -Verbose ScriptAnalyzer +Import-Module -Verbose PSScriptAnalyzer $violationMessage = "Missing 'Get-TargetResource' function. DSC Resource must implement Get, Set and Test-TargetResource functions." $classViolationMessage = "Missing 'Set' function. DSC Class must implement Get, Set and Test functions." diff --git a/Tests/Rules/UseDeclaredVarsMoreThanAssignments.tests.ps1 b/Tests/Rules/UseDeclaredVarsMoreThanAssignments.tests.ps1 index aa43b7381..61b5b34a2 100644 --- a/Tests/Rules/UseDeclaredVarsMoreThanAssignments.tests.ps1 +++ b/Tests/Rules/UseDeclaredVarsMoreThanAssignments.tests.ps1 @@ -1,5 +1,5 @@ -Import-Module ScriptAnalyzer -$violationMessage = "The variable declaredVar is assigned but never used." +Import-Module PSScriptAnalyzer +$violationMessage = "The variable 'declaredVar' is assigned but never used." $violationName = "PSUseDeclaredVarsMoreThanAssigments" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\UseDeclaredVarsMoreThanAssignments.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/UseIdenticalParametersDSC.tests.ps1 b/Tests/Rules/UseIdenticalParametersDSC.tests.ps1 index 08979d25b..fca63cb6e 100644 --- a/Tests/Rules/UseIdenticalParametersDSC.tests.ps1 +++ b/Tests/Rules/UseIdenticalParametersDSC.tests.ps1 @@ -1,4 +1,4 @@ -Import-Module ScriptAnalyzer +Import-Module PSScriptAnalyzer $violationMessage = "The Test and Set-TargetResource functions of DSC Resource must have the same parameters." $violationName = "PSDSCUseIdenticalParametersForDSC" diff --git a/Tests/Rules/UseShouldProcessCorrectly.tests.ps1 b/Tests/Rules/UseShouldProcessCorrectly.tests.ps1 index 560a68d7a..908c96d24 100644 --- a/Tests/Rules/UseShouldProcessCorrectly.tests.ps1 +++ b/Tests/Rules/UseShouldProcessCorrectly.tests.ps1 @@ -1,5 +1,5 @@ -Import-Module ScriptAnalyzer -$violationMessage = "Verb-Files has the ShouldProcess attribute but does not call ShouldProcess/ShouldContinue." +Import-Module PSScriptAnalyzer +$violationMessage = "'Verb-Files' has the ShouldProcess attribute but does not call ShouldProcess/ShouldContinue." $violationName = "PSShouldProcess" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\BadCmdlet.ps1 | Where-Object {$_.RuleName -eq $violationName} diff --git a/Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1 b/Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1 index 9f146885b..bd1e49259 100644 --- a/Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1 +++ b/Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1 @@ -1,6 +1,6 @@ -Import-Module ScriptAnalyzer -$nounViolationMessage = "The cmdlet Verb-Files uses a plural noun. A singular noun should be used instead." -$verbViolationMessage = "The cmdlet Verb-Files uses an unapproved verb." +Import-Module PSScriptAnalyzer +$nounViolationMessage = "The cmdlet 'Verb-Files' uses a plural noun. A singular noun should be used instead." +$verbViolationMessage = "The cmdlet 'Verb-Files' uses an unapproved verb." $nounViolationName = "PSUseSingularNouns" $verbViolationName = "PSUseApprovedVerbs" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path