Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion Rules/UseIdenticalMandatoryParametersDSC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private IDictionary<string, string> GetKeys(string fileName)

var cimClass = cimClasses?.FirstOrDefault();
var cimSuperClassProperties = new HashSet<string>(
cimClass?.CimSuperClass.CimClassProperties.Select(p => p.Name) ??
cimClass?.CimSuperClass?.CimClassProperties.Select(cimPropertyDeclaration => cimPropertyDeclaration.Name) ??
Enumerable.Empty<string>());

return cimClass?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#requires -Version 4.0 -Modules CimCmdlets

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[ClassVersion("1.0.0")]
class ClassWithNoParent
{
[Write] Boolean Anonymous;
};

9 changes: 9 additions & 0 deletions Tests/Rules/UseIdenticalMandatoryParametersForDSC.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $badResourceFilepath = [System.IO.Path]::Combine(
'MSFT_WaitForAnyNoIdenticalMandatoryParameter.psm1');
$goodResourceFilepath = [System.IO.Path]::Combine($resourceBasepath,'MSFT_WaitForAny','MSFT_WaitForAny.psm1');

$noparentClassFilepath = [System.IO.Path]::Combine($resourceBasepath,'ClassWithNoParent','ClassWithNoParent.psm1');

Describe "UseIdenticalMandatoryParametersForDSC" {
Context "When a mandatory parameters are not present" {
Expand All @@ -33,4 +34,12 @@ Describe "UseIdenticalMandatoryParametersForDSC" {
$violations.Count | Should -Be 0
}
}

Context "When a CIM class has no parent" {
# regression test for #982 - just check no uncaught exception
It "Should find no violations, and throw no exceptions" {
$violations = Invoke-ScriptAnalyzer -Path $noParentClassFilepath -IncludeRule $ruleName
$violations.Count | Should -Be 0
}
}
}