From 8b170c8a21dd8e4a7bf089f14b42baed52c32541 Mon Sep 17 00:00:00 2001 From: Daniel Hughes <2237515+dan-hughes@users.noreply.github.com> Date: Sun, 17 Nov 2024 14:22:27 +0000 Subject: [PATCH] Fix HQRM with preview DscResource.ScriptAnalyzer Rules (#134) --- .vscode/analyzersettings.psd1 | 101 +++++++++++------- CHANGELOG.md | 14 +++ RequiredModules.psd1 | 32 +++--- build.yaml | 23 ++-- source/Public/Assert-ElevatedUser.ps1 | 3 +- .../Public/Set-DscMachineRebootRequired.ps1 | 4 +- 6 files changed, 108 insertions(+), 69 deletions(-) diff --git a/.vscode/analyzersettings.psd1 b/.vscode/analyzersettings.psd1 index b1bdba8..799e0d0 100644 --- a/.vscode/analyzersettings.psd1 +++ b/.vscode/analyzersettings.psd1 @@ -1,44 +1,73 @@ @{ - CustomRulePath = '.\output\RequiredModules\DscResource.AnalyzerRules' + CustomRulePath = @( + '.\output\RequiredModules\DscResource.AnalyzerRules' + '.\output\RequiredModules\Indented.ScriptAnalyzerRules' + ) IncludeDefaultRules = $true - IncludeRules = @( + IncludeRules = @( # DSC Resource Kit style guideline rules. - 'PSAvoidDefaultValueForMandatoryParameter', - 'PSAvoidDefaultValueSwitchParameter', - 'PSAvoidInvokingEmptyMembers', - 'PSAvoidNullOrEmptyHelpMessageAttribute', - 'PSAvoidUsingCmdletAliases', - 'PSAvoidUsingComputerNameHardcoded', - 'PSAvoidUsingDeprecatedManifestFields', - 'PSAvoidUsingEmptyCatchBlock', - 'PSAvoidUsingInvokeExpression', - 'PSAvoidUsingPositionalParameters', - 'PSAvoidShouldContinueWithoutForce', - 'PSAvoidUsingWMICmdlet', - 'PSAvoidUsingWriteHost', - 'PSDSCReturnCorrectTypesForDSCFunctions', - 'PSDSCStandardDSCFunctionsInResource', - 'PSDSCUseIdenticalMandatoryParametersForDSC', - 'PSDSCUseIdenticalParametersForDSC', - 'PSMisleadingBacktick', - 'PSMissingModuleManifestField', - 'PSPossibleIncorrectComparisonWithNull', - 'PSProvideCommentHelp', - 'PSReservedCmdletChar', - 'PSReservedParams', - 'PSUseApprovedVerbs', - 'PSUseCmdletCorrectly', - 'PSUseOutputTypeCorrectly', - 'PSAvoidGlobalVars', - 'PSAvoidUsingConvertToSecureStringWithPlainText', - 'PSAvoidUsingPlainTextForPassword', - 'PSAvoidUsingUsernameAndPasswordParams', - 'PSDSCUseVerboseMessageInDSCResource', - 'PSShouldProcess', - 'PSUseDeclaredVarsMoreThanAssignments', - 'PSUsePSCredentialType', + 'PSAvoidDefaultValueForMandatoryParameter' + 'PSAvoidDefaultValueSwitchParameter' + 'PSAvoidInvokingEmptyMembers' + 'PSAvoidNullOrEmptyHelpMessageAttribute' + 'PSAvoidUsingCmdletAliases' + 'PSAvoidUsingComputerNameHardcoded' + 'PSAvoidUsingDeprecatedManifestFields' + 'PSAvoidUsingEmptyCatchBlock' + 'PSAvoidUsingInvokeExpression' + 'PSAvoidUsingPositionalParameters' + 'PSAvoidShouldContinueWithoutForce' + 'PSAvoidUsingWMICmdlet' + 'PSAvoidUsingWriteHost' + 'PSDSCReturnCorrectTypesForDSCFunctions' + 'PSDSCStandardDSCFunctionsInResource' + 'PSDSCUseIdenticalMandatoryParametersForDSC' + 'PSDSCUseIdenticalParametersForDSC' + 'PSMisleadingBacktick' + 'PSMissingModuleManifestField' + 'PSPossibleIncorrectComparisonWithNull' + 'PSProvideCommentHelp' + 'PSReservedCmdletChar' + 'PSReservedParams' + 'PSUseApprovedVerbs' + 'PSUseCmdletCorrectly' + 'PSUseOutputTypeCorrectly' + 'PSAvoidGlobalVars' + 'PSAvoidUsingConvertToSecureStringWithPlainText' + 'PSAvoidUsingPlainTextForPassword' + 'PSAvoidUsingUsernameAndPasswordParams' + 'PSDSCUseVerboseMessageInDSCResource' + 'PSShouldProcess' + 'PSUseDeclaredVarsMoreThanAssignments' + 'PSUsePSCredentialType' + + # Additional rules from the module ScriptAnalyzer + 'PSUseConsistentWhitespace' + 'UseCorrectCasing' + 'PSPlaceOpenBrace' + 'PSPlaceCloseBrace' + 'AlignAssignmentStatement' + 'AvoidUsingDoubleQuotesForConstantString' + 'UseShouldProcessForStateChangingFunctions' + # Rules from the modules DscResource.AnalyzerRules 'Measure-*' + + # Rules from the module Indented.ScriptAnalyzerRules + 'AvoidCreatingObjectsFromAnEmptyString' + 'AvoidDashCharacters' + 'AvoidEmptyNamedBlocks' + 'AvoidFilter' + 'AvoidHelpMessage' + 'AvoidNestedFunctions' + 'AvoidNewObjectToCreatePSObject' + 'AvoidParameterAttributeDefaultValues' + 'AvoidProcessWithoutPipeline' + 'AvoidSmartQuotes' + 'AvoidThrowOutsideOfTry' + 'AvoidWriteErrorStop' + 'AvoidWriteOutput' + 'UseSyntacticallyCorrectExamples' ) } diff --git a/CHANGELOG.md b/CHANGELOG.md index 4598821..73ad47e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Added Indented.AnalyzerRules and config +- Use prerelease DscResource.ScriptAnalyzer + +### Changed + +- Move docs generation to separate task. +- Remove build.yml config not required. + +### Fixed + +- Fixed HQRM scriptanalyzer errors + ## [0.19.0] - 2024-10-15 ### Changed diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 477b6c5..3af9fe9 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -1,5 +1,5 @@ @{ - PSDependOptions = @{ + PSDependOptions = @{ AddToPath = $true Target = 'output\RequiredModules' Parameters = @{ @@ -7,18 +7,24 @@ } } - InvokeBuild = 'latest' - PSScriptAnalyzer = 'latest' - Pester = 'latest' - Plaster = 'latest' - ModuleBuilder = 'latest' - ChangelogManagement = 'latest' - Sampler = 'latest' - 'Sampler.GitHubTasks' = 'latest' - MarkdownLinkCheck = 'latest' - 'DscResource.AnalyzerRules' = 'latest' - xDscResourceDesigner = 'latest' - 'DscResource.Test' = 'latest' + InvokeBuild = 'latest' + PSScriptAnalyzer = 'latest' + Pester = 'latest' + Plaster = 'latest' + ModuleBuilder = 'latest' + ChangelogManagement = 'latest' + Sampler = 'latest' + 'Sampler.GitHubTasks' = 'latest' + MarkdownLinkCheck = 'latest' + 'DscResource.AnalyzerRules' = @{ + Version = 'latest' + Parameters = @{ + AllowPrerelease = $true + } + } + 'Indented.ScriptAnalyzerRules' = 'latest' + xDscResourceDesigner = 'latest' + 'DscResource.Test' = 'latest' # Prerequisite modules for documentation. 'DscResource.DocGenerator' = 'latest' diff --git a/build.yaml b/build.yaml index 4e4a3be..8794fdb 100644 --- a/build.yaml +++ b/build.yaml @@ -24,16 +24,17 @@ BuildWorkflow: - Build_Module_ModuleBuilder - Build_NestedModules_ModuleBuilder - Create_changelog_release_output - - Generate_Wiki_Content + + docs: - Generate_Conceptual_Help - - Generate_Markdown_For_Public_Commands - - Generate_External_Help_File_For_Public_Commands - - Clean_Markdown_Of_Public_Commands + - Generate_Wiki_Content - Generate_Wiki_Sidebar - Clean_Markdown_Metadata + - Package_Wiki_Content pack: - build + - docs - package_module_nupkg hqrmtest: @@ -158,16 +159,6 @@ DscResource.DocGenerator: - '\*(.+?)\*' # Match Italic (asterisk) Publish_GitHub_Wiki_Content: Debug: false - Generate_Wiki_Content: - MofResourceMetadata: - Type: MofResource - Category: Resources - ClassResourceMetadata: - Type: ClassResource - Category: Resources - CompositeResourceMetadata: - Type: CompositeResource - Category: Resources Generate_Wiki_Sidebar: - Debug: false - AlwaysOverwrite: true + Debug: false + AlwaysOverwrite: true diff --git a/source/Public/Assert-ElevatedUser.ps1 b/source/Public/Assert-ElevatedUser.ps1 index 6b18b48..3825799 100644 --- a/source/Public/Assert-ElevatedUser.ps1 +++ b/source/Public/Assert-ElevatedUser.ps1 @@ -32,7 +32,8 @@ function Assert-ElevatedUser { [CmdletBinding()] - param ( + param + ( [Parameter()] [ValidateNotNullOrEmpty()] [System.String] diff --git a/source/Public/Set-DscMachineRebootRequired.ps1 b/source/Public/Set-DscMachineRebootRequired.ps1 index 0771dc7..3b7d35b 100644 --- a/source/Public/Set-DscMachineRebootRequired.ps1 +++ b/source/Public/Set-DscMachineRebootRequired.ps1 @@ -32,9 +32,7 @@ function Set-DscMachineRebootRequired #> [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')] [CmdletBinding()] - param - ( - ) + param () $global:DSCMachineStatus = 1 }