AtomLinter / linter-htmlhint

Linter plugin for html, using htmlhint
40 stars 19 forks source link

Any way to ignore PHP sections in HTMLhint? #157

Closed richardbushell closed 7 years ago

richardbushell commented 7 years ago

The title says it all. Is there any way to ignore PHP sections in HTMLhint? Our files are mainly of mixed content, half PHP, half HTML. Our PHP linter currently only lints in the PHP sections between the <?php ... ?> and <?= ... ?> tags, but HTMLhint throws errors in every PHP section too. Anyway, or option, to ignore PHP or other SSI sections within HTMLhint?

Arcanemagus commented 7 years ago

HTMLHint unfortunately has no concept of a processor to strip out parts of the file it doesn't understand.

Your options are to either ignore the errors it throws in those sections, either through a blanket ignore of the rule in configuration or just manually, or to disable this linter entirely on PHP files.

It's rather unfortunate that there isn't a HTML linter of the same quality as the likes of ESLint. 😞

dafky2000 commented 6 years ago

Sorry for raising the dead....

Can you rely on the user having PHP installed? It's not the prettiest but, I use this to remove all PHP code (and preserve new lines in the PHP so reported line numbers still match):

php -d short_open_tag=On -r 'echo array_reduce(token_get_all(file_get_contents($argv[1])),function($c,$i){return $i[0]==321?$c.$i[1]:$c.str_repeat("\n",@count_chars($i.$i[1])[10]);});' -- /path/to/file.php | htmlhint /dev/stdin | sed -e s:/dev/stdin:/path/to/file.php:g

Credit goes to casimir-et-hippolyte on StackOverflow - https://stackoverflow.com/a/47024521/2623965

Related to #35

Arcanemagus commented 6 years ago

I'm already not too happy with the RegEx solution in #167, relying on having PHP installed and taking the hit of spawning an external process is too much for something that should be done in htmlhint in the first place (likely with an XML parser).

dafky2000 commented 6 years ago

I agree but I thought this was the best place to post. I'm sure it can be worked into most's workflow.

Edit: I never saw #167, thank you!