Skip to content
Merged
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
7 changes: 6 additions & 1 deletion Rules/UseCompatibleCmdlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private struct RuleParameters
private bool hasInitializationError;
private string reference;
private readonly string defaultReference = "desktop-5.1.14393.206-windows";
private readonly string alternativeDefaultReference = "core-6.0.2-windows";
private RuleParameters ruleParameters;

public UseCompatibleCmdlets()
Expand Down Expand Up @@ -274,6 +275,10 @@ private void SetupCmdletsDictionary()

ruleParameters.compatibility = compatibilityList.ToArray();
reference = defaultReference;
if (compatibilityList.Count == 1 && compatibilityList[0] == defaultReference)
{
reference = alternativeDefaultReference;
}
#if DEBUG
// Setup reference file
object referenceObject;
Expand Down Expand Up @@ -326,7 +331,7 @@ private void SetupCmdletsDictionary()
return;
}

var extentedCompatibilityList = compatibilityList.Concat(Enumerable.Repeat(reference, 1));
var extentedCompatibilityList = compatibilityList.Union(Enumerable.Repeat(reference, 1));
foreach (var compat in extentedCompatibilityList)
{
string psedition, psversion, os;
Expand Down
13 changes: 10 additions & 3 deletions Tests/Rules/UseCompatibleCmdlets.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ Describe "UseCompatibleCmdlets" {
process
{
It ("found {0} violations for '{1}'" -f $expectedViolations, $command) {
Invoke-ScriptAnalyzer -ScriptDefinition $command -IncludeRule $ruleName -Settings $settings | `
Get-Count | `
Should -Be $expectedViolations
$warnings = Invoke-ScriptAnalyzer -ScriptDefinition $command -IncludeRule $ruleName -Settings $settings
$warnings.Count | Should -Be $expectedViolations
$warnings | ForEach-Object {
$_.RuleName | Should -Be 'PSUseCompatibleCmdlets'
}
}
}
}
Expand All @@ -54,4 +56,9 @@ Describe "UseCompatibleCmdlets" {
@("Start-VM", "New-SmbShare", "Get-Disk") | `
Test-Command -Settings $settings -ExpectedViolations 1
}

Context "Default reference can also be used as target platform" {
$settings = @{rules=@{PSUseCompatibleCmdlets=@{compatibility=@("desktop-5.1.14393.206-windows")}}}
@("Remove-Service") | Test-Command -Settings $settings -ExpectedViolations 1
}
}