Public/Test-CCDocumentation.ps1
|
function Test-CCDocumentation { [CmdletBinding()] param( [Parameter(Mandatory)][string]$Path, [string]$Standard = 'core', [string]$Config ) $cfg = Get-CCRepoConfig -Path $Path -Standard $Standard -ConfigFile $Config $disabled = $cfg['disabled_checks'] ?? @() $results = @() # DOC-001: README has required sections if ('DOC-001' -notin $disabled -and $cfg['readme_sections'].Count -gt 0) { $readmePath = Join-Path $Path 'README.md' if (Test-Path $readmePath) { $content = Get-Content $readmePath -Raw $missing = @() foreach ($section in $cfg['readme_sections']) { # Match ## Section or # Section (case-insensitive) if ($content -notmatch "(?mi)^#{1,3}\s+$section") { $missing += $section } } if ($missing.Count -eq 0) { $results += New-CCRepoCheckResult -CheckId 'DOC-001' -Category 'Documentation' ` -Item 'README.md sections' -Status 'Pass' -Severity 'Error' ` -Message "README.md contains all required sections" -Standard $Standard } else { $results += New-CCRepoCheckResult -CheckId 'DOC-001' -Category 'Documentation' ` -Item 'README.md sections' -Status 'Fail' -Severity 'Error' ` -Message "README.md missing sections: $($missing -join ', ')" -Standard $Standard ` -FixAvailable $true -FixAction "Add sections: $($missing -join ', ')" } } else { $results += New-CCRepoCheckResult -CheckId 'DOC-001' -Category 'Documentation' ` -Item 'README.md sections' -Status 'Skipped' -Severity 'Error' ` -Message "README.md not found — cannot check sections" -Standard $Standard } } # DOC-002: CHANGELOG follows Keep-a-Changelog if ('DOC-002' -notin $disabled -and $cfg['changelog_format'] -eq 'keep-a-changelog') { $changelogPath = Join-Path $Path 'CHANGELOG.md' if (Test-Path $changelogPath) { $content = Get-Content $changelogPath -Raw $hasVersion = $content -match '\[[\d]+\.[\d]+\.[\d]+\]' $hasCategory = $content -match '(?m)^###\s+(Added|Changed|Deprecated|Removed|Fixed|Security)' if ($hasVersion -and $hasCategory) { $results += New-CCRepoCheckResult -CheckId 'DOC-002' -Category 'Documentation' ` -Item 'CHANGELOG format' -Status 'Pass' -Severity 'Warning' ` -Message "CHANGELOG.md follows Keep-a-Changelog format" -Standard $Standard } else { $results += New-CCRepoCheckResult -CheckId 'DOC-002' -Category 'Documentation' ` -Item 'CHANGELOG format' -Status 'Warning' -Severity 'Warning' ` -Message "CHANGELOG.md may not follow Keep-a-Changelog format" -Standard $Standard ` -FixAvailable $false } } else { $results += New-CCRepoCheckResult -CheckId 'DOC-002' -Category 'Documentation' ` -Item 'CHANGELOG format' -Status 'Skipped' -Severity 'Warning' ` -Message "CHANGELOG.md not found" -Standard $Standard } } $results } |