PowerShell / Crescendo

a module for wrapping native applications in a PowerShell function and module
MIT License
397 stars 37 forks source link

Using ScriptAnalyzer with exported module generates a ton of output #200

Closed DennisL68 closed 1 year ago

DennisL68 commented 1 year ago

Prerequisites

Steps to reproduce

When running the generated code using ScriptAnalyzer I'm greated with a lot of Warnings and Information output.

It's very tedious to walk through the code by hand after each export.

RuleName                             Severity    ScriptName               Line Message
--------                             --------    ----------               ---- -------
PSAvoidTrailingWhitespace            Information PSConfig.psd1            72   Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psd1            73   Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psd1            74   Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psd1            75   Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psd1            76   Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psm1            5    Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psm1            204  Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psm1            206  Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psm1            212  Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psm1            214  Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psm1            425  Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psm1            746  Line has trailing whitespace
PSAvoidTrailingWhitespace            Information PSConfig.psm1            751  Line has trailing whitespace
PSUseSingularNouns                   Warning     PSConfig.psm1            338  The cmdlet 'Invoke-PSConfigRegi
                                                                               sterFeatures' uses a plural
                                                                               noun. A singular noun should
                                                                               be used instead.
PSUseSingularNouns                   Warning     PSConfig.psm1            434  The cmdlet 'Invoke-PSConfigSecu
                                                                               reResourceFiles' uses a plural
                                                                               noun. A singular noun should
                                                                               be used instead.
PSUseSingularNouns                   Warning     PSConfig.psm1            529  The cmdlet 'Invoke-PSConfigRegi
                                                                               sterServices' uses a plural
                                                                               noun. A singular noun should
                                                                               be used instead.
PSUseDeclaredVarsMoreThanAssignments Warning     PSConfig.psm1            743  The variable 'logs' is
                                                                               assigned but never used.
PSShouldProcess                      Warning     PSConfig.psm1            180  'Invoke-PSConfigProductUpgrade'
                                                                                calls
                                                                               ShouldProcess/ShouldContinue
                                                                               but does not have the
                                                                               ShouldProcess attribute.
PSShouldProcess                      Warning     PSConfig.psm1            306  'Invoke-PSConfigInstallApplicat
                                                                               ionContent' calls
                                                                               ShouldProcess/ShouldContinue
                                                                               but does not have the
                                                                               ShouldProcess attribute.
PSShouldProcess                      Warning     PSConfig.psm1            401  'Invoke-PSConfigRegisterFeature
                                                                               s' calls
                                                                               ShouldProcess/ShouldContinue
                                                                               but does not have the
                                                                               ShouldProcess attribute.
PSShouldProcess                      Warning     PSConfig.psm1            497  'Invoke-PSConfigSecureResourceF
                                                                               iles' calls
                                                                               ShouldProcess/ShouldContinue
                                                                               but does not have the
                                                                               ShouldProcess attribute.
PSShouldProcess                      Warning     PSConfig.psm1            593  'Invoke-PSConfigRegisterService
                                                                               s' calls
                                                                               ShouldProcess/ShouldContinue
                                                                               but does not have the
                                                                               ShouldProcess attribute.
PSShouldProcess                      Warning     PSConfig.psm1            702  'Invoke-PSConfigSafeProductUpgr
                                                                               ade' calls
                                                                               ShouldProcess/ShouldContinue
                                                                               but does not have the
                                                                               ShouldProcess attribute.

Expected behavior

Invoke-ScriptAnalyzer *

Actual behavior

Invoke-ScriptAnalyzer *

RuleName                             Severity    ScriptName               Line Message
--------                             --------    ----------               ---- -------
...

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.10
PSEdition                      Core
GitCommitId                    7.2.10
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

1.1.0-Preview01

Visuals

No response

theJasonHelmick commented 1 year ago

Hi @DennisL68 -- thank you for the issue! I can see we can improve the trailing white space in the generated code to help make the readability better. Thank you for the suggestion!

JamesWTruher commented 1 year ago

trailing whitespace in generator fixed in commit 40d62a6d4010dc0160f025a5317966c6ef623879

theJasonHelmick commented 1 year ago

Fixed/closed - in release: https://www.powershellgallery.com/packages/Microsoft.PowerShell.Crescendo/1.1.0-RC1

nlsdg commented 1 year ago

@DennisL68 The warnings about plural noun you need to fix in your own code (the source .json). Change the value for Noun for the indicated commands and regerate the module. (for example: change PSConfigRegisterServices to PSConfigRegisterService)

The warnings about ShouldProcess/ShouldContinue require a fix in Crescendo itself. It only checks the SupportsShouldProcess from the .json to see if it should add the SupportsShouldProcess declaration to the generated cmdlet. The generated code always get the $PSCmdlet.ShouldProcess call, instead of being added conditionally. This issue should be reopened (as it didn't address the complete orginal issue) or a new issue should be opened.