WPTT / WPThemeReview

PHP_CodeSniffer rules (sniffs) to enforce WordPress theme review coding conventions
MIT License
209 stars 37 forks source link

[New sniff?] Check for non-printable characters #94

Closed jrfnl closed 6 years ago

jrfnl commented 7 years ago

Rule type:

Warning

Rule:

Check for non-printable characters [\x00-\x08\x0B-\x0C\x0E-\x1F\x80-\xFF]

Ref: https://make.wordpress.org/themes/handbook/review/required/theme-check-plugin/#info

Theme check file covering this rule:

https://github.com/WordPress/theme-check/blob/master/checks/nonprintable.php

Notes for implementation:

To do:

grappler commented 7 years ago

For this sniff we can most likely use the token T_BAD_CHARACTER

selul commented 7 years ago

i would like to try this.

jrfnl commented 6 years ago

From: https://github.com/WPTRT/WordPress-Coding-Standards/pull/103#issuecomment-274278772

I spoke to Otto and the reason this was added in the Theme Check was to check for Byte Order Mark. Explanation. This is now being checked with Generic.Files.ByteOrderMark

The check was made a bit looser to try to catch other issues too.

I did a bit of research, non printable characters are things like line breaks. In order for this sniff to work we would need to think of places where it does not make sense to have non printable characters. I am not sure how many places there are.

More of the ASCII codes can be found in the links 1-31 and 127-159 are the invisible characters. http://ascii.cl/htmlcodes.htm http://www.ascii-code.com/

It basically needs to become clear whether just checking for the BOM is enough, or checking for more non-printables is needed.

If the latter, PR #103 contains the basic principle of a sniff for that, but should in that case probably be pulled upstream, either in WPCS or - even better - in PHPCS itself.