From 237a34dfb39d8937e4c502618f3749e81f64f72a Mon Sep 17 00:00:00 2001 From: Samuel Mannehed Date: Thu, 23 Jan 2025 13:16:14 +0100 Subject: [PATCH] Add exceptions for CSS validator false positives Some new CSS incorrectly give errors from validator.w3.org. Issues were opened in that repo, so hopefully we can remove these exceptions soon. I searched for alternative validators, but couldn't find a different one that had a simple API like this one. In order to reliably detect & handle these exceptions we unfortunately need to make the validator output parsing quite a bit more complicated. --- utils/validate | 57 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/utils/validate b/utils/validate index a6b5507..3f5cb87 100755 --- a/utils/validate +++ b/utils/validate @@ -28,16 +28,63 @@ for fn in "$@"; do curl --silent \ --header "Content-Type: ${type}; charset=utf-8" \ --data-binary @${fn} \ - https://validator.w3.org/nu/?out=text > $OUT - cat $OUT - echo + "https://validator.w3.org/nu/?out=gnu&level=error&asciiquotes=yes" \ + > $OUT # We don't fail the check for warnings as some warnings are # not relevant for us, and we don't currently have a way to # ignore just those - if grep -q -s -E "^Error:" $OUT; then + while read -r line; do + echo + + line_info=$(echo $line | cut -d ":" -f 2) + start_info=$(echo $line_info | cut -d "-" -f 1) + end_info=$(echo $line_info | cut -d "-" -f 2) + + line_start=$(echo $start_info | cut -d "." -f 1) + col_start=$(echo $start_info | cut -d "." -f 2) + + line_end=$(echo $end_info | cut -d "." -f 1) + col_end=$(echo $end_info | cut -d "." -f 2) + + error=$(echo $line | cut -d ":" -f 4-) + + case $error in + *"\"scrollbar-gutter\": Property \"scrollbar-gutter\" doesn't exist.") + # FIXME: https://github.com/validator/validator/issues/1788 + echo "Ignoring below error on line ${line_start}," \ + "the scrollbar-gutter property actually exist and is widely" \ + "supported:" + echo $error + continue + ;; + *"\"clip-path\": \"path("*) + # FIXME: https://github.com/validator/validator/issues/1786 + echo "Ignoring below error on line ${line_start}," \ + "the path() function is valid for clip-path and is" \ + "widely supported:" + echo $error + continue + ;; + *"Parse Error.") + # FIXME: https://github.com/validator/validator/issues/1786 + lineofselector=$(grep -n "@supports selector(" $fn | cut -d ":" -f 1) + linediff=$((lineofselector-line_start)) + # Only ignore if parse error is within 50 lines of "selector()" + if [ ${linediff#-} -lt 50 ]; then + echo "Ignoring below error on line ${line_start}," \ + "the @supports selector() function should not give a parse" \ + "error:" + echo $error + continue + fi + ;; + esac + echo "ERROR between line ${line_start} (col ${col_start})" \ + "and line ${line_end} (col ${col_end}):" + echo $error RET=1 - fi + done < "$OUT" done rm $OUT