修改完成
This commit is contained in:
@@ -3,6 +3,7 @@ $root = Split-Path $PSScriptRoot -Parent
|
||||
$allowlistPath = Join-Path $PSScriptRoot 'document-flow-position-allowlist.json'
|
||||
$allowlist = Get-Content -LiteralPath $allowlistPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
||||
$allowed = @{}
|
||||
$seenAllowed = @{}
|
||||
foreach ($entry in $allowlist) {
|
||||
$allowed["$($entry.file)::$($entry.selector)"] = $entry.reason
|
||||
}
|
||||
@@ -15,20 +16,31 @@ foreach ($file in $files) {
|
||||
foreach ($styleMatch in [regex]::Matches($source, '(?s)<style\b[^>]*>(?<css>.*?)</style>')) {
|
||||
$css = $styleMatch.Groups['css'].Value
|
||||
foreach ($rule in [regex]::Matches($css, '(?s)(?<selector>[^{}]+)\{(?<body>[^{}]*)\}')) {
|
||||
$body = $rule.Groups['body'].Value
|
||||
if ($body -notmatch '(?m)position\s*:\s*(absolute|fixed|sticky)\s*;') { continue }
|
||||
$body = [regex]::Replace($rule.Groups['body'].Value, '(?s)/\*.*?\*/', '')
|
||||
$positionMatches = [regex]::Matches($body, '(?im)(?<![-\w])position\s*:\s*(?<value>[^;{}]+?)\s*;')
|
||||
if ($positionMatches.Count -eq 0) { continue }
|
||||
$selector = (($rule.Groups['selector'].Value -replace '(?s)^.*@media[^\{]*', '') -replace '\s+', ' ').Trim()
|
||||
$key = "$relative::$selector"
|
||||
if (-not $allowed.ContainsKey($key)) {
|
||||
$position = [regex]::Match($body, '(?m)position\s*:\s*(absolute|fixed|sticky)\s*;').Groups[1].Value
|
||||
$violations.Add("$relative :: $selector :: position:$position")
|
||||
if ($allowed.ContainsKey($key)) {
|
||||
$seenAllowed[$key] = $true
|
||||
} else {
|
||||
foreach ($positionMatch in $positionMatches) {
|
||||
$position = ($positionMatch.Groups['value'].Value -replace '\s+', ' ').Trim()
|
||||
$violations.Add("$relative :: $selector :: position:$position")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$staleAllowlistEntries = @($allowed.Keys | Where-Object { -not $seenAllowed.ContainsKey($_) } | Sort-Object)
|
||||
if ($staleAllowlistEntries.Count -gt 0) {
|
||||
$staleAllowlistEntries | ForEach-Object { Write-Output "STALE ALLOWLIST :: $_" }
|
||||
throw "DOCUMENT-FLOW-POSITION-CONTRACT found $($staleAllowlistEntries.Count) stale allowlist entries."
|
||||
}
|
||||
|
||||
if ($violations.Count -gt 0) {
|
||||
$violations | Sort-Object | ForEach-Object { Write-Output $_ }
|
||||
throw "DOCUMENT-FLOW-POSITION-CONTRACT found $($violations.Count) non-overlay positioning rules."
|
||||
throw "DOCUMENT-FLOW-POSITION-CONTRACT found $($violations.Count) non-allowlisted position declarations."
|
||||
}
|
||||
Write-Output 'DOCUMENT-FLOW-POSITION-CONTRACT PASS'
|
||||
|
||||
Reference in New Issue
Block a user