-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFormat-Codebase.ps1
More file actions
52 lines (44 loc) · 1.56 KB
/
Format-Codebase.ps1
File metadata and controls
52 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
param (
[string]$DirectoryPath = "./Public"
)
# Ensure PSScriptAnalyzer is installed
if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
Write-Error "PSScriptAnalyzer module is not installed. Install it using: Install-Module -Name PSScriptAnalyzer -Scope CurrentUser"
exit 1
}
# $Settings = @{
# IncludeDefaultRules = $true
# IncludeRules = @(
# 'PSPlaceOpenBrace',
# 'PSPlaceCloseBrace',
# 'PSUseConsistentWhitespace'
# )
# Rules = @{
# PSPlaceOpenBrace = @{
# Enable = $true
# OnSameLine = $true
# NewLineAfter = $true
# IgnoreOneLineBlock = $true
# }
# PSPlaceCloseBrace = @{
# Enable = $false
# NewLineAfter = $false
# IgnoreOneLineBlock = $true
# }
# PSUseConsistentWhitespace = @{
# Enable = $true
# CheckOpenBrace = $true
# CheckInnerBrace = $true
# CheckPipe = $true
# CheckParameter = $true
# }
# }
# }
$scriptFiles = Get-ChildItem -Path $DirectoryPath -Include @("*.ps1") -Recurse
foreach ($file in $scriptFiles) {
$relativePath = $file.FullName -replace $DirectoryPath, ''
Write-Host "Formatting file: $relativePath"
$content = Get-Content -Path $file.FullName -Raw
$formattedContent = Invoke-Formatter -ScriptDefinition $content
Set-Content -Path $file.FullName -Value $formattedContent -NoNewline
}