svenkreiss / html5validator

Command line tool to validate HTML5 files. Great for continuous integration.
MIT License
314 stars 34 forks source link

--ignore flag works but the return code is nonzero #94

Closed simevo closed 2 years ago

simevo commented 2 years ago

If I run html5validator (installed with pip in a virtualenv on Debian 11) against a dummy HTML file:

mkdir -p qq
cat > qq/index.html
<!DOCTYPE html>
<html>
  <head>
    <title>Test</title>
  </head>
  <body>
  </body>
</html>
^d
html5validator --root qq/ --also-check-css --format text --log INFO

returns:

INFO:html5validator.cli:Files to validate: 
  qq/index.html
INFO:html5validator.cli:Number of files: 1
INFO:html5validator.validator:All good.

and echo $? yields 0.

But if I add <div x-data="stationsMap"></div> inside the body and --ignore-re ".*Attribute .x-.* not allowed on element.*" to the comand line to ignore the x-data attribute it returns:

INFO:html5validator.cli:Files to validate: 
  qq/index.html
INFO:html5validator.cli:Number of files: 1
From line 6, column 5; to line 6, column 30 in resource file:/tmp/qq/index.html
Document checking completed.

but echo $? yields 2.

Also reproducible with docker run --rm -it -v "$PWD/qq:/qq" cyb3rjak3/html5validator:latest-alpine html5validator --root /qq/ --also-check-css --format text --ignore-re ".*Attribute .x-.* not allowed on element.*" --log INFO

Thanks!

simevo commented 2 years ago

Sorry I did not realize that you have to --ignore / --ignore-re all messages even informative ones ... this command works for me:

 html5validator --ignore-re "(.*Attribute .x-.* not allowed on element.*|From line.*)" --ignore "Document checking completed" --root qq/ --also-check-css --format text --log INFO
ptmkenny commented 9 months ago

I think that needed to use --ignore "Document checking completed" should be noted in the docs; this is not intuitive, because you don't normally need to ignore this message to get a 0 exit code on success.