Skip to content

Commit

Permalink
Fix safecomands spelling (pester#1800)
Browse files Browse the repository at this point in the history
  • Loading branch information
asears authored Dec 3, 2020
1 parent 148d39a commit a9355cc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions Pester.BuildAnalyzerRules/Pester.BuildAnalyzerRules.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
$SafeCommands = & { . "$PSScriptRoot/../src/functions/Pester.SafeCommands.ps1"; $Script:SafeCommands }
# Workaround as RuleSuppressionID-based suppression is bugged. returns error.
# Should be replaced with the following line when PSScriptAnalyzer is fixed. See Invoke-Pester
# [Diagnostics.CodeAnalysis.SuppressMessageAttribute('Pester.BuildAnalyzerRules\Measure-SafeComands', 'Remove-Variable')]
# [Diagnostics.CodeAnalysis.SuppressMessageAttribute('Pester.BuildAnalyzerRules\Measure-SafeCommands', 'Remove-Variable')]
$IgnoreUnsafeCommands = @('Remove-Variable')
function Measure-SafeComands {
function Measure-SafeCommands {
<#
.SYNOPSIS
Should use $SafeCommand-variant of external function when available.
.DESCRIPTION
Pester module defines a $SafeCommands dictionary for external commands to avoid hijacking. To fix a violation of this rule, update the call to use SafeCoomands variant, ex. `& $SafeCommands['CommandName'] -Param1 Value1`.
Pester module defines a $SafeCommands dictionary for external commands to avoid hijacking. To fix a violation of this rule, update the call to use SafeCommands variant, ex. `& $SafeCommands['CommandName'] -Param1 Value1`.
.EXAMPLE
Measure-SafeComands -CommandAst $CommandAst
Measure-SafeCommands -CommandAst $CommandAst
.INPUTS
[System.Management.Automation.Language.CommandAst]
.OUTPUTS
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord[]]
.NOTES
None
#>
# TODO This warning is currently thrown for SafeCommand
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseOutputTypeCorrectly", "")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Pester.BuildAnalyzerRules\Measure-SafeCommands", "")]
[CmdletBinding()]
[OutputType([Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
Param
Expand Down
2 changes: 1 addition & 1 deletion src/Pester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ function Invoke-Pester {
about_Pester
#>
# Currently doesn't work. $IgnoreUnsafeCommands filter used in rule as workaround
# [Diagnostics.CodeAnalysis.SuppressMessageAttribute('Pester.BuildAnalyzerRules\Measure-SafeComands', 'Remove-Variable', Justification = 'Remove-Variable can't remove "optimized variables" when using "alias" for Remove-Variable.')]
# [Diagnostics.CodeAnalysis.SuppressMessageAttribute('Pester.BuildAnalyzerRules\Measure-SafeCommands', 'Remove-Variable', Justification = 'Remove-Variable can't remove "optimized variables" when using "alias" for Remove-Variable.')]
[CmdletBinding(DefaultParameterSetName = 'Simple')]
param(
[Parameter(Position = 0, Mandatory = 0, ParameterSetName = "Simple")]
Expand Down
2 changes: 1 addition & 1 deletion src/functions/New-Fixture.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Describe "#name#" {
}

function Create-File {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('Pester.BuildAnalyzerRules\Measure-SafeComands', 'Write-Warning', Justification = 'Mocked in unit test for New-Fixture.')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('Pester.BuildAnalyzerRules\Measure-SafeCommands', 'Write-Warning', Justification = 'Mocked in unit test for New-Fixture.')]
param($Path, $Name, $Content)
if (-not (& $SafeCommands['Test-Path'] -Path $Path)) {
& $SafeCommands['New-Item'] -ItemType Directory -Path $Path | & $SafeCommands['Out-Null']
Expand Down
2 changes: 1 addition & 1 deletion src/functions/Pester.SafeCommands.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $safeCommandLookupParameters = @{
}

# Suppress from ScriptAnalyzer rule when possible in root of script (future PSSA release?)
# [Diagnostics.CodeAnalysis.SuppressMessageAttribute('Pester.BuildAnalyzerRules\Measure-SafeComands', 'Get-Command', Justification = 'Used to generate SafeCommands list used for AnalyzerRule.')]
# [Diagnostics.CodeAnalysis.SuppressMessageAttribute('Pester.BuildAnalyzerRules\Measure-SafeCommands', 'Get-Command', Justification = 'Used to generate SafeCommands list used for AnalyzerRule.')]
$Get_Command = Get-Command Get-Command -CommandType Cmdlet -ErrorAction 'Stop'
$script:SafeCommands = @{
'Get-Command' = $Get_Command
Expand Down

0 comments on commit a9355cc

Please sign in to comment.