-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule 'PSDSCUseIdenticalMandatoryParametersForDSC' throws incorrect error #1192
Comments
@ykuijs Thanks for reporting it. I can repro and approve that behaviour changed between 1.17.1 and 1.18.0 and I could already boil it down to a one line change in #1046 |
For several resources in SharePointDsc are we using subclasses, for example https://github.com/PowerShell/SharePointDsc/tree/dev/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp As you can see in the schema of SPExcelServiceApp, the MSFT_SPExcelFileLocation class is defined in the schema with a key parameter called Address. However this class is used as EmbeddedInstance for the parameter TrustedFileLocations. The TrustedFileLocations parameter IS declared in all *-TargetResource methods. In PSSA v1.17 this setup was fine, but v1.18 PSSA now throws an error for all parameters in the subclass that are specified as "Key" or "Required" that they are not present in the *-TargetResource methods, which they are not supposed to. Since we "borrowed" this setup from xWebsite in xWebAdministration, I guess tests in new PRs for this resource will fail as well. I hope this explains the issue a little bit more. Let me know if you need more info! |
FYI: As a workaround (so our PRs aren't blocked) I have disabled this specific test for the affected resources. If you fork SharePointDsc and run Invoke-ScriptAnalyzer on one of the resources to test/reproduce, you first have to remove the following line from all methods:
|
Hmm, actually, by repro-ing locally (by cd-ing to the |
Just tried to reproduce and you are absolutely correct. I also get the NullReferenceException with v1.17.1. I am not very good with C# (I am an IT Pro guy, with a small Dev background :-)), but will try take a look at it and hopefully can figure out what needs to get changed. |
I have found where the issue is coming from: PSScriptAnalyzer/Rules/UseIdenticalMandatoryParametersDSC.cs Lines 259 to 274 in 23a18f6
In our case, but also in xWebsite, the first class in the file is the subclass. When switching the order (placing the main class first), the rule isn't triggered. Now for the solution: What I think should happen, is that the code should select the class which has "OMI_BaseResource" as CimSuperClassName instead of simply the first one: Unfortunately my C# skills aren't good enough to implement this myself. @bergmeister, can you assist with implementing this? |
Awesome work. Yes, I'm happy to start implementing a fix to that, I will tag you in the PR when I'll open it (I hope in 1-2 days). This is a great example of team work :-) |
@ykuijs PSSA 1.18.1 has finally been released :-) |
@bergmeister Thanks for letting me know! |
Steps to reproduce
Since the recent release, several tests in the SharePointDsc module fail with the following error:
The following PSScriptAnalyzer rule 'PSDSCUseIdenticalMandatoryParametersForDSC' errors need to be fixed:
MSFT_SPSearchContentSource.psm1 (Line 1): The 'Required' parameter 'ScheduleType' is not present in 'Get-TargetResource' DSC resource function(s).
MSFT_SPSearchContentSource.psm1 (Line 219): The 'Required' parameter 'ScheduleType' is not present in 'Set-TargetResource' DSC resource function(s).
MSFT_SPSearchContentSource.psm1 (Line 683): The 'Required' parameter 'ScheduleType' is not present in 'Test-TargetResource' DSC resource function(s).
The specified parameter however are parameters in subclasses, which should not be present in the *-TargetResource methods.
Expected behavior
Not complaint about the missing parameters
Actual behavior
Gives false positives:
Environment data
Tests are running in AppVeyor with PSv5.1 and v1.18 of PSScriptAnalyzer
The text was updated successfully, but these errors were encountered: