Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit 34c318d

Browse files
committed
Initial version
Bug fix Bugfix Write-Info MoreBugFixes docker tests fix Fixing Markdown tests More pester tests fixed pester fix Final fix pester fix... yet another pester test fix... ok last one... really, this is the last one..
1 parent e3b80e1 commit 34c318d

File tree

13 files changed

+370
-232
lines changed

13 files changed

+370
-232
lines changed

.MetaTestOptIn.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"Common Tests - Validate Script Files",
66
"Common Tests - Spellcheck Markdown Files",
77
"Common Tests - Relative Path Length",
8-
"Common Tests - Validate Markdown Links"
8+
"Common Tests - Validate Markdown Links",
9+
"Common Tests - Custom Script Analyzer Rules"
910
]

.vscode/analyzersettings.psd1

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@{
2+
<#
3+
For the custom rules to work, the DscResource.Tests repo must be
4+
cloned. It is automatically clone as soon as any unit or
5+
integration tests are run.
6+
#>
7+
CustomRulePath = '.\DscResource.AnalyzerRules'
8+
9+
IncludeRules = @(
10+
# DSC Resource Kit style guideline rules.
11+
'PSAvoidDefaultValueForMandatoryParameter',
12+
'PSAvoidDefaultValueSwitchParameter',
13+
'PSAvoidInvokingEmptyMembers',
14+
'PSAvoidNullOrEmptyHelpMessageAttribute',
15+
'PSAvoidUsingCmdletAliases',
16+
'PSAvoidUsingComputerNameHardcoded',
17+
'PSAvoidUsingDeprecatedManifestFields',
18+
'PSAvoidUsingEmptyCatchBlock',
19+
'PSAvoidUsingInvokeExpression',
20+
'PSAvoidUsingPositionalParameters',
21+
'PSAvoidShouldContinueWithoutForce',
22+
'PSAvoidUsingWMICmdlet',
23+
'PSAvoidUsingWriteHost',
24+
'PSDSCReturnCorrectTypesForDSCFunctions',
25+
'PSDSCStandardDSCFunctionsInResource',
26+
'PSDSCUseIdenticalMandatoryParametersForDSC',
27+
'PSDSCUseIdenticalParametersForDSC',
28+
'PSMisleadingBacktick',
29+
'PSMissingModuleManifestField',
30+
'PSPossibleIncorrectComparisonWithNull',
31+
'PSProvideCommentHelp',
32+
'PSReservedCmdletChar',
33+
'PSReservedParams',
34+
'PSUseApprovedVerbs',
35+
'PSUseCmdletCorrectly',
36+
'PSUseOutputTypeCorrectly',
37+
'PSAvoidGlobalVars',
38+
'PSAvoidUsingConvertToSecureStringWithPlainText',
39+
'PSAvoidUsingPlainTextForPassword',
40+
'PSAvoidUsingUsernameAndPasswordParams',
41+
'PSDSCUseVerboseMessageInDSCResource',
42+
'PSShouldProcess',
43+
'PSUseDeclaredVarsMoreThanAssignments',
44+
'PSUsePSCredentialType',
45+
46+
<#
47+
This is to test all the DSC Resource Kit custom rules.
48+
The name of the function-blocks of each custom rule start
49+
with 'Measure*'.
50+
#>
51+
'Measure-*'
52+
)
53+
54+
IncludeDefaultRules = $true
55+
}

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"powershell.codeFormatting.whitespaceAfterSeparator": true,
99
"powershell.codeFormatting.ignoreOneLineBlock": false,
1010
"powershell.codeFormatting.preset": "Custom",
11+
"powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1",
1112
"files.trimTrailingWhitespace": true,
1213
"files.insertFinalNewline": true,
1314
}

AppVeyor.psm1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function Invoke-AppveyorInstallTask
3535
[CmdletBinding(DefaultParameterSetName = 'Default')]
3636
param
3737
(
38+
[Parameter()]
3839
[Version]
3940
$PesterMaximumVersion
4041
)
@@ -1003,7 +1004,6 @@ function Invoke-AppveyorTestScriptTask
10031004
#>
10041005
function Invoke-AppveyorAfterTestTask
10051006
{
1006-
10071007
[CmdletBinding(DefaultParameterSetName = 'Default')]
10081008
param
10091009
(
@@ -1234,7 +1234,6 @@ function Push-TestArtifact
12341234
#>
12351235
function Invoke-AppVeyorDeployTask
12361236
{
1237-
12381237
[CmdletBinding(DefaultParameterSetName = 'Default')]
12391238
param
12401239
(

DscResource.AnalyzerRules/DscResource.AnalyzerRules.psm1

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function Measure-ParameterBlockParameterAttribute
3939
{
4040
[CmdletBinding()]
4141
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
42-
Param
42+
param
4343
(
4444
[Parameter(Mandatory = $true)]
4545
[ValidateNotNullOrEmpty()]
@@ -109,7 +109,7 @@ function Measure-ParameterBlockMandatoryNamedArgument
109109
{
110110
[CmdletBinding()]
111111
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
112-
Param
112+
param
113113
(
114114
[Parameter(Mandatory = $true)]
115115
[ValidateNotNullOrEmpty()]
@@ -265,7 +265,7 @@ function Measure-IfStatement
265265
{
266266
[CmdletBinding()]
267267
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
268-
Param
268+
param
269269
(
270270
[Parameter(Mandatory = $true)]
271271
[ValidateNotNullOrEmpty()]
@@ -345,7 +345,7 @@ function Measure-ForEachStatement
345345
{
346346
[CmdletBinding()]
347347
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
348-
Param
348+
param
349349
(
350350
[Parameter(Mandatory = $true)]
351351
[ValidateNotNullOrEmpty()]
@@ -417,7 +417,7 @@ function Measure-DoUntilStatement
417417
{
418418
[CmdletBinding()]
419419
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
420-
Param
420+
param
421421
(
422422
[Parameter(Mandatory = $true)]
423423
[ValidateNotNullOrEmpty()]
@@ -489,7 +489,7 @@ function Measure-DoWhileStatement
489489
{
490490
[CmdletBinding()]
491491
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
492-
Param
492+
param
493493
(
494494
[Parameter(Mandatory = $true)]
495495
[ValidateNotNullOrEmpty()]
@@ -561,7 +561,7 @@ function Measure-WhileStatement
561561
{
562562
[CmdletBinding()]
563563
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
564-
Param
564+
param
565565
(
566566
[Parameter(Mandatory = $true)]
567567
[ValidateNotNullOrEmpty()]
@@ -633,7 +633,7 @@ function Measure-ForStatement
633633
{
634634
[CmdletBinding()]
635635
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
636-
Param
636+
param
637637
(
638638
[Parameter(Mandatory = $true)]
639639
[ValidateNotNullOrEmpty()]
@@ -705,7 +705,7 @@ function Measure-SwitchStatement
705705
{
706706
[CmdletBinding()]
707707
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
708-
Param
708+
param
709709
(
710710
[Parameter(Mandatory = $true)]
711711
[ValidateNotNullOrEmpty()]
@@ -781,7 +781,7 @@ function Measure-TryStatement
781781
{
782782
[CmdletBinding()]
783783
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
784-
Param
784+
param
785785
(
786786
[Parameter(Mandatory = $true)]
787787
[ValidateNotNullOrEmpty()]
@@ -853,7 +853,7 @@ function Measure-CatchClause
853853
{
854854
[CmdletBinding()]
855855
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
856-
Param
856+
param
857857
(
858858
[Parameter(Mandatory = $true)]
859859
[ValidateNotNullOrEmpty()]
@@ -924,7 +924,7 @@ function Measure-TypeDefinition
924924
{
925925
[CmdletBinding()]
926926
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
927-
Param
927+
param
928928
(
929929
[Parameter(Mandatory = $true)]
930930
[ValidateNotNullOrEmpty()]
@@ -1023,7 +1023,7 @@ function Measure-Keyword
10231023
{
10241024
[CmdletBinding()]
10251025
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
1026-
Param
1026+
param
10271027
(
10281028
[Parameter(Mandatory = $true)]
10291029
[ValidateNotNullOrEmpty()]

DscResource.CodeCoverage/CodeCovIo.psm1

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ function Add-UniqueFileLineToTable
4040

4141
# file paths need to be relative to repo root when querying GIT
4242
Push-Location -LiteralPath $RepoRoot
43-
try {
43+
try
44+
{
4445
Write-Verbose -Message "running git ls-files" -Verbose
4546

4647
# Get the list of files as Git sees them
@@ -51,8 +52,8 @@ function Add-UniqueFileLineToTable
5152
{
5253
#Find the file as Git sees it
5354
$file = $command.File
54-
$fileKey = $file.replace($RepoRoot,'').TrimStart('\').replace('\','/')
55-
$fileKey = $fileKeys.where{$_ -like $fileKey}
55+
$fileKey = $file.replace($RepoRoot, '').TrimStart('\').replace('\', '/')
56+
$fileKey = $fileKeys.where{ $_ -like $fileKey }
5657

5758
if ($null -eq $fileKey)
5859
{
@@ -69,19 +70,19 @@ function Add-UniqueFileLineToTable
6970

7071
if (!$FileLine.ContainsKey($fileKey))
7172
{
72-
$FileLine.add($fileKey, @{ $TableName = @{}})
73+
$FileLine.add($fileKey, @{ $TableName = @{ } })
7374
}
7475

7576
if (!$FileLine.$fileKey.ContainsKey($TableName))
7677
{
77-
$FileLine.$fileKey.Add($TableName,@{})
78+
$FileLine.$fileKey.Add($TableName, @{ })
7879
}
7980

8081
$lines = $FileLine.($fileKey).$TableName
8182
$lineKey = $($command.line)
8283
if (!$lines.ContainsKey($lineKey))
8384
{
84-
$lines.Add($lineKey,1)
85+
$lines.Add($lineKey, 1)
8586
}
8687
else
8788
{
@@ -107,7 +108,7 @@ function Add-UniqueFileLineToTable
107108
function Test-CodeCoverage
108109
{
109110
[CmdletBinding()]
110-
param(
111+
param (
111112
[Parameter(Mandatory = $true)]
112113
[Object]
113114
$CodeCoverage
@@ -137,9 +138,9 @@ function Test-CodeCoverage
137138
function Export-CodeCovIoJson
138139
{
139140
[CmdletBinding()]
140-
param(
141+
param (
141142
[Parameter(Mandatory = $true)]
142-
[ValidateScript({Test-CodeCoverage -CodeCoverage $_})]
143+
[ValidateScript( { Test-CodeCoverage -CodeCoverage $_ })]
143144
[Object]
144145
$CodeCoverage,
145146

@@ -174,12 +175,12 @@ function Export-CodeCovIoJson
174175
}
175176

176177
# A table of the file key then a sub-tables of `misses` and `hits` lines.
177-
$FileLine = @{}
178+
$FileLine = @{ }
178179

179180
# define common parameters
180-
$addUniqueFileLineParams= @{
181+
$addUniqueFileLineParams = @{
181182
FileLine = $FileLine
182-
RepoRoo = $RepoRoot
183+
RepoRoo = $RepoRoot
183184
}
184185

185186
<#
@@ -192,29 +193,29 @@ function Export-CodeCovIoJson
192193
Add-UniqueFileLineToTable -Command $CodeCoverage.HitCommands -TableName 'hits' @addUniqueFileLineParams
193194

194195
# Create the results structure
195-
$resultLineData = @{}
196-
$resultMessages = @{}
197-
$result = @{
196+
$resultLineData = @{ }
197+
$resultMessages = @{ }
198+
$result = @{
198199
coverage = $resultLineData
199200
messages = $resultMessages
200201
}
201202

202203
foreach ($file in $FileLine.Keys)
203204
{
204-
$hit = 0
205+
$hit = 0
205206
$partial = 0
206-
$missed = 0
207+
$missed = 0
207208
Write-Verbose -Message "summarizing for file: $file"
208209

209210
# Get the hits, if they exist
210-
$hits = @{}
211+
$hits = @{ }
211212
if ($FileLine.$file.ContainsKey('hits'))
212213
{
213214
$hits = $FileLine.$file.hits
214215
}
215216

216217
# Get the misses, if they exist
217-
$misses = @{}
218+
$misses = @{ }
218219
if ($FileLine.$file.ContainsKey('misses'))
219220
{
220221
$misses = $FileLine.$file.misses
@@ -234,7 +235,7 @@ function Export-CodeCovIoJson
234235
}
235236

236237
$lineData = @()
237-
$messages = @{}
238+
$messages = @{ }
238239

239240
<#
240241
produce the results
@@ -289,8 +290,8 @@ function Export-CodeCovIoJson
289290
}
290291
}
291292

292-
$resultLineData.Add($file,$lineData)
293-
$resultMessages.add($file,$messages)
293+
$resultLineData.Add($file, $lineData)
294+
$resultMessages.add($file, $messages)
294295
}
295296

296297
$commitOutput = @(&git.exe log -1 --pretty=format:%H)
@@ -299,7 +300,7 @@ function Export-CodeCovIoJson
299300
Write-Verbose -Message "Branch: $Branch"
300301

301302
$json = $result | ConvertTo-Json
302-
$json = $json.Replace('"!null!"','null')
303+
$json = $json.Replace('"!null!"', 'null')
303304

304305
$json | Out-File -Encoding ascii -LiteralPath $Path -Force
305306
return $Path

0 commit comments

Comments
 (0)