Skip to content

Commit 772d97f

Browse files
Refactor Helpers module functions to improve parameter handling and suppress diagnostic warnings
1 parent 74ea471 commit 772d97f

File tree

1 file changed

+31
-89
lines changed

1 file changed

+31
-89
lines changed

scripts/Helpers/Helpers.psm1

Lines changed: 31 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
function Add-ContentFromItem {
1+
[CmdletBinding()]
2+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
3+
'PSReviewUnusedParameter', '',
4+
Justification = 'LogGroup - Scoping affects the variables line of sight.'
5+
)]
6+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
7+
'PSAvoidUsingWriteHost', '',
8+
Justification = 'Want to just write to the console, not the pipeline.'
9+
)]
10+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
11+
'PSAvoidLongLines', '',
12+
Justification = 'Easier to read the multi ternery operators in a single line.'
13+
)]
14+
param()
15+
16+
function Add-ContentFromItem {
217
<#
318
.SYNOPSIS
419
Add the content of a folder or file to the root module file.
@@ -75,14 +90,6 @@ function Build-PSModule {
7590
#>
7691
[OutputType([void])]
7792
[CmdletBinding()]
78-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
79-
'PSReviewUnusedParameter', '', Scope = 'Function',
80-
Justification = 'LogGroup - Scoping affects the variables line of sight.'
81-
)]
82-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
83-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
84-
Justification = 'Want to just write to the console, not the pipeline.'
85-
)]
8693
param(
8794
# Name of the module.
8895
[Parameter(Mandatory)]
@@ -130,14 +137,6 @@ function Build-PSModuleBase {
130137
Build-PSModuleBase -SourceFolderPath 'C:\MyModule\src\MyModule' -OutputFolderPath 'C:\MyModule\build\MyModule'
131138
#>
132139
[CmdletBinding()]
133-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
134-
'PSReviewUnusedParameter', '', Scope = 'Function',
135-
Justification = 'LogGroup - Scoping affects the variables line of sight.'
136-
)]
137-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
138-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
139-
Justification = 'Want to just write to the console, not the pipeline.'
140-
)]
141140
param(
142141
# Name of the module.
143142
[Parameter(Mandatory)]
@@ -174,10 +173,6 @@ function Build-PSModuleDocumentation {
174173
Builds a module.
175174
#>
176175
[CmdletBinding()]
177-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
178-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
179-
Justification = 'Want to just write to the console, not the pipeline.'
180-
)]
181176
param(
182177
# Name of the module.
183178
[Parameter(Mandatory)]
@@ -295,30 +290,17 @@ function Build-PSModuleDocumentation {
295290

296291
function Build-PSModuleManifest {
297292
<#
298-
.SYNOPSIS
299-
Compiles the module manifest.
293+
.SYNOPSIS
294+
Compiles the module manifest.
300295
301-
.DESCRIPTION
302-
This function will compile the module manifest.
303-
It will generate the module manifest file and copy it to the output folder.
296+
.DESCRIPTION
297+
This function will compile the module manifest.
298+
It will generate the module manifest file and copy it to the output folder.
304299
305-
.EXAMPLE
306-
Build-PSModuleManifest -SourceFolderPath 'C:\MyModule\src\MyModule' -OutputFolderPath 'C:\MyModule\build\MyModule'
300+
.EXAMPLE
301+
Build-PSModuleManifest -SourceFolderPath 'C:\MyModule\src\MyModule' -OutputFolderPath 'C:\MyModule\build\MyModule'
307302
#>
308303
[CmdletBinding()]
309-
310-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
311-
'PSAvoidLongLines', '', Scope = 'Function',
312-
Justification = 'Easier to read the multi ternery operators in a single line.'
313-
)]
314-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
315-
'PSReviewUnusedParameter', '', Scope = 'Function',
316-
Justification = 'LogGroup - Scoping affects the variables line of sight.'
317-
)]
318-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
319-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
320-
Justification = 'Want to just write to the console, not the pipeline.'
321-
)]
322304
param(
323305
# Name of the module.
324306
[Parameter(Mandatory)]
@@ -789,7 +771,6 @@ function Build-PSModuleRootModule {
789771
.EXAMPLE
790772
Build-PSModuleRootModule -SourceFolderPath 'C:\MyModule\src\MyModule' -OutputFolderPath 'C:\MyModule\build\MyModule'
791773
#>
792-
[CmdletBinding()]
793774
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
794775
'PSReviewUnusedParameter', '', Scope = 'Function',
795776
Justification = 'LogGroup - Scoping affects the variables line of sight.'
@@ -798,6 +779,7 @@ function Build-PSModuleRootModule {
798779
'PSAvoidUsingWriteHost', '', Scope = 'Function',
799780
Justification = 'Want to just write to the console, not the pipeline.'
800781
)]
782+
[CmdletBinding()]
801783
param(
802784
# Name of the module.
803785
[Parameter(Mandatory)]
@@ -1134,10 +1116,6 @@ function Get-PSModuleAliasesToExport {
11341116
Get-PSModuleAliasesToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
11351117
#>
11361118
[CmdletBinding()]
1137-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1138-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
1139-
Justification = 'Want to just write to the console, not the pipeline.'
1140-
)]
11411119
param(
11421120
# Path to the folder where the module source code is located.
11431121
[Parameter(Mandatory)]
@@ -1214,10 +1192,6 @@ function Get-PSModuleCmdletsToExport {
12141192
Get-PSModuleCmdletsToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
12151193
#>
12161194
[CmdletBinding()]
1217-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1218-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
1219-
Justification = 'Want to just write to the console, not the pipeline.'
1220-
)]
12211195
param(
12221196
# Path to the folder where the module source code is located.
12231197
[Parameter(Mandatory)]
@@ -1253,10 +1227,6 @@ function Get-PSModuleFunctionsToExport {
12531227
Get-PSModuleFunctionsToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
12541228
#>
12551229
[CmdletBinding()]
1256-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1257-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
1258-
Justification = 'Want to just write to the console, not the pipeline.'
1259-
)]
12601230
[OutputType([array])]
12611231
param(
12621232
# Path to the folder where the module source code is located.
@@ -1301,10 +1271,6 @@ function Get-PSModuleVariablesToExport {
13011271
.EXAMPLE
13021272
Get-PSModuleVariablesToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
13031273
#>
1304-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1305-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
1306-
Justification = 'Want to just write to the console, not the pipeline.'
1307-
)]
13081274
[OutputType([string])]
13091275
[OutputType([Collections.Generic.List[string]])]
13101276
[CmdletBinding()]
@@ -1378,10 +1344,6 @@ function Import-PSModule {
13781344
Imports a module located at $ModuleFolderPath with the name $moduleName.
13791345
#>
13801346
[CmdletBinding()]
1381-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1382-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
1383-
Justification = 'Want to just write to the console, not the pipeline.'
1384-
)]
13851347
param(
13861348
# Path to the folder where the module source code is located.
13871349
[Parameter(Mandatory)]
@@ -1425,14 +1387,6 @@ function Publish-PSModule {
14251387
#>
14261388
[OutputType([void])]
14271389
[CmdletBinding()]
1428-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1429-
'PSReviewUnusedParameter', '', Scope = 'Function',
1430-
Justification = 'LogGroup - Scoping affects the variables line of sight.'
1431-
)]
1432-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1433-
'PSUseDeclaredVarsMoreThanAssignments', '',
1434-
Justification = 'LogGroup - Scoping affects the variables line of sight.'
1435-
)]
14361390
param(
14371391
# Name of the module to process.
14381392
[Parameter()]
@@ -1861,27 +1815,23 @@ function Publish-PSModule {
18611815
function Resolve-PSModuleDependency {
18621816
<#
18631817
.SYNOPSIS
1864-
Resolves module dependencies from a manifest file using Install-PSResource.
1818+
Resolves module dependencies from a manifest file using Install-PSResource.
18651819
18661820
.DESCRIPTION
1867-
Reads a module manifest (PSD1) and for each required module converts the old
1868-
Install-Module parameters (MinimumVersion, MaximumVersion, RequiredVersion)
1869-
into a single NuGet version range string for Install-PSResource's –Version parameter.
1870-
(Note: If RequiredVersion is set, that value takes precedence.)
1821+
Reads a module manifest (PSD1) and for each required module converts the old
1822+
Install-Module parameters (MinimumVersion, MaximumVersion, RequiredVersion)
1823+
into a single NuGet version range string for Install-PSResource's –Version parameter.
1824+
(Note: If RequiredVersion is set, that value takes precedence.)
18711825
18721826
.EXAMPLE
1873-
Resolve-PSModuleDependency -ManifestFilePath 'C:\MyModule\MyModule.psd1'
1874-
Installs all modules defined in the manifest file, following PSModuleInfo structure.
1827+
Resolve-PSModuleDependency -ManifestFilePath 'C:\MyModule\MyModule.psd1'
1828+
Installs all modules defined in the manifest file, following PSModuleInfo structure.
18751829
18761830
.NOTES
18771831
Should later be adapted to support both pre-reqs, and dependencies.
18781832
Should later be adapted to take 4 parameters sets: specific version ("requiredVersion" | "GUID"), latest version ModuleVersion,
18791833
and latest version within a range MinimumVersion - MaximumVersion.
18801834
#>
1881-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1882-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
1883-
Justification = 'Want to just write to the console, not the pipeline.'
1884-
)]
18851835
[CmdletBinding()]
18861836
param(
18871837
# The path to the manifest file.
@@ -2006,14 +1956,6 @@ function Update-PSModuleManifestAliasesToExport {
20061956
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',
20071957
Justification = 'Updates a file that is being built.'
20081958
)]
2009-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
2010-
'PSReviewUnusedParameter', '', Scope = 'Function',
2011-
Justification = 'LogGroup - Scoping affects the variables line of sight.'
2012-
)]
2013-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
2014-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
2015-
Justification = 'Want to just write to the console, not the pipeline.'
2016-
)]
20171959
[CmdletBinding()]
20181960
param(
20191961
# Name of the module.

0 commit comments

Comments
 (0)