Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Engine/Settings/core-6.1.0-linux-arm.json
Original file line number Diff line number Diff line change
Expand Up @@ -1388,11 +1388,6 @@
"CommandType": "Function",
"ParameterSets": "[[-ConfigurationData] <hashtable>] [<CommonParameters>]"
},
{
"Name": "Write-Log",
"CommandType": "Function",
"ParameterSets": "[-message] <string> [-WhatIf] [-Confirm] [<CommonParameters>]"
},
{
"Name": "Write-MetaConfigFile",
"CommandType": "Function",
Expand Down
5 changes: 0 additions & 5 deletions Engine/Settings/core-6.1.0-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -1388,11 +1388,6 @@
"CommandType": "Function",
"ParameterSets": "[[-ConfigurationData] <hashtable>] [<CommonParameters>]"
},
{
"Name": "Write-Log",
"CommandType": "Function",
"ParameterSets": "[-message] <string> [-WhatIf] [-Confirm] [<CommonParameters>]"
},
{
"Name": "Write-MetaConfigFile",
"CommandType": "Function",
Expand Down
5 changes: 0 additions & 5 deletions Engine/Settings/core-6.1.0-macos.json
Original file line number Diff line number Diff line change
Expand Up @@ -1388,11 +1388,6 @@
"CommandType": "Function",
"ParameterSets": "[[-ConfigurationData] <hashtable>] [<CommonParameters>]"
},
{
"Name": "Write-Log",
"CommandType": "Function",
"ParameterSets": "[-message] <string> [-WhatIf] [-Confirm] [<CommonParameters>]"
},
{
"Name": "Write-MetaConfigFile",
"CommandType": "Function",
Expand Down
5 changes: 0 additions & 5 deletions Engine/Settings/core-6.1.0-windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -1689,11 +1689,6 @@
"CommandType": "Function",
"ParameterSets": "[-Value] <string> [-Path] <string> [<CommonParameters>]"
},
{
"Name": "Write-Log",
"CommandType": "Function",
"ParameterSets": "[-message] <string> [-WhatIf] [-Confirm] [<CommonParameters>]"
},
{
"Name": "Write-MetaConfigFile",
"CommandType": "Function",
Expand Down
37 changes: 37 additions & 0 deletions Tests/Rules/AvoidOverwritingBuiltInCmdlets.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,41 @@ describe 'AvoidOverwritingBuiltInCmdlets' {
}
}

context 'Write-Log is not a built-in command in PowerShell 6.1 profiles (#2146)' {
BeforeAll {
$writeLogScript = @'
function Write-Log {
}

function Get-ChildItem {
}
'@
}

it 'should only flag Get-ChildItem with default settings (PowerShellVersion not specified)' {
$s = @{ IncludeRules = @($ruleName) }
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $writeLogScript -Settings $s
$violations.Message | Should -BeLike '*Get-ChildItem*'
$violations.Message | Should -Not -BeLike '*Write-Log*'
@($violations).Count | Should -Be 1
}

it 'should only flag Get-ChildItem for <profile>' -TestCases @(
@{ profile = 'core-6.1.0-windows' }
@{ profile = 'core-6.1.0-linux' }
@{ profile = 'core-6.1.0-linux-arm' }
@{ profile = 'core-6.1.0-macos' }
) {
param($profile)
$s = @{
IncludeRules = @($ruleName)
Rules = @{ $ruleName = @{ PowerShellVersion = @($profile) } }
}
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $writeLogScript -Settings $s
$violations.Count | Should -Be 1
$violations.Message | Should -BeLike '*Get-ChildItem*'
$violations.Message | Should -Not -BeLike '*Write-Log*'
}
}

}