Skip to content

Commit d84b024

Browse files
committed
PSAvoidUsingCmdletAliases
1 parent f288303 commit d84b024

6 files changed

Lines changed: 33 additions & 11 deletions

PSScriptAnalyzerSettings.psd1

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
@{
2-
IncludeRules=@('PSProvideCommentHelp',
3-
'PSAvoidUsingWriteHost')
2+
IncludeRules=@('PSUseApprovedVerbs',
3+
'PSReservedCmdletChar',
4+
'PSReservedParams',
5+
'PSShouldProcess',
6+
'PSUseShouldProcessForStateChangingFunctions',
7+
'PSUseSingularNouns',
8+
'PSMissingModuleManifestField',
9+
'PSAvoidDefaultValueSwitchParameter',
10+
'PSAvoidUsingCmdletAliases',
11+
'PSAvoidUsingWMICmdlet',
12+
'PSAvoidUsingEmptyCatchBlock',
13+
'PSUseCmdletCorrectly',
14+
'PSUseShouldProcessForStateChangingFunctions',
15+
'PSAvoidUsingPositionalParameters',
16+
'PSAvoidGlobalVars',
17+
'PSUseDeclaredVarsMoreThanAssignments',
18+
'PSAvoidUsingInvokeExpression',
19+
'PSAvoidUsingPlainTextForPassword',
20+
'PSAvoidUsingComputerNameHardcoded',
21+
'PSAvoidUsingConvertToSecureStringWithPlainText',
22+
'PSUsePSCredentialType',
23+
'PSAvoidUsingUserNameAndPasswordParams',
24+
'PSDSC*'
25+
)
426
}

src/private/Convert-ArrayToRegex.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Convert-ArrayToRegex {
1919
'^(' + ($Items -join '|') + ')$'
2020
}
2121
else {
22-
'^(' + (($Items | %{[regex]::Escape($_)}) -join '|') + ')$'
22+
'^(' + (($Items | ForEach-Object{[regex]::Escape($_)}) -join '|') + ')$'
2323
}
2424
}
2525
else {

src/private/Get-BuildFilePath.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
function Get-BuildFilePath {
2-
$BuildPath = (Get-ChildItem -File -Filter "*.buildenvironment.json" -Path '.\','..\','.\build\' -ErrorAction:SilentlyContinue | select -First 1).FullName
2+
$BuildPath = (Get-ChildItem -File -Filter "*.buildenvironment.json" -Path '.\','..\','.\build\' -ErrorAction:SilentlyContinue | Select-Object -First 1).FullName
33
}

src/private/Get-FunctionParameter.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function Get-FunctionParameter {
7878
$functions = $CodeBlock | Get-Function -Name $Name
7979
if (-not $IncludeEmbedded) {
8080
Write-Verbose "$($FunctionName): Not including embedded functions."
81-
$functions = $functions | where {-not $_.IsEmbedded}
81+
$functions = $functions | Where-Object {-not $_.IsEmbedded}
8282
}
8383

8484
Foreach ($f in $functions) {
@@ -93,7 +93,7 @@ function Get-FunctionParameter {
9393
'ParameterType' = $ParamType[0].typeName.FullName
9494
}
9595
# This will add in any other parameter attributes if they are specified (default attributes are thus not included and output may not be normalized)
96-
$p.FindAll($paramattributes, $true) | Foreach {
96+
$p.FindAll($paramattributes, $true) | ForEach-Object {
9797
$OutProps.($_.ArgumentName) = $_.Argument.Value
9898
}
9999
$Output += New-Object -TypeName PSObject -Property $OutProps
@@ -114,7 +114,7 @@ function Get-FunctionParameter {
114114
'ParameterType' = $ParamType[0].typeName.FullName
115115
}
116116
# This will add in any other parameter attributes if they are specified (default attributes are thus not included and output may not be normalized)
117-
$p.FindAll($paramattributes, $true) | Foreach {
117+
$p.FindAll($paramattributes, $true) | ForEach-Object {
118118
$OutProps.($_.ArgumentName) = $_.Argument.Value
119119
}
120120
$Output += New-Object -TypeName PSObject -Property $OutProps

src/private/New-CommentBasedHelp.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@
7878
$OutCBH = @{}
7979
$OutCBH.FunctionName = $f
8080
[string]$OutParams = ''
81-
$fparams = @($AllParams | Where {$_.FunctionName -eq $f} | Sort-Object -Property Position)
81+
$fparams = @($AllParams | Where-Object {$_.FunctionName -eq $f} | Sort-Object -Property Position)
8282
if ($fparams.count -gt 0) {
83-
$fparams | foreach {
83+
$fparams | ForEach-Object {
8484
$ParamHelpMessage = if ([string]::IsNullOrEmpty($_.HelpMessage)) { $_.ParameterName + " explanation`n`r`n`r"} else {$_.HelpMessage + "`n`r`n`r"}
8585

8686
$OutParams += $CBH_PARAM -replace '%%PARAM%%',$_.ParameterName -replace '%%PARAMHELP%%',$ParamHelpMessage

src/public/Add-PublicFunction.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function Add-PublicFunction {
6666
$PublicFunctionSrc = Join-Path $BuildEnvPath $BuildEnvInfo.PublicFunctionSource
6767
$TemplatePath = Join-Path $BuildEnvPath $BuildEnvInfo.FunctionTemplates
6868
$TemplateLookup = @{}
69-
Get-ChildItem -Path $TemplatePath -Filter '*.tem' | Foreach {
69+
Get-ChildItem -Path $TemplatePath -Filter '*.tem' | ForEach-Object {
7070
$TemplateLookup.($_.BaseName) = $_.FullName
7171
}
7272
$BuildEnvVars = (Get-Member -Type 'NoteProperty' -InputObject $LoadedBuildEnv).Name
@@ -101,7 +101,7 @@ function Add-PublicFunction {
101101
$NewFunctionOutput = $TemplateData -replace '%%FunctionName%%', $FunctionName
102102

103103
# Next replace any other variables found in our build environment file that exist in the template.
104-
$BuildEnvVars | Foreach {
104+
$BuildEnvVars | ForEach-Object {
105105
Write-Verbose " Replacing %%$($_)%% with $($BuildEnvInfo.$_) if found in template..."
106106
$NewFunctionOutput = $NewFunctionOutput -replace "%%$($_)%%", ($BuildEnvInfo.$_ -join ',')
107107
}

0 commit comments

Comments
 (0)