-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix.ps1
More file actions
112 lines (97 loc) · 4 KB
/
Copy pathfix.ps1
File metadata and controls
112 lines (97 loc) · 4 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# fix.ps1
#
# PURPOSE:
# Applies all available auto-fixers with progress output. Always exits 0.
# Run this after making changes to automatically handle formatting
# so agents and developers do not need to respond to lint output.
# Handles: dotnet format, markdownlint, yamlfix, YAML line endings.
#
# EXTENSION POINTS:
# Search for "[PROJECT-SPECIFIC]" comments to find the designated locations
# for adding project-specific auto-fix operations.
#
# MODIFICATION POLICY:
# Only modify this file to add project-specific operations at the designated
# [PROJECT-SPECIFIC] extension points, or to update tool versions as needed.
# ==============================================================================
# HELPER FUNCTIONS
# ==============================================================================
function Get-VenvActivateScript {
if (Test-Path ".venv/Scripts/Activate.ps1") { return ".venv/Scripts/Activate.ps1" } # Windows
if (Test-Path ".venv/bin/Activate.ps1") { return ".venv/bin/Activate.ps1" } # Linux/macOS
return $null
}
function Initialize-PythonVenv {
param([switch]$Silent)
if (-not (Test-Path ".venv")) {
if ($Silent) { python -m venv .venv 2>$null } else { python -m venv .venv }
if ($LASTEXITCODE -ne 0) { return $false }
}
$activateScript = Get-VenvActivateScript
if (-not $activateScript) { return $false }
if ($Silent) { & $activateScript 2>$null } else { & $activateScript }
if (-not (Get-Command deactivate -ErrorAction SilentlyContinue)) { return $false }
$installSucceeded = $false
try {
if ($Silent) {
pip install -r pip-requirements.txt --quiet --disable-pip-version-check 2>$null
} else {
pip install -r pip-requirements.txt --quiet --disable-pip-version-check
}
$installSucceeded = $LASTEXITCODE -eq 0
return $installSucceeded
}
finally {
if (-not $installSucceeded -and (Get-Command deactivate -ErrorAction SilentlyContinue)) {
deactivate 2>$null
}
}
}
function Normalize-YamlLineEndings {
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
Get-ChildItem -Recurse -Include "*.yaml", "*.yml" |
Where-Object { $_.FullName -notmatch '[/\\](\.git|node_modules|\.venv|thirdparty|third-party|3rd-party|\.agent-logs)[/\\]' } |
ForEach-Object {
$raw = [System.IO.File]::ReadAllText($_.FullName)
$fixed = $raw.Replace("`r`n", "`n")
if ($raw -ne $fixed) {
[System.IO.File]::WriteAllText($_.FullName, $fixed, $utf8NoBom)
}
}
}
# ==============================================================================
# AUTO-FIX
# Applies all auto-fixers with progress output. Never fails — applies what it can and
# exits 0 so agents do not react to any output as a problem to solve.
# ==============================================================================
# --- YAML Auto-Fix ---
Write-Host "Fixing: YAML..."
if (Initialize-PythonVenv -Silent) {
yamlfix . 2>$null
deactivate 2>$null
}
Normalize-YamlLineEndings
# --- Markdown Auto-Fix ---
Write-Host "Fixing: markdown..."
$env:PUPPETEER_SKIP_DOWNLOAD = "true"
npm install --silent 2>$null
if ($LASTEXITCODE -eq 0) {
npx markdownlint-cli2 --fix "**/*.md" 2>$null
}
# [PROJECT-SPECIFIC] Add additional auto-fixers here.
# Example (Prettier for TypeScript/JSON):
# npx prettier --write "src/**/*.{ts,json}" 2>$null
# --- .NET Auto-Format ---
Write-Host "Fixing: dotnet format..."
$slnFiles = @(Get-ChildItem -Filter "*.sln" -ErrorAction SilentlyContinue) +
@(Get-ChildItem -Filter "*.slnx" -ErrorAction SilentlyContinue)
if ($slnFiles.Count -gt 0) {
dotnet restore > $null 2>&1
dotnet format 2>$null
}
# [PROJECT-SPECIFIC] Add additional language-specific auto-formatters here.
# Example (C/C++ with clang-format):
# Get-ChildItem -Recurse -Include "*.cpp","*.hpp","*.h" |
# ForEach-Object { clang-format -i $_.FullName } 2>$null
Write-Host "Auto-fix complete."
exit 0