validator/grunt-html

Check files with HTML

LukeMauldin opened this issue · 12 comments

Currently if I run the validator on a file like 'app.html.php', the validator will not run on the file because it must end in an '.html' extension. The validator should be able to run on files like '.html..php'

The backend that grunt-html uses isn't a PHP checker. It's an HTML checker. The problem with trying to validate *.php files is that they're not actually HTML, and they often (usually) contain constructs that aren't conforming HTML. So you when you check them you get a bunch of messages about things that aren't mistakes but that are actually valid PHP.

I can reproduce that. I've renamed test/invalid.html to test/invalid.html.php, then ran this:

java -jar vnu.jar test/invalid.html.php

Instead of outputting the expected errors, it outputs nothing.

@sideshowbarker this looks like an issue of vnu.jar. I tried the --html to force html validation, but that had no effect. Is there a way to make it ignore the file extension and validate as html regardless?

@sideshowbarker thanks for chiming in, somehow I didn't see your comment before posting the one above.

Anyway, since this plugin makes it reasonable to ignore specific errors, it seems fine to still allow validation of php files. The file extension shouldn't really matter, it could be hbars for a handlebars template, which should still be valid html.

@sideshowbarker this looks like an issue of vnu.jar. I tried the --html to force html validation, but that had no effect. Is there a way to make it ignore the file extension and validate as html regardless?

There is no such option currently. I can add one but part of the reason I intentionally wrote it to behave this way is to make it work sanely for the case of recursively descending into directories that might contain files of any number of other kinds/extensions; e.g., .txt files, or .md files, or whatever.

So it strikes me that the way to get it to work sanely for the recursively-descending-into-directories case with other file extensions is to provide an option to explicitly specify other file extensions you want it to check for.

But then again like I said in my earlier comment, php files aren't HTML, and trying to check them as if they were HTML often doesn't produce satisfactory results.

All that said, I'm still willing to add an option if somebody can file an issue for it upstream at https://github.com/validator/validator/issues

Lets see what @LukeMauldin thinks about all this.

I now understand that the vnu.jar checker cannot correctly check PHP files. However, in the current version of grunt-html, it appears to work. For example, when I run it, 'grunt-html' returns that it checked 36 files and no errors were found. Ideally, there should be at least a warning reported stating that the files cannot be checked because they did not end in *.html

Ideally, there should be at least a warning reported stating that the files cannot be checked because they did not end in *.html

There's a verbose option upstream that (I think) does that. (At least I know I put it in the code; can't remember if I documented it and exposed it; will check.) But anyway I still think it could be useful to provide and option for explicitly specifying a list of other extensions to check (in addition to .html and .xhtml files). @LukeMauldin, would that work OK for you?

That would be great

This plugin always provides an exact file list to the jar file. An option to just check all specified files would address the issue here.

This plugin always provides an exact file list to the jar file.

Ah, OK, that makes sense.

An option to just check all specified files would address the issue here.

OK, good—that'd actually be easier for me to implement than what I proposed earlier here, so I'd be quite happy to implement it that way.

I just released a new version of vnu.jar: https://github.com/validator/validator/releases/tag/20150216

This change alters the default handling of non-HTML files. Before by default it skipped any documents without .html, .htm, .xhtml, or .xht extensions; instead now by default all documents that are found are checked, regardless of extension. I added a new --skip-non-html option to provide the old default behavior— that is, to causes any files without .html, .htm, .xhtml, or .xht extensions to be skipped.

Once this gets integrated into grunt-html, please test and let me know if it's not working as expected.

@LukeMauldin the version in master now allows validating php files, can you give it a try?