Closed johlju closed 3 years ago
This was added in the working branch add-script-analyzer-rule-for-Import-SQLPSModule and in the folder AnalyzerRules. But the problem is that the CustomRulePath
in the Script Analyzer settings file analyzersettings.psd1
does not allow an array of paths:
When adding above configuration all the custom rules stops working.
So only way to support this is to add it do DscResource.Analysis, or make a Pester test that runs Invoke-ScriptAnalyzer
with just this particular custom rule. The former is not a good choice since this rule is limited to SqlServerDsc and would need to made more generic like adding the option to configure it through the Script Analyzer settings file (not sure how to do that). So the only viable option right now is to create a QA test that runs this custom rule.
I have it working with multiple paths in the Script Analyzer settings file. The problem was that the rules need to be exported by a module of in a module script file. So this works:
@{
CustomRulePath = @(
'.\output\RequiredModules\DscResource.AnalyzerRules'
'.\source\AnalyzerRules\SqlServerDsc.AnalyzerRules.psm1'
)
IncludeRules = @(
# DSC Resource Kit style guideline rules.
...
# Additional rules
...
'Measure-*'
)
}
In the issue https://github.com/dsccommunity/SqlServerDsc/issues/1680#issuecomment-769723694 there was an issue reported that the resource failed due to the SMO assemblies was not loaded. This was due to that
Import-SQLPSModule
was not called.Suggest adding a PSScriptAnalyzer rule that validates that each
*-TargetResource
function do callImport-SQLPSModule
. If a function is not suppose to callImport-SQLPSModule
then it would be possible to suppress the analyzer rule for that particular function.