dsccommunity / DscResource.Test

Module to test your Projects against the HQRM guidelines
MIT License
5 stars 8 forks source link

How to suppress a PSScriptAnalyzer rule? #135

Closed raandree closed 2 months ago

raandree commented 2 months ago

I want to use this module for checking the code in DscBuildHelpers. Some functions however are much more helpful if they write something to the console. I am trying to suppress the rule 'PSAvoidUsingWriteHost' by following this recommendation. Now I have this error:

[-] Should not suppress the required rule 'PSAvoidUsingWriteHost' 3ms (2ms|0ms)
    Expected collection PSAvoidUsingWriteHost to not contain 'PSAvoidUsingWriteHost', because no module script file should suppress a required Script Analyzer rule, but it was found.        
    at $_ | Should -Not -BeIn $suppressedRuleNames -Because 'no module script file should suppress a required Script Analyzer rule', D:\DscBuildHelpers\output\RequiredModules\DscResource.Test\0.16.3\Tests\QA\PSSAResource.common.v5.Tests.ps1:172
    at <ScriptBlock>, D:\DscBuildHelpers\output\RequiredModules\DscResource.Test\0.16.3\Tests\QA\PSSAResource.common.v5.Tests.ps1:172

How can I allow calls to Write-Host and still make use of this module?

dan-hughes commented 2 months ago

Currently it doesn't look like you can supress a specific rule if it's marked as required.

You could add the following into the build.yml as a work around.

Pester:
  ExcludeTag:
    - RequiredPSSA
raandree commented 2 months ago

Thanks, @dan-hughes, that did it.

johlju commented 2 months ago

I also pushed a new full release yesterday, have that resolved this as well?

dan-hughes commented 2 months ago

@johlju, I'm not sure the fix I made will resolve this as that for Pester 4. It doesn't look like required rules can be suppressed, especially in the Pester 5 script version.