Skip to content

Commit 38af480

Browse files
Disable PSUseConsistentIndentation rule and update IncludeRules in Custom.Settings.psd1; add test script demonstrating poor PowerShell practices
1 parent 4043969 commit 38af480

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

tests/srcTestRepo/tests/Custom.Settings.psd1

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Placement = 'begin'
3232
}
3333
PSUseConsistentIndentation = @{
34-
Enable = $true
34+
Enable = $false
3535
IndentationSize = 4
3636
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
3737
Kind = 'space'
@@ -51,14 +51,15 @@
5151
}
5252
ExcludeRules = @(
5353
'PSUseConsistentWhitespace'
54+
'PSAvoidUsingWriteHost'
55+
)
56+
IncludeRules = @(
57+
'PSAvoidSemicolonsAsLineTerminators'
58+
'PSPlaceCloseBrace'
59+
# 'PSPlaceOpenBrace'
60+
'PSProvideCommentHelp'
61+
'PSUseConsistentIndentation'
5462
)
55-
# IncludeRules = @(
56-
# 'PSAvoidSemicolonsAsLineTerminators'
57-
# 'PSPlaceCloseBrace'
58-
# 'PSPlaceOpenBrace'
59-
# 'PSProvideCommentHelp'
60-
# 'PSUseConsistentIndentation'
61-
# )
6263
Severity = @(
6364
'Error'
6465
'Warning'

tests/srcTestRepo/tests/Test.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function wreckPSSociety {
2+
# This function is a purposeful exercise in breaking every PowerShell best practice.
3+
# No Verb-Noun naming, no param block, no proper help documentation,
4+
# inconsistent variable naming, and reliance on Write-Host for output.
5+
6+
if ($args.Count -lt 2) {
7+
Write-Host 'Error: Please supply two arguments.' -ForegroundColor Red
8+
return
9+
}
10+
11+
# Inconsistent variable names: one lowercase, one uppercase.
12+
$firstVal = $args[0]
13+
$SECONDVAL = $args[1]
14+
15+
# Arbitrary logic: if both arguments can be cast to integers, add them;
16+
# otherwise, simply concatenate them as strings.
17+
if (($firstVal -as [int]) -and ($SECONDVAL -as [int])) {
18+
Write-Host "Adding numbers, even if it's not best practice..." -ForegroundColor Yellow
19+
$result = [int]$firstVal + [int]$SECONDVAL } else { Write-Host 'Concatenating values without type checking or clear intent...' -ForegroundColor Yellow
20+
$result = $firstVal + $SECONDVAL
21+
}
22+
23+
Write-Host "Result: $result" -ForegroundColor Blue
24+
}

0 commit comments

Comments
 (0)