diff --git a/Engine/Settings/core-6.1.0-linux-arm.json b/Engine/Settings/core-6.1.0-linux-arm.json index 9a43e97d0..1a9db871a 100644 --- a/Engine/Settings/core-6.1.0-linux-arm.json +++ b/Engine/Settings/core-6.1.0-linux-arm.json @@ -1388,11 +1388,6 @@ "CommandType": "Function", "ParameterSets": "[[-ConfigurationData] ] []" }, - { - "Name": "Write-Log", - "CommandType": "Function", - "ParameterSets": "[-message] [-WhatIf] [-Confirm] []" - }, { "Name": "Write-MetaConfigFile", "CommandType": "Function", diff --git a/Engine/Settings/core-6.1.0-linux.json b/Engine/Settings/core-6.1.0-linux.json index a07018167..331c74224 100644 --- a/Engine/Settings/core-6.1.0-linux.json +++ b/Engine/Settings/core-6.1.0-linux.json @@ -1388,11 +1388,6 @@ "CommandType": "Function", "ParameterSets": "[[-ConfigurationData] ] []" }, - { - "Name": "Write-Log", - "CommandType": "Function", - "ParameterSets": "[-message] [-WhatIf] [-Confirm] []" - }, { "Name": "Write-MetaConfigFile", "CommandType": "Function", diff --git a/Engine/Settings/core-6.1.0-macos.json b/Engine/Settings/core-6.1.0-macos.json index 6b95f2588..b69187140 100644 --- a/Engine/Settings/core-6.1.0-macos.json +++ b/Engine/Settings/core-6.1.0-macos.json @@ -1388,11 +1388,6 @@ "CommandType": "Function", "ParameterSets": "[[-ConfigurationData] ] []" }, - { - "Name": "Write-Log", - "CommandType": "Function", - "ParameterSets": "[-message] [-WhatIf] [-Confirm] []" - }, { "Name": "Write-MetaConfigFile", "CommandType": "Function", diff --git a/Engine/Settings/core-6.1.0-windows.json b/Engine/Settings/core-6.1.0-windows.json index 1dab0a657..34969b4c1 100644 --- a/Engine/Settings/core-6.1.0-windows.json +++ b/Engine/Settings/core-6.1.0-windows.json @@ -1689,11 +1689,6 @@ "CommandType": "Function", "ParameterSets": "[-Value] [-Path] []" }, - { - "Name": "Write-Log", - "CommandType": "Function", - "ParameterSets": "[-message] [-WhatIf] [-Confirm] []" - }, { "Name": "Write-MetaConfigFile", "CommandType": "Function", diff --git a/Tests/Rules/AvoidOverwritingBuiltInCmdlets.tests.ps1 b/Tests/Rules/AvoidOverwritingBuiltInCmdlets.tests.ps1 index 2a111af0a..2ca542924 100644 --- a/Tests/Rules/AvoidOverwritingBuiltInCmdlets.tests.ps1 +++ b/Tests/Rules/AvoidOverwritingBuiltInCmdlets.tests.ps1 @@ -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 ' -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*' + } + } + }