-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint.ps1
More file actions
145 lines (122 loc) · 4.66 KB
/
lint.ps1
File metadata and controls
145 lines (122 loc) · 4.66 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# lint.ps1
#
# PURPOSE:
# Runs all lint checks and reports failures. Exits 1 on error.
# Used by CI/CD as the merge gate and by the lint-fix agent
# during pre-PR cleanup.
#
# To auto-fix formatting issues, run fix.ps1 instead.
#
# EXTENSION POINTS:
# Search for "[PROJECT-SPECIFIC]" comments to find the designated locations
# for adding project-specific lint checks.
#
# 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 {
if (-not (Test-Path ".venv")) {
python -m venv .venv
if ($LASTEXITCODE -ne 0) { return $false }
}
$activateScript = Get-VenvActivateScript
if (-not $activateScript) { return $false }
& $activateScript
if (-not (Get-Command deactivate -ErrorAction SilentlyContinue)) { return $false }
$installSucceeded = $false
try {
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
}
}
}
# ==============================================================================
# LINT CHECKS
# Runs all lint checks. Exits 1 if any check fails.
# ==============================================================================
$lintError = $false
# --- PYTHON SECTION ---
# Sets up a virtual environment and runs yamllint.
Write-Host "Linting: YAML..."
$skipPython = -not (Initialize-PythonVenv)
if ($skipPython) { $lintError = $true }
if (-not $skipPython) {
yamllint .
if ($LASTEXITCODE -ne 0) { $lintError = $true }
deactivate
}
# [PROJECT-SPECIFIC] Add additional Python-based lint checks here.
# Example:
# if (-not $skipPython) {
# flake8 src/
# if ($LASTEXITCODE -ne 0) { $lintError = $true }
# }
# --- NPM SECTION ---
# Installs npm dependencies and runs cspell and markdownlint-cli2.
Write-Host "Linting: spelling and markdown..."
$skipNpm = $false
$env:PUPPETEER_SKIP_DOWNLOAD = "true"
npm install --silent
if ($LASTEXITCODE -ne 0) { $lintError = $true; $skipNpm = $true }
if (-not $skipNpm) {
npx cspell --no-progress --no-color --quiet "**/*.{md,yaml,yml,json,cs,cpp,hpp,h,txt}"
if ($LASTEXITCODE -ne 0) { $lintError = $true }
npx markdownlint-cli2 "**/*.md"
if ($LASTEXITCODE -ne 0) { $lintError = $true }
}
# [PROJECT-SPECIFIC] Add additional npm-based lint checks here.
# Example (ESLint for TypeScript):
# if (-not $skipNpm) {
# npx eslint "src/**/*.ts"
# if ($LASTEXITCODE -ne 0) { $lintError = $true }
# }
# --- DOTNET LINTING SECTION ---
# Runs compliance tools: reqstream, versionmark, reviewmark.
Write-Host "Linting: compliance tools..."
$skipDotnetTools = $false
dotnet tool restore > $null
if ($LASTEXITCODE -ne 0) { $lintError = $true; $skipDotnetTools = $true }
if (-not $skipDotnetTools) {
dotnet reqstream --lint --requirements requirements.yaml
if ($LASTEXITCODE -ne 0) { $lintError = $true }
dotnet versionmark --lint
if ($LASTEXITCODE -ne 0) { $lintError = $true }
dotnet reviewmark --lint
if ($LASTEXITCODE -ne 0) { $lintError = $true }
}
# [PROJECT-SPECIFIC] Add additional dotnet tool lint checks here.
# Example:
# if (-not $skipDotnetTools) {
# dotnet custom-tool --lint
# if ($LASTEXITCODE -ne 0) { $lintError = $true }
# }
# --- DOTNET FORMATTING SECTION ---
# Verifies C# code formatting matches .editorconfig rules.
Write-Host "Linting: dotnet format..."
$skipDotnetFormat = $false
dotnet restore > $null
if ($LASTEXITCODE -ne 0) { $lintError = $true; $skipDotnetFormat = $true }
if (-not $skipDotnetFormat) {
dotnet format --verify-no-changes --no-restore
if ($LASTEXITCODE -ne 0) { $lintError = $true }
}
# [PROJECT-SPECIFIC] Add additional format verification checks here.
# Example (clang-format check for C/C++):
# Get-ChildItem -Recurse -Include "*.cpp","*.hpp","*.h" | ForEach-Object {
# $result = clang-format --dry-run --Werror $_.FullName 2>&1
# if ($LASTEXITCODE -ne 0) { Write-Output $result; $lintError = $true }
# }
exit ($lintError ? 1 : 0)